Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't report promises as open handles #6716

Merged
merged 4 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `[babel-jest]` Make `getCacheKey()` take into account `createTransformer` options ([#6699](https://github.com/facebook/jest/pull/6699))
- `[docs]` Fix contributors link ([#6711](https://github.com/facebook/jest/pull/6711))
- `[jest-cli]` Don't report promises as open handles ([#6716](https://github.com/facebook/jest/pull/6716))

## 23.4.1

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('');
});
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