Skip to content

Commit bb39cb2

Browse files
fix: Avoid creating the word testfalse in the message on test timeout (#13954)
1 parent 92630a6 commit bb39cb2

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
- `[jest-circus]` Send test case results for `todo` tests ([#13915](https://github.com/facebook/jest/pull/13915))
1717
- `[jest-circus]` Update message printed on test timeout ([#13830](https://github.com/facebook/jest/pull/13830))
18+
- `[jest-circus]` Avoid creating the word "testfalse" when `takesDoneCallback` is `false` in the message printed on test timeout AND updated timeouts test ([#13954](https://github.com/facebook/jest/pull/13954))
1819
- `[@jest/test-result]` Allow `TestResultsProcessor` type to return a Promise ([#13950](https://github.com/facebook/jest/pull/13950))
1920

2021
### Chore & Maintenance

e2e/__tests__/__snapshots__/timeouts.test.ts.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ Time: <<REPLACED>>
2626
Ran all test suites."
2727
`;
2828
29+
exports[`does not exceed the timeout parameter 1`] = `
30+
"PASS __tests__/a-banana.js
31+
✓ banana"
32+
`;
33+
34+
exports[`does not exceed the timeout parameter 2`] = `
35+
"Test Suites: 1 passed, 1 total
36+
Tests: 1 passed, 1 total
37+
Snapshots: 0 total
38+
Time: <<REPLACED>>
39+
Ran all test suites."
40+
`;
41+
2942
exports[`exceeds the command line testTimeout 1`] = `
3043
"Test Suites: 1 failed, 1 total
3144
Tests: 1 failed, 1 total
@@ -42,6 +55,14 @@ Time: <<REPLACED>>
4255
Ran all test suites."
4356
`;
4457
58+
exports[`exceeds the timeout parameter 1`] = `
59+
"Test Suites: 1 failed, 1 total
60+
Tests: 1 failed, 1 total
61+
Snapshots: 0 total
62+
Time: <<REPLACED>>
63+
Ran all test suites."
64+
`;
65+
4566
exports[`exceeds the timeout specifying that \`done\` has not been called 1`] = `
4667
"Test Suites: 1 failed, 1 total
4768
Tests: 1 failed, 1 total

e2e/__tests__/timeouts.test.ts

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ test('exceeds the timeout', () => {
3030

3131
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
3232
const {rest, summary} = extractSummary(stderr);
33-
expect(rest).toMatch(
34-
/(jest\.setTimeout|jasmine\.DEFAULT_TIMEOUT_INTERVAL|Exceeded timeout)/,
35-
);
33+
const regexToMatch =
34+
process.env.JEST_JASMINE === '1'
35+
? /(Async callback was not invoked within the 20 ms timeout specified by jest\.setTimeout\.)/
36+
: /(Exceeded timeout of 20 ms for a test\.)/;
37+
38+
expect(rest).toMatch(/(jest\.setTimeout\(20\))/);
39+
expect(rest).toMatch(regexToMatch);
3640
expect(summary).toMatchSnapshot();
3741
expect(exitCode).toBe(1);
3842
});
@@ -77,9 +81,11 @@ test('exceeds the command line testTimeout', () => {
7781
'--testTimeout=200',
7882
]);
7983
const {rest, summary} = extractSummary(stderr);
80-
expect(rest).toMatch(
81-
/(jest\.setTimeout|jasmine\.DEFAULT_TIMEOUT_INTERVAL|Exceeded timeout)/,
82-
);
84+
const regexToMatch =
85+
process.env.JEST_JASMINE === '1'
86+
? /(Async callback was not invoked within the 200 ms timeout specified by jest\.setTimeout\.)/
87+
: /(Exceeded timeout of 200 ms for a test\.)/;
88+
expect(rest).toMatch(regexToMatch);
8389
expect(summary).toMatchSnapshot();
8490
expect(exitCode).toBe(1);
8591
});
@@ -108,6 +114,50 @@ test('does not exceed the command line testTimeout', () => {
108114
expect(exitCode).toBe(0);
109115
});
110116

117+
test('exceeds the timeout parameter', () => {
118+
writeFiles(DIR, {
119+
'__tests__/a-banana.js': `
120+
121+
test('banana', () => {
122+
return new Promise(resolve => {
123+
setTimeout(resolve, 1000);
124+
});
125+
}, 200);
126+
`,
127+
'package.json': '{}',
128+
});
129+
130+
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
131+
const {rest, summary} = extractSummary(stderr);
132+
const regexToMatch =
133+
process.env.JEST_JASMINE === '1'
134+
? /(Async callback was not invoked within the 200 ms timeout specified by jest\.setTimeout\.)/
135+
: /(Exceeded timeout of 200 ms for a test\.)/;
136+
expect(rest).toMatch(regexToMatch);
137+
expect(summary).toMatchSnapshot();
138+
expect(exitCode).toBe(1);
139+
});
140+
141+
test('does not exceed the timeout parameter', () => {
142+
writeFiles(DIR, {
143+
'__tests__/a-banana.js': `
144+
145+
test('banana', () => {
146+
return new Promise(resolve => {
147+
setTimeout(resolve, 200);
148+
});
149+
}, 1000);
150+
`,
151+
'package.json': '{}',
152+
});
153+
154+
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
155+
const {rest, summary} = extractSummary(stderr);
156+
expect(rest).toMatchSnapshot();
157+
expect(summary).toMatchSnapshot();
158+
expect(exitCode).toBe(0);
159+
});
160+
111161
test('exceeds the timeout specifying that `done` has not been called', () => {
112162
writeFiles(DIR, {
113163
'__tests__/a-banana.js': `
@@ -122,9 +172,12 @@ test('exceeds the timeout specifying that `done` has not been called', () => {
122172

123173
const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
124174
const {rest, summary} = extractSummary(stderr);
125-
expect(rest).toMatch(
126-
/(jest\.setTimeout|Exceeded timeout\.while waiting for `done()` to be called)/,
127-
);
175+
const regexToMatch =
176+
process.env.JEST_JASMINE === '1'
177+
? /(Async callback was not invoked within the 20 ms timeout specified by jest\.setTimeout\.)/
178+
: /(Exceeded timeout of 20 ms for a test while waiting for `done\(\)` to be called\.)/;
179+
expect(rest).toMatch(/(jest\.setTimeout\(20\))/);
180+
expect(rest).toMatch(regexToMatch);
128181
expect(summary).toMatchSnapshot();
129182
expect(exitCode).toBe(1);
130183
});

packages/jest-circus/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const _makeTimeoutMessage = (
179179
`Exceeded timeout of ${formatTime(timeout)} for a ${
180180
isHook ? 'hook' : 'test'
181181
}${
182-
takesDoneCallback && ' while waiting for `done()` to be called'
182+
takesDoneCallback ? ' while waiting for `done()` to be called' : ''
183183
}.\nAdd a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout.`;
184184

185185
// Global values can be overwritten by mocks or tests. We'll capture

0 commit comments

Comments
 (0)