Skip to content

Commit b144f11

Browse files
committed
Follow existing test style without --forceExit
1 parent 439018f commit b144f11

4 files changed

Lines changed: 45 additions & 16 deletions

File tree

e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,35 @@ Jest has detected the following 1 open handle potentially keeping Jest from exit
3838
3939
at Object.setTimeout (__tests__/inside.js:9:3)
4040
`;
41+
42+
exports[`prints out info about open handlers from lifecycle functions with a \`done\` callback 1`] = `
43+
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
44+
45+
● Timeout
46+
47+
7 |
48+
8 | beforeAll(done => {
49+
> 9 | setTimeout(() => {}, 10000);
50+
| ^
51+
10 | done();
52+
11 | });
53+
12 |
54+
55+
at Object.setTimeout (__tests__/in-done-lifecycle.js:9:3)
56+
`;
57+
58+
exports[`prints out info about open handlers from tests with a \`done\` callback 1`] = `
59+
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
60+
61+
● Timeout
62+
63+
7 |
64+
8 | test('something', done => {
65+
> 9 | setTimeout(() => {}, 10000);
66+
| ^
67+
10 | expect(true).toBe(true);
68+
11 | done();
69+
12 | });
70+
71+
at Object.setTimeout (__tests__/in-done-function.js:9:3)
72+
`;

e2e/__tests__/detectOpenHandles.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,26 @@ it('prints out info about open handlers from inside tests', async () => {
125125
});
126126

127127
it('prints out info about open handlers from tests with a `done` callback', async () => {
128-
const {stderr} = runJest('detect-open-handles', [
128+
const run = runContinuous('detect-open-handles', [
129129
'in-done-function',
130130
'--detectOpenHandles',
131-
'--forceExit',
132131
]);
132+
await run.waitUntil(({stderr}) => stderr.includes('Jest has detected'));
133+
const {stderr} = await run.end();
133134
const textAfterTest = getTextAfterTest(stderr);
134135

135-
expect(textAfterTest).toContain('TCPSERVERWRAP');
136+
expect(wrap(textAfterTest)).toMatchSnapshot();
136137
});
137138

138139
it('prints out info about open handlers from lifecycle functions with a `done` callback', async () => {
139-
const {stderr} = runJest('detect-open-handles', [
140+
const run = runContinuous('detect-open-handles', [
140141
'in-done-lifecycle',
141142
'--detectOpenHandles',
142143
'--forceExit',
143144
]);
145+
await run.waitUntil(({stderr}) => stderr.includes('Jest has detected'));
146+
const {stderr} = await run.end();
144147
const textAfterTest = getTextAfterTest(stderr);
145148

146-
expect(textAfterTest).toContain('TCPSERVERWRAP');
149+
expect(wrap(textAfterTest)).toMatchSnapshot();
147150
});

e2e/detect-open-handles/__tests__/in-done-function.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
const http = require('http');
87

98
test('something', done => {
10-
const server = http.createServer((_, response) => response.end('ok'));
11-
server.listen(0, () => {
12-
expect(true).toBe(true);
13-
done();
14-
});
9+
setTimeout(() => {}, 10000);
10+
expect(true).toBe(true);
11+
done();
1512
});

e2e/detect-open-handles/__tests__/in-done-lifecycle.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
const http = require('http');
87

98
beforeAll(done => {
10-
const server = http.createServer((_, response) => response.end('ok'));
11-
server.listen(0, () => {
12-
done();
13-
});
9+
setTimeout(() => {}, 10000);
10+
done();
1411
});
1512

1613
test('something', () => {

0 commit comments

Comments
 (0)