diff --git a/CHANGELOG.md b/CHANGELOG.md index 960996411d70..36003f385552 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[jest-config]` Fix `--coverage` with `--findRelatedTests` overwriting `collectCoverageFrom` options ([#6736](https://github.com/facebook/jest/pull/6736)) - `[jest-config]` Update default config for testURL from 'about:blank' to 'http://localhost' to address latest JSDOM security warning. ([#6792](https://github.com/facebook/jest/pull/6792)) - `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648)) +- `[jest-cli]` Don't report promises as open handles ([#6716](https://github.com/facebook/jest/pull/6716)) ## 23.4.2 diff --git a/e2e/__tests__/detect_open_handles.js b/e2e/__tests__/detect_open_handles.js index cacac6835f91..51e4059d7084 100644 --- a/e2e/__tests__/detect_open_handles.js +++ b/e2e/__tests__/detect_open_handles.js @@ -25,13 +25,13 @@ try { } function getTextAfterTest(stderr) { - return stderr.split('Ran all test suites.')[1].trim(); + return (stderr.split(/Ran all test suites(.*)\n/)[2] || '').trim(); } it('prints message about flag on slow tests', async () => { const {stderr} = await runJest.until( 'detect-open-handles', - [], + ['outside'], 'Jest did not exit one second after the test run has completed.', ); const textAfterTest = getTextAfterTest(stderr); @@ -42,7 +42,7 @@ it('prints message about flag on slow tests', async () => { it('prints message about flag on forceExit', async () => { const {stderr} = await runJest.until( 'detect-open-handles', - ['--forceExit'], + ['outside', '--forceExit'], 'Force exiting Jest', ); const textAfterTest = getTextAfterTest(stderr); @@ -53,7 +53,7 @@ it('prints message about flag on forceExit', async () => { it('prints out info about open handlers', async () => { const {stderr} = await runJest.until( 'detect-open-handles', - ['--detectOpenHandles'], + ['outside', '--detectOpenHandles'], 'Jest has detected', ); const textAfterTest = getTextAfterTest(stderr); @@ -70,7 +70,18 @@ it('prints out info about open handlers', async () => { 8 | at Object. (server.js:7:5) - at Object. (__tests__/test.js:1:1) + at Object. (__tests__/outside.js:1:1) `.trim(), ); }); + +it('does not report promises', () => { + // The test here is basically that it exits cleanly without reporting anything (does not need `runJest.until`) + const {stderr} = runJest('detect-open-handles', [ + 'promise', + '--detectOpenHandles', + ]); + const textAfterTest = getTextAfterTest(stderr); + + expect(textAfterTest).toBe(''); +}); diff --git a/e2e/detect-open-handles/__tests__/test.js b/e2e/detect-open-handles/__tests__/outside.js similarity index 100% rename from e2e/detect-open-handles/__tests__/test.js rename to e2e/detect-open-handles/__tests__/outside.js diff --git a/e2e/detect-open-handles/__tests__/promise.js b/e2e/detect-open-handles/__tests__/promise.js new file mode 100644 index 000000000000..5210fb114d7b --- /dev/null +++ b/e2e/detect-open-handles/__tests__/promise.js @@ -0,0 +1,4 @@ +test('something', () => { + new Promise(() => {}); + expect(true).toBe(true); +}); diff --git a/packages/jest-cli/src/collectHandles.js b/packages/jest-cli/src/collectHandles.js index 18ad05f097be..f0fc12144bc2 100644 --- a/packages/jest-cli/src/collectHandles.js +++ b/packages/jest-cli/src/collectHandles.js @@ -17,6 +17,9 @@ export default function collectHandles(): () => Array { const activeHandles: Map = new Map(); function initHook(asyncId, type) { + if (type === 'PROMISE') { + return; + } const error = new Error(type); if (Error.captureStackTrace) {