From 2cbc1d6b1526f53e3d33f4e866e5c0000be79fa5 Mon Sep 17 00:00:00 2001 From: Dercilio Fontes Date: Fri, 24 Feb 2023 19:37:48 -0500 Subject: [PATCH 1/6] fix: Avoid creating the word testfalse in the message on test timeout --- packages/jest-circus/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index f59fd2886b80..13cf3b321e05 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -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 From fecfe4da45debfe3f23f3460e56706b3f22b4d94 Mon Sep 17 00:00:00 2001 From: Dercilio Fontes Date: Fri, 24 Feb 2023 19:41:06 -0500 Subject: [PATCH 2/6] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac7e81d9a9c..e0252c0fa115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ([#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 From 0c2d69fc61af02453aec11746ff06193ca40382d Mon Sep 17 00:00:00 2001 From: Dercilio Fontes Date: Sat, 25 Feb 2023 19:24:28 -0500 Subject: [PATCH 3/6] Updated timeouts test --- .../__snapshots__/timeouts.test.ts.snap | 34 ++++++++++++ e2e/__tests__/timeouts.test.ts | 53 ++++++++++++++++--- 2 files changed, 80 insertions(+), 7 deletions(-) diff --git a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap index 70a79392c7cc..a90970b10f7a 100644 --- a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap @@ -13,6 +13,19 @@ Time: <> Ran all test suites." `; +exports[`does not exceed the command line testTimeout 3`] = ` +"PASS __tests__/a-banana.js + ✓ banana" +`; + +exports[`does not exceed the command line testTimeout 4`] = ` +"Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites." +`; + exports[`does not exceed the timeout 1`] = ` "PASS __tests__/a-banana.js ✓ banana" @@ -26,6 +39,19 @@ Time: <> 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: <> +Ran all test suites." +`; + exports[`exceeds the command line testTimeout 1`] = ` "Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total @@ -42,6 +68,14 @@ Time: <> 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: <> +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 diff --git a/e2e/__tests__/timeouts.test.ts b/e2e/__tests__/timeouts.test.ts index 8a462042ed1f..26091e880584 100644 --- a/e2e/__tests__/timeouts.test.ts +++ b/e2e/__tests__/timeouts.test.ts @@ -30,9 +30,9 @@ 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)/, - ); + + expect(rest).toMatch(/(jest\.setTimeout\(20\))/); + expect(rest).toMatch(/(Exceeded timeout of 20 ms for a test\.)/); expect(summary).toMatchSnapshot(); expect(exitCode).toBe(1); }); @@ -77,9 +77,7 @@ test('exceeds the command line testTimeout', () => { '--testTimeout=200', ]); const {rest, summary} = extractSummary(stderr); - expect(rest).toMatch( - /(jest\.setTimeout|jasmine\.DEFAULT_TIMEOUT_INTERVAL|Exceeded timeout)/, - ); + expect(rest).toMatch(/(Exceeded timeout of 200 ms for a test\.)/); expect(summary).toMatchSnapshot(); expect(exitCode).toBe(1); }); @@ -108,6 +106,46 @@ 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); + expect(rest).toMatch(/(Exceeded timeout of 200 ms for a test\.)/); + 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': ` @@ -122,8 +160,9 @@ 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\(20\))/); expect(rest).toMatch( - /(jest\.setTimeout|Exceeded timeout\.while waiting for `done()` to be called)/, + /(Exceeded timeout of 20 ms for a test while waiting for `done\(\)` to be called\.)/, ); expect(summary).toMatchSnapshot(); expect(exitCode).toBe(1); From 3c11598da3f7419ef5ede94699ccd0e103dd9a44 Mon Sep 17 00:00:00 2001 From: Dercilio Fontes Date: Sat, 25 Feb 2023 19:30:29 -0500 Subject: [PATCH 4/6] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0252c0fa115..f4f5bbe26c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +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 ([#13954](https://github.com/facebook/jest/pull/13954)) +- `[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 From 3138ae65c7034d2e7c1666cc72975bd0adbbd7bf Mon Sep 17 00:00:00 2001 From: Dercilio Fontes Date: Sat, 25 Feb 2023 20:31:53 -0500 Subject: [PATCH 5/6] Created regexToMatch checking for JEST_JASMINE --- e2e/__tests__/timeouts.test.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/e2e/__tests__/timeouts.test.ts b/e2e/__tests__/timeouts.test.ts index 26091e880584..d369665f5f5b 100644 --- a/e2e/__tests__/timeouts.test.ts +++ b/e2e/__tests__/timeouts.test.ts @@ -30,9 +30,13 @@ test('exceeds the timeout', () => { 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 20 ms timeout specified by jest\.setTimeout\.)/ + : /(Exceeded timeout of 20 ms for a test\.)/; expect(rest).toMatch(/(jest\.setTimeout\(20\))/); - expect(rest).toMatch(/(Exceeded timeout of 20 ms for a test\.)/); + expect(rest).toMatch(regexToMatch); expect(summary).toMatchSnapshot(); expect(exitCode).toBe(1); }); @@ -77,7 +81,11 @@ test('exceeds the command line testTimeout', () => { '--testTimeout=200', ]); const {rest, summary} = extractSummary(stderr); - expect(rest).toMatch(/(Exceeded timeout of 200 ms for a test\.)/); + 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); }); @@ -121,7 +129,11 @@ test('exceeds the timeout parameter', () => { const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']); const {rest, summary} = extractSummary(stderr); - expect(rest).toMatch(/(Exceeded timeout of 200 ms for a test\.)/); + 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); }); @@ -160,10 +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); + 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( - /(Exceeded timeout of 20 ms for a test while waiting for `done\(\)` to be called\.)/, - ); + expect(rest).toMatch(regexToMatch); expect(summary).toMatchSnapshot(); expect(exitCode).toBe(1); }); From 73a5e68df20b1a58a5e842d8c02c361d07b177ac Mon Sep 17 00:00:00 2001 From: Dercilio Fontes Date: Sat, 25 Feb 2023 20:41:26 -0500 Subject: [PATCH 6/6] Removed snapshots --- e2e/__tests__/__snapshots__/timeouts.test.ts.snap | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap index a90970b10f7a..b68b979b731b 100644 --- a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap @@ -13,19 +13,6 @@ Time: <> Ran all test suites." `; -exports[`does not exceed the command line testTimeout 3`] = ` -"PASS __tests__/a-banana.js - ✓ banana" -`; - -exports[`does not exceed the command line testTimeout 4`] = ` -"Test Suites: 1 passed, 1 total -Tests: 1 passed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites." -`; - exports[`does not exceed the timeout 1`] = ` "PASS __tests__/a-banana.js ✓ banana"