percy / percy-agent

[Deprecated in favor of `@percy/cli`] An agent process for integrating with Percy.
https://percy.io
MIT License
22 stars 23 forks source link

TypeErrors when running percy exec with PERCY_TOKEN present #485

Closed jfuston closed 4 years ago

jfuston commented 4 years ago

Hey all, seeing a couple errors upon initial runs that I've not seen in our other projects, wanted to check and see if you could point me in the right direction.

I'm running percy exec -- cypress run --env configFile=${env} --browser chrome --spec 'cypress/tests/visual/*' and in the console I get the following but only when the PERCY_TOKEN is present.

[percy] TypeError Cannot read property 'body' of undefined | Fri Mar 13 2020 16:10:37 GMT-0500 (Central Daylight Time)
[percy] stopping percy...
[percy] waiting for 0 snapshots to complete...
[percy] done.
[percy] percy has started.
Possibly unhandled TypeError: A catch filter must be an error constructor
    at Promise$catch (/Users/jfuston/dev/response/node_modules/bluebird/js/bluebird.js:964:21)
    at try_once (/Users/jfuston/dev/response/node_modules/bluebird-retry/lib/bluebird-retry.js:81:14)
    at retry (/Users/jfuston/dev/response/node_modules/bluebird-retry/lib/bluebird-retry.js:123:12)
    at PercyClient._httpPost (/Users/jfuston/dev/response/node_modules/percy-client/dist/main.js:141:14)
    at PercyClient.createBuild (/Users/jfuston/dev/response/node_modules/percy-client/dist/main.js:198:19)
    at BuildService.create (/Users/jfuston/dev/response/node_modules/@percy/agent/dist/services/build-service.js:16:18)
    at AgentService.start (/Users/jfuston/dev/response/node_modules/@percy/agent/dist/services/agent-service.js:34:48)
    at Exec.start (/Users/jfuston/dev/response/node_modules/@percy/agent/dist/commands/percy-command.js:36:37)
    at Exec.run (/Users/jfuston/dev/response/node_modules/@percy/agent/dist/commands/exec.js:25:24)
^C[percy] stopping percy...
[percy] waiting for 0 snapshots to complete...
[percy] done.

The tests will run as expected if I don't interrupt the process but it still collects 0 snapshots at the end.

I'm on "@percy/cypress": "2.3.1", and "cypress": "4.1.0", but have tried down to "@percy/cypress": "2.0.0" and "cypress": "4.0.0" and still see the same issue.

Any ideas?

Robdel12 commented 4 years ago

Hey @jfuston! I haven't seen that error before -- which version of node are you using?

jfuston commented 4 years ago

Hey @Robdel12, this project is running on v10.17.0

Robdel12 commented 4 years ago

Gotcha, that should work. I just realized there was an error above it too:

[percy] TypeError Cannot read property 'body' of undefined | Fri Mar 13 2020 16:10:37 GMT-0500 (Central Daylight Time)

Is there any network mocking going on? That error suggests that the DOM snapshot we send from Cypress to our process is empty: https://github.com/percy/percy-cypress/blob/master/lib/index.ts#L17-L39 (body)

jfuston commented 4 years ago

Definitely, we're changing a route or two per test. Mostly small things so we don't have to keep a couple dozen accounts in various configurations laying around in pristine condition. Nothing I'd expect to cause the DOM to be empty though. Are there particular routes Percy uses that you think we may be stepping on with Cypress?

jfuston commented 4 years ago

I should add that we're using Cypress' baseUrl to confine it to our app and we're not doing anything crazy with glob matches on routes. We've had success doing similar stubbing in other projects

Robdel12 commented 4 years ago

This might not be within the Cypress SDK. Could you paste the full logs? Does a Percy build ever get created?

Looks like its failing to create a build:

at PercyClient.createBuild (/Users/jfuston/dev/response/node_modules/percy-client/dist/main.js:198:19)
jfuston commented 4 years ago

I may have cut you an example after I archived the project in Percy just to make sure I didn't do something wrong there. Let me run another one real quick. What's the location of the full log you're looking for?

jfuston commented 4 years ago

Hmm. I'm still seeing that PercyClient.createBuild line which is curious because the web UI does show a corresponding entry and that it's "Receiving Build"

Robdel12 commented 4 years ago

Yeah, it looks like it's failing here: https://github.com/percy/percy-agent/blob/f58202767e000170e0af9391cc51fd422607d826/src/services/build-service.ts#L15

It might be failing to provide a response because of retry on a first failed request (not 100% sure on the why). But that's the line that's throwing the error πŸ€”

Robdel12 commented 4 years ago

Can you tell me which versions of bluebird-retry & bluebird your project is resolving to? (yarn why or npm ls)

jfuston commented 4 years ago

here's the output for those two:

jfuston-MacBook-Pro:response jfuston$ npm ls bluebird-retry
response@0.3.0 /Users/jfuston/dev/response
└─┬ @percy/cypress@2.3.1
  └─┬ @percy/agent@0.24.3
    └─┬ percy-client@3.6.1
      └── bluebird-retry@0.11.0

jfuston-MacBook-Pro:response jfuston$ npm ls bluebird
response@0.3.0 /Users/jfuston/dev/response
β”œβ”€β”¬ @percy/cypress@2.3.1
β”‚ └─┬ @percy/agent@0.24.3
β”‚   └─┬ percy-client@3.6.1
β”‚     └── UNMET PEER DEPENDENCY bluebird@3.7.2
β”œβ”€β”¬ babel-eslint@4.1.8
β”‚ └─┬ babel-core@5.8.38
β”‚   └── bluebird@2.11.0
β”œβ”€β”€ bluebird@0.8.1-0
β”œβ”€β”¬ UNMET PEER DEPENDENCY cypress@4.1.0
β”‚ └── bluebird@3.7.2
└─┬ grunt-emma@2.2.1 (github:emmadev/grunt-emma#d923ea54e5ed5bbeb86bc7440a4d76884d3ca58f)
  └─┬ request-promise@4.2.5
    └── bluebird@3.7.2
jfuston commented 4 years ago

Updating that devDependency to bluebird@3.7.2 fixed it. I must've overlooked the output complaining about that when initially installing @percy/cypress. Thank you for digging through that so quickly!

Robdel12 commented 4 years ago

No problem! The hero here is behind the scenes, @wwilsman. He spotted that and realized the error message here was different from their wiki: https://github.com/petkaantonov/bluebird/wiki/Error:-Catch-filter-must-inherit-from-Error-or-be-a-simple-predicate-function

Whoop! That's good that it's working now πŸ˜ƒ

Robdel12 commented 4 years ago

FWIW, we're going to be getting rid of bluebird in the near future & use native node promises. Hopefully this is no ever a possible issue soon 🀞

jfuston commented 4 years ago

Glad to hear it, I'll keep an eye out for that change! Thanks again for the insane responsiveness.

Robdel12 commented 4 years ago

No problem, glad we could get it sorted πŸ˜ƒ