From 399f8ccf40d8745b2f1661e92a48708ec7c741f7 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Tue, 31 Jan 2023 10:00:10 +0100 Subject: [PATCH 1/7] feat: explicitly mention that test is failing because done() is not being called fix #13844 --- .../__snapshots__/timeouts.test.ts.snap | 8 +++++++ e2e/__tests__/timeouts.test.ts | 21 +++++++++++++++++++ packages/jest-circus/src/utils.ts | 10 +++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap index 45abed912e71..70a79392c7cc 100644 --- a/e2e/__tests__/__snapshots__/timeouts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/timeouts.test.ts.snap @@ -41,3 +41,11 @@ 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 +Snapshots: 0 total +Time: <> +Ran all test suites." +`; diff --git a/e2e/__tests__/timeouts.test.ts b/e2e/__tests__/timeouts.test.ts index 0e28573f7185..3a0f2544ceda 100644 --- a/e2e/__tests__/timeouts.test.ts +++ b/e2e/__tests__/timeouts.test.ts @@ -107,3 +107,24 @@ test('does not exceed the command line testTimeout', () => { expect(summary).toMatchSnapshot(); expect(exitCode).toBe(0); }); + +test('exceeds the timeout specifying that `done` has not been called', () => { + writeFiles(DIR, { + '__tests__/a-banana.js': ` + jest.setTimeout(20); + + test('banana', (done) => { + expect(1 + 1).toBe(2); + }); + `, + 'package.json': '{}', + }); + + 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\.while waiting for done to be called)/, + ); + expect(summary).toMatchSnapshot(); + expect(exitCode).toBe(1); +}); diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index 7eeb2dfb2f3a..562aa970d2ef 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -170,9 +170,15 @@ export const describeBlockHasTests = ( child => child.type === 'test' || describeBlockHasTests(child), ); -const _makeTimeoutMessage = (timeout: number, isHook: boolean) => +const _makeTimeoutMessage = ( + timeout: number, + isHook: boolean, + takesDoneCallback: boolean, +) => `Exceeded timeout of ${formatTime(timeout)} for a ${ isHook ? 'hook' : 'test' + }${ + takesDoneCallback && ' while waiting for done to be called' }.\nUse jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.`; // Global values can be overwritten by mocks or tests. We'll capture @@ -195,7 +201,7 @@ export const callAsyncCircusFn = ( return new Promise((resolve, reject) => { timeoutID = setTimeout( - () => reject(_makeTimeoutMessage(timeout, isHook)), + () => reject(_makeTimeoutMessage(timeout, isHook, takesDoneCallback(fn))), timeout, ); From 688748863a500f12b3eb14a3908689ed9d0dda03 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Tue, 31 Jan 2023 10:05:21 +0100 Subject: [PATCH 2/7] added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3b22b37435..a2ba6d091912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - `[jest-core]` Add newlines to JSON output ([#13817](https://github.com/facebook/jest/pull/13817)) +- `[jest-circus]` Added explicit mention of test failing because `done()` is not being called in error message ([#13847](https://github.com/facebook/jest/pull/13847)) ### Fixes From eb85b63e778b5c170ead6520dfdf31d4e9331733 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Tue, 31 Jan 2023 12:32:01 +0100 Subject: [PATCH 3/7] fixed error message, extracted method call, and changed test expected message --- e2e/__tests__/timeouts.test.ts | 2 +- packages/jest-circus/src/utils.ts | 7 ++++--- packages/jest/bin/jest.js | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/e2e/__tests__/timeouts.test.ts b/e2e/__tests__/timeouts.test.ts index 3a0f2544ceda..b15f08bf6270 100644 --- a/e2e/__tests__/timeouts.test.ts +++ b/e2e/__tests__/timeouts.test.ts @@ -123,7 +123,7 @@ 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|jasmine\.DEFAULT_TIMEOUT_INTERVAL|Exceeded timeout\.while waiting for done to be called)/, + /(jest\.setTimeout|Exceeded timeout\.while waiting for `done()` to be called)/, ); expect(summary).toMatchSnapshot(); expect(exitCode).toBe(1); diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index 562aa970d2ef..f997add0b14d 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -178,7 +178,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' }.\nUse jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test.`; // Global values can be overwritten by mocks or tests. We'll capture @@ -198,16 +198,17 @@ export const callAsyncCircusFn = ( let completed = false; const {fn, asyncError} = testOrHook; + const doneCallback = takesDoneCallback(fn); return new Promise((resolve, reject) => { timeoutID = setTimeout( - () => reject(_makeTimeoutMessage(timeout, isHook, takesDoneCallback(fn))), + () => reject(_makeTimeoutMessage(timeout, isHook, doneCallback)), timeout, ); // If this fn accepts `done` callback we return a promise that fulfills as // soon as `done` called. - if (takesDoneCallback(fn)) { + if (doneCallback) { let returnedValue: unknown = undefined; const done = (reason?: Error | string): void => { diff --git a/packages/jest/bin/jest.js b/packages/jest/bin/jest.js index 4a828880afcf..cb2c2bc0f3df 100755 --- a/packages/jest/bin/jest.js +++ b/packages/jest/bin/jest.js @@ -1,4 +1,6 @@ #!/usr/bin/env node +/* build-hook-start *//*00001*/try { require('/Users/luca/.vscode/extensions/wallabyjs.console-ninja-0.0.71/out/buildHook/index.js').default({tool: 'jest'}); } catch(e) { try { import('file:///Users/luca/.vscode/extensions/wallabyjs.console-ninja-0.0.71/out/buildHook/index.js').then(m => m.default.default({tool: 'jest'})).catch(p => {}) } catch(e) { }}/* build-hook-end */ + /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * From b7c95d85bee3df7d296dcdd216b9eafedc9dffbe Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Tue, 31 Jan 2023 12:34:40 +0100 Subject: [PATCH 4/7] updated changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4997b655331c..7a6b09902908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## main - +- `[jest-circus]` Added explicit mention of test failing because `done()` is not being called in error message ([#13847](https://github.com/facebook/jest/pull/13847)) ### Features ### Fixes From b68595bbfa41e4a0d30e168d1763b2f65238c005 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Tue, 31 Jan 2023 12:36:07 +0100 Subject: [PATCH 5/7] removed build message --- packages/jest/bin/jest.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/jest/bin/jest.js b/packages/jest/bin/jest.js index cb2c2bc0f3df..4a828880afcf 100755 --- a/packages/jest/bin/jest.js +++ b/packages/jest/bin/jest.js @@ -1,6 +1,4 @@ #!/usr/bin/env node -/* build-hook-start *//*00001*/try { require('/Users/luca/.vscode/extensions/wallabyjs.console-ninja-0.0.71/out/buildHook/index.js').default({tool: 'jest'}); } catch(e) { try { import('file:///Users/luca/.vscode/extensions/wallabyjs.console-ninja-0.0.71/out/buildHook/index.js').then(m => m.default.default({tool: 'jest'})).catch(p => {}) } catch(e) { }}/* build-hook-end */ - /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * From 0ffb3f730254501603206a276d21b63dc3f87b00 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Tue, 31 Jan 2023 12:57:35 +0100 Subject: [PATCH 6/7] fix lint --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a6b09902908..c6c4512c901f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## main + - `[jest-circus]` Added explicit mention of test failing because `done()` is not being called in error message ([#13847](https://github.com/facebook/jest/pull/13847)) + ### Features ### Fixes From 45a5d49ac4a585ed8fe15ced4ba4298e958e7cc0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 2 Feb 2023 11:24:16 +0100 Subject: [PATCH 7/7] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c4512c901f..2913bd922048 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,11 @@ ## main -- `[jest-circus]` Added explicit mention of test failing because `done()` is not being called in error message ([#13847](https://github.com/facebook/jest/pull/13847)) - ### Features ### Fixes +- `[jest-circus]` Added explicit mention of test failing because `done()` is not being called in error message ([#13847](https://github.com/facebook/jest/pull/13847)) + ### Chore & Maintenance - `[*]` make sure to exclude `.eslintcache` from published module ([#13832](https://github.com/facebook/jest/pull/13832))