Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors when browser launching fails #78

Merged
merged 1 commit into from Jun 1, 2021

Conversation

calebeby
Copy link
Member

@calebeby calebeby commented May 28, 2021

This PR fixes a bug I noticed on cloudfour-patterns.

Previously, if npm failed to run the postinstall script for puppeteer (or ignored it? I noticed npm@7 ignores postinstall scripts sometimes), then when you run pleasantest, here is what would happen:

Pleasantest sees that there is no cached browser instance to connect to
Pleasantest spawns a new process to launch a new browser
In the spawned process, puppeteer.launch() is called
puppeteer.launch() throws an error, saying that the browser binary is missing, but since it is in a child process, the error is not displayed anywhere
---
5 seconds later: Jest force-quits the test because it timed out

Now, errors that are thrown in the child process get passed to the main process, where they are thrown:

Failed to start browser: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (869685).

Testing

  • npm ci
  • Lose the browser binary: rm -rf node_modules/puppeteer/.local-chromium
  • Clear out any references to cached browser instances: rm /Users/<your username>/Library/Application\ Support/pleasantest-nodejs/config.json
  • Run a test (probably just one, running them all takes a long time if they are all failing): npm run test toBeVisible. It should fail and display a helpful message.
  • Run the test again (or another test). It should fail again with the same message. (This is to make sure that it does not try to cache the browser that failed to launch the first time)
  • node ./node_modules/puppeteer/install.js to re-download the browser binaries
  • npm run test should pass

@calebeby
Copy link
Member Author

image

Easiest to review with "hide whitespace changes" checked

Copy link
Member

@Paul-Hebert Paul-Hebert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good and works as advertised 👍

@calebeby calebeby merged commit 55b75f9 into main Jun 1, 2021
@calebeby calebeby deleted the handle-browser-launch-error branch June 1, 2021 20:19
@github-actions github-actions bot mentioned this pull request Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants