percy / percy-script

[Deprecated] PercyScript is the easiest way to get started with visual testing and Percy.
https://percy.io
MIT License
2 stars 2 forks source link

PercyAgent is not defined #15

Closed plegner closed 4 years ago

plegner commented 4 years ago

When running percy exec -- node test/snapshots.js on MacOS, with v1.1.0 of @percy/script, I get the following error:

[percy] percy has started.
Error: Evaluation failed: ReferenceError: PercyAgent is not defined
    at __puppeteer_evaluation_script__:2:28
    at ExecutionContext._evaluateInternal (/.../node_modules/puppeteer/lib/cjs/common/ExecutionContext.js:217:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async ExecutionContext.evaluate (/.../node_modules/puppeteer/lib/cjs/common/ExecutionContext.js:106:16)
    at async percySnapshot (/.../node_modules/@percy/script/snapshot.js:38:21)
    at async snapshot (/.../node_modules/@percy/script/index.js:21:7)
    at async /.../test/snapshots.js:30:5
    at async Object.run (/.../node_modules/@percy/script/index.js:25:7)
  -- ASYNC --
    at ExecutionContext.<anonymous> (/.../node_modules/puppeteer/lib/cjs/common/helper.js:109:19)
    at DOMWorld.evaluate (/.../node_modules/puppeteer/lib/cjs/common/DOMWorld.js:84:24)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
  -- ASYNC --
    at Frame.<anonymous> (/.../node_modules/puppeteer/lib/cjs/common/helper.js:109:19)
    at Page.evaluate (/.../node_modules/puppeteer/lib/cjs/common/Page.js:883:14)
    at Page.<anonymous> (/.../node_modules/puppeteer/lib/cjs/common/helper.js:110:27)
    at percySnapshot (/.../node_modules/@percy/script/snapshot.js:38:32)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async snapshot (/.../node_modules/@percy/script/index.js:21:7)
    at async /.../test/snapshots.js:30:5
    at async Object.run (/.../node_modules/@percy/script/index.js:25:7)
[percy] stopping percy...
[percy] waiting for 0 snapshots to complete...
[percy] done.
Robdel12 commented 4 years ago

Hey @plegner, thanks for the issue! What kind of page is being snapshotted here? It seems like this line is silently failing: https://github.com/percy/percy-script/blob/master/snapshot.js#L22-L24 we're relying on PercyAgent to be available on the window object later on here: https://github.com/percy/percy-script/blob/master/snapshot.js#L39

I have a feeling the issue is a timing one: https://github.com/mathigon/textbooks/pull/181/files#diff-e50531e6b40c4b9d0853ded9c646bd0dR28-R33 looping over URLs like this (without any wait between the visit and then percySnapshot) will result in flaky snapshots. Try adding an await -- I'm curious if this error goes away:

PercyScript.run(async (page, percySnapshot) => {
  for (const p of pages) {
    await page.goto(`http://localhost:5000/${p}#full`);
    await page.waitFor(2000);
    await percySnapshot(`${p}-en`, {widths: [1200, 374], percyCSS});
  }
});
plegner commented 4 years ago

Thanks so much for investigating, @Robdel12! adding a waitFor did not fix the error, but I played around with it some more and noticed that we had a typo when generating the list of URLs to test, so that all of them responded with a 404 error…

I'm sorry for troubling you – although it might still be useful to have more specific error messages in these cases.