question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests fail with UnhandledPromiseRejectionWarning if they connect to imgur.com

See original GitHub issue

Workaround

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
UziTechcommented, Nov 24, 2021

Should be fixed in v6.0.1 🎉

0reactions
mukacommented, Nov 25, 2021

Hi @IljaKroonen @UziTech seems I introduced a bug, PR #456 revert the modification on disconnect. Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnhandledPromiseRejectionWar...
I am working in svelte and installed node modules using npm i. The same code is working in Linux. But, when I am...
Read more >
Imgur: The magic of the Internet
Imgur is the easiest way to discover and enjoy the magic of the Internet.
Read more >
Possible Unhandled Promise Rejection in react native-node.js
This error is most like because you're using JSON.parse(response) or response.json() wrong. You may be parsing the response but the response is not...
Read more >
How to find which test warns unhandledPromiseRejection in jest
As most of you, me too wrongly guessed the test suite above the warning message warns about unhandledPromiseRejection . That eat up quite ......
Read more >
Imgur-hosted image fails to load in web page object ONLY ...
It works perfectly in Tableau Desktop, but fails when I publish it to Tableau Public, with an error message saying that 'imgur.com refused...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found