Skip to content

Commit 0591f22

Browse files
SimenBthymikee
authored andcommittedAug 8, 2018
fix: don't report promises as open handles (#6716)
1 parent 71dcfd0 commit 0591f22

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `[jest-config]` Fix `--coverage` with `--findRelatedTests` overwriting `collectCoverageFrom` options ([#6736](https://github.com/facebook/jest/pull/6736))
1313
- `[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))
1414
- `[jest-cli]` Fix `testMatch` not working with negations ([#6648](https://github.com/facebook/jest/pull/6648))
15+
- `[jest-cli]` Don't report promises as open handles ([#6716](https://github.com/facebook/jest/pull/6716))
1516

1617
## 23.4.2
1718

‎e2e/__tests__/detect_open_handles.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ try {
2525
}
2626

2727
function getTextAfterTest(stderr) {
28-
return stderr.split('Ran all test suites.')[1].trim();
28+
return (stderr.split(/Ran all test suites(.*)\n/)[2] || '').trim();
2929
}
3030

3131
it('prints message about flag on slow tests', async () => {
3232
const {stderr} = await runJest.until(
3333
'detect-open-handles',
34-
[],
34+
['outside'],
3535
'Jest did not exit one second after the test run has completed.',
3636
);
3737
const textAfterTest = getTextAfterTest(stderr);
@@ -42,7 +42,7 @@ it('prints message about flag on slow tests', async () => {
4242
it('prints message about flag on forceExit', async () => {
4343
const {stderr} = await runJest.until(
4444
'detect-open-handles',
45-
['--forceExit'],
45+
['outside', '--forceExit'],
4646
'Force exiting Jest',
4747
);
4848
const textAfterTest = getTextAfterTest(stderr);
@@ -53,7 +53,7 @@ it('prints message about flag on forceExit', async () => {
5353
it('prints out info about open handlers', async () => {
5454
const {stderr} = await runJest.until(
5555
'detect-open-handles',
56-
['--detectOpenHandles'],
56+
['outside', '--detectOpenHandles'],
5757
'Jest has detected',
5858
);
5959
const textAfterTest = getTextAfterTest(stderr);
@@ -70,7 +70,18 @@ it('prints out info about open handlers', async () => {
7070
8 |
7171
7272
at Object.<anonymous> (server.js:7:5)
73-
at Object.<anonymous> (__tests__/test.js:1:1)
73+
at Object.<anonymous> (__tests__/outside.js:1:1)
7474
`.trim(),
7575
);
7676
});
77+
78+
it('does not report promises', () => {
79+
// The test here is basically that it exits cleanly without reporting anything (does not need `runJest.until`)
80+
const {stderr} = runJest('detect-open-handles', [
81+
'promise',
82+
'--detectOpenHandles',
83+
]);
84+
const textAfterTest = getTextAfterTest(stderr);
85+
86+
expect(textAfterTest).toBe('');
87+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test('something', () => {
2+
new Promise(() => {});
3+
expect(true).toBe(true);
4+
});

‎packages/jest-cli/src/collectHandles.js

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export default function collectHandles(): () => Array<Error> {
1717
const activeHandles: Map<string, Error> = new Map();
1818

1919
function initHook(asyncId, type) {
20+
if (type === 'PROMISE') {
21+
return;
22+
}
2023
const error = new Error(type);
2124

2225
if (Error.captureStackTrace) {

0 commit comments

Comments
 (0)
Please sign in to comment.