Failing tests will throw an UnhandledPromiseRejectionWarning but will still pass.
This has been brought up in another issue as a side effect.
https://github.com/smooth-code/jest-puppeteer/issues/106#issuecomment-426245782
It is possible this is a windows specific bug
PASS test/integration/app.test.js (10.084s)
app
โ renders the page (8320ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 10.158s, estimated 14s
Ran all test suites.
(node:18816) UnhandledPromiseRejectionWarning: Error: Text not found "Page Renders"
Protocol error (Runtime.callFunctionOn): Target closed.
(node:18816) 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(). (rejection id: 1)
(node:18816) [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.
If I add a timeout after each test of something over the 500ms timeout.
afterEach(async () => {
await new Promise(resolve => setTimeout(resolve, 550));
});
then it will fail tests
FAIL test/integration/app.test.js (10.712s)
app
ร renders the page (8946ms)
โ app โบ renders the page
TimeoutError: Text found "Page Renders"
waiting for function failed: timeout 500ms exceeded
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 10.786s, estimated 11s
Ran all test suites.
Run tests. I am running them on a windows machine that may be an issue.
Tests should fail.
I am afraid I working in a corporate repo
npx envinfo --system --binaries --npmPackages expect-puppeteer,jest-dev-server,jest-environment-puppeteer,jest-puppeteer,spawnd --markdown --clipboardPaste the results here:
## System:
- OS: Windows 10
- CPU: (8) x64 Intel(R) Core(TM) i5-8400H CPU @ 2.50GHz
- Memory: 8.71 GB / 15.78 GB
## Binaries:
- Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
- npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
hi @dptoot
Could give me some information about the renders the page test code?
@xiaoyuhen Thanks for getting back. Let me say first that with the exception of this issue jest-puppeteer has been great and simple to setup!
This is my initial setup of integration testing so there is not a lot going on.
I am running the suite on windows and it is part of a lerna based monorepo. The test setup is located
at the root level and the npm poc commands use lerna's scope to run the build/start commands within ./packages/poc dir
// ./jest.integration.config.js
module.exports = {
preset: 'jest-puppeteer',
testPathIgnorePatterns: [
'\\\\node_modules\\\\',
'<rootDir>/test/unit',
],
};
// ./jest-puppeteer.config.js
module.exports = {
browserContext: 'incognito',
launch: {
headless: true,
devtools: true,
},
server: {
command: 'npm run poc:build && npm run poc:start',
port: 3000,
launchTimeout: 30000,
debug: true,
},
};
// ./test/integration/app.test.js
/* global page */
describe('app', () => {
// Timeout needs to be increased to allow our page to initially navigate.
// https://github.com/smooth-code/jest-puppeteer/issues/106#issuecomment-413344050
beforeEach(async () => {
jest.setTimeout(15000);
await page.goto('http://localhost:3000');
});
afterEach(async () => {
await new Promise(resolve => setTimeout(resolve, 550));
});
it('renders the page', async () => {
expect(page).toMatch('Page Renders');
});
});
Thanks for the help
Closing this. Looks like the issue was on my side.
The expect methods needed an await to function correctly
it('renders the page', async () => {
await expect(page).toMatch('Page Renders');
});
for others landing here: often the cause for such exception is long-running test โ just like the example above when test runs for longer than 5sec (the default wait time) jest gives up, does some clean-up (I guess) and you can see all sorts of promise rejection errors. Solution is to either specify longer timeout in the test itself
it('description', () => {}, 60000)
or somewhere before the test extend globally the timeout via jest.setTimeout(60000)
Most helpful comment
Closing this. Looks like the issue was on my side.
The expect methods needed an await to function correctly