Tests fail with UnhandledPromiseRejectionWarning if they connect to imgur.com
See original GitHub issueWorkaround
For other people with the same problem, a workaround for this issue is to integrate Jest and Puppeteer manually rather than using this preset.
🐛 Bug Report
The following test fails:
test('weird', async () => {
await page.goto("https://imgur.com");
expect(true).toBe(true);
});
Stacktrace:
λ ~/dev/weird-bug ← npx jest
FAIL ./test.js
✕ weird (1495 ms)
● weird
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 2.176 s, estimated 3 s
Ran all test suites.
(node:9861) UnhandledPromiseRejectionWarning: Error: Caught error after test environment was torn down
Navigation failed because browser has disconnected!
at /home/lark/dev/gorged/node_modules/puppeteer/src/common/LifecycleWatcher.ts:105:13
at /home/lark/dev/gorged/node_modules/puppeteer/vendor/mitt/src/index.ts:81:75
at Array.map (<anonymous>)
at Object.emit (/home/lark/dev/gorged/node_modules/puppeteer/vendor/mitt/src/index.ts:81:56)
at CDPSession.emit (/home/lark/dev/gorged/node_modules/puppeteer/src/common/EventEmitter.ts:97:18)
at CDPSession._onClosed (/home/lark/dev/gorged/node_modules/puppeteer/src/common/Connection.ts:319:10)
at Connection._onMessage (/home/lark/dev/gorged/node_modules/puppeteer/src/common/Connection.ts:123:17)
at WebSocket.<anonymous> (/home/lark/dev/gorged/node_modules/puppeteer/src/node/NodeWebSocketTransport.ts:41:42)
at WebSocket.onMessage (/home/lark/dev/gorged/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
(node:9861) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9861) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Other sites work fine, such as google, reddit, and stackexchange. I’m not sure if there are other sites which exhibit the same behaviour.
Note that this is not a problem with Jest timing out, since the failure happens in 2.7s, which is under the 5s Jest timeout.
To Reproduce
Steps to reproduce the behavior:
Install Jest, Puppeteer, and jest-puppeteer, and then run the above test suite.
My exact versions are as follows, from package-lock.json
:
jest: 26.6.3
jest-puppeteer: 4.4.0
puppeteer: 8.0.0
In desperation, I also tried with a bunch of different versions for Puppeteer, all the way down to 1.0.0. None worked.
Expected behavior
The test succeeds.
Link to repl or repo (highly encouraged)
None; provided code is a complete MWE.
Run npx envinfo --system --binaries --npmPackages expect-puppeteer,jest-dev-server,jest-environment-puppeteer,jest-puppeteer,spawnd --markdown --clipboard
Paste the results here:
## System:
- OS: Linux 5.8 Pop!_OS 20.10
- CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
- Memory: 9.31 GB / 15.44 GB
- Container: Yes
- Shell: 5.0.17 - /bin/bash
## Binaries:
- Node: 12.18.2 - /usr/bin/node
- npm: 6.14.8 - /usr/bin/npm
## npmPackages:
- jest-puppeteer: ^4.4.0 => 4.4.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Top GitHub Comments
Should be fixed in v6.0.1 🎉
Hi @IljaKroonen @UziTech seems I introduced a bug, PR #456 revert the modification on disconnect. Thank you