Skip to content

Commit

Permalink
fix: Avoid creating the word testfalse in the message on test timeout (
Browse files Browse the repository at this point in the history
  • Loading branch information
DercilioFontes authored Feb 26, 2023
1 parent 92630a6 commit bb39cb2
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

- `[jest-circus]` Send test case results for `todo` tests ([#13915](https://github.com/facebook/jest/pull/13915))
- `[jest-circus]` Update message printed on test timeout ([#13830](https://github.com/facebook/jest/pull/13830))
- `[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))
- `[@jest/test-result]` Allow `TestResultsProcessor` type to return a Promise ([#13950](https://github.com/facebook/jest/pull/13950))

### Chore & Maintenance
Expand Down
21 changes: 21 additions & 0 deletions e2e/__tests__/__snapshots__/timeouts.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ Time: <<REPLACED>>
Ran all test suites."
`;
exports[`does not exceed the timeout parameter 1`] = `
"PASS __tests__/a-banana.js
✓ banana"
`;
exports[`does not exceed the timeout parameter 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites."
`;
exports[`exceeds the command line testTimeout 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Expand All @@ -42,6 +55,14 @@ Time: <<REPLACED>>
Ran all test suites."
`;
exports[`exceeds the timeout parameter 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites."
`;
exports[`exceeds the timeout specifying that \`done\` has not been called 1`] = `
"Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Expand Down
71 changes: 62 additions & 9 deletions e2e/__tests__/timeouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ test('exceeds the timeout', () => {

const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
const {rest, summary} = extractSummary(stderr);
expect(rest).toMatch(
/(jest\.setTimeout|jasmine\.DEFAULT_TIMEOUT_INTERVAL|Exceeded timeout)/,
);
const regexToMatch =
process.env.JEST_JASMINE === '1'
? /(Async callback was not invoked within the 20 ms timeout specified by jest\.setTimeout\.)/
: /(Exceeded timeout of 20 ms for a test\.)/;

expect(rest).toMatch(/(jest\.setTimeout\(20\))/);
expect(rest).toMatch(regexToMatch);
expect(summary).toMatchSnapshot();
expect(exitCode).toBe(1);
});
Expand Down Expand Up @@ -77,9 +81,11 @@ test('exceeds the command line testTimeout', () => {
'--testTimeout=200',
]);
const {rest, summary} = extractSummary(stderr);
expect(rest).toMatch(
/(jest\.setTimeout|jasmine\.DEFAULT_TIMEOUT_INTERVAL|Exceeded timeout)/,
);
const regexToMatch =
process.env.JEST_JASMINE === '1'
? /(Async callback was not invoked within the 200 ms timeout specified by jest\.setTimeout\.)/
: /(Exceeded timeout of 200 ms for a test\.)/;
expect(rest).toMatch(regexToMatch);
expect(summary).toMatchSnapshot();
expect(exitCode).toBe(1);
});
Expand Down Expand Up @@ -108,6 +114,50 @@ test('does not exceed the command line testTimeout', () => {
expect(exitCode).toBe(0);
});

test('exceeds the timeout parameter', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
test('banana', () => {
return new Promise(resolve => {
setTimeout(resolve, 1000);
});
}, 200);
`,
'package.json': '{}',
});

const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
const {rest, summary} = extractSummary(stderr);
const regexToMatch =
process.env.JEST_JASMINE === '1'
? /(Async callback was not invoked within the 200 ms timeout specified by jest\.setTimeout\.)/
: /(Exceeded timeout of 200 ms for a test\.)/;
expect(rest).toMatch(regexToMatch);
expect(summary).toMatchSnapshot();
expect(exitCode).toBe(1);
});

test('does not exceed the timeout parameter', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
test('banana', () => {
return new Promise(resolve => {
setTimeout(resolve, 200);
});
}, 1000);
`,
'package.json': '{}',
});

const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
const {rest, summary} = extractSummary(stderr);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
expect(exitCode).toBe(0);
});

test('exceeds the timeout specifying that `done` has not been called', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `
Expand All @@ -122,9 +172,12 @@ test('exceeds the timeout specifying that `done` has not been called', () => {

const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']);
const {rest, summary} = extractSummary(stderr);
expect(rest).toMatch(
/(jest\.setTimeout|Exceeded timeout\.while waiting for `done()` to be called)/,
);
const regexToMatch =
process.env.JEST_JASMINE === '1'
? /(Async callback was not invoked within the 20 ms timeout specified by jest\.setTimeout\.)/
: /(Exceeded timeout of 20 ms for a test while waiting for `done\(\)` to be called\.)/;
expect(rest).toMatch(/(jest\.setTimeout\(20\))/);
expect(rest).toMatch(regexToMatch);
expect(summary).toMatchSnapshot();
expect(exitCode).toBe(1);
});
2 changes: 1 addition & 1 deletion packages/jest-circus/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const _makeTimeoutMessage = (
`Exceeded timeout of ${formatTime(timeout)} for a ${
isHook ? 'hook' : 'test'
}${
takesDoneCallback && ' while waiting for `done()` to be called'
takesDoneCallback ? ' while waiting for `done()` to be called' : ''
}.\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.`;

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

0 comments on commit bb39cb2

Please sign in to comment.