Skip to content

Commit

Permalink
fix: don't report promises as open handles (#6716)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and thymikee committed Aug 8, 2018
1 parent 71dcfd0 commit 0591f22
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 16 additions & 5 deletions e2e/__tests__/detect_open_handles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -70,7 +70,18 @@ it('prints out info about open handlers', async () => {
8 |
at Object.<anonymous> (server.js:7:5)
at Object.<anonymous> (__tests__/test.js:1:1)
at Object.<anonymous> (__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('');
});
File renamed without changes.
4 changes: 4 additions & 0 deletions e2e/detect-open-handles/__tests__/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test('something', () => {
new Promise(() => {});
expect(true).toBe(true);
});
3 changes: 3 additions & 0 deletions packages/jest-cli/src/collectHandles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default function collectHandles(): () => Array<Error> {
const activeHandles: Map<string, Error> = new Map();

function initHook(asyncId, type) {
if (type === 'PROMISE') {
return;
}
const error = new Error(type);

if (Error.captureStackTrace) {
Expand Down

0 comments on commit 0591f22

Please sign in to comment.