From df7d9f67d572e70c9d042eb7d628dc5575570079 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Tue, 8 Sep 2020 09:14:19 -0700 Subject: [PATCH 1/7] fix(types): Remove .each void type --- packages/jest-types/src/Global.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 2102d0c0e4b4..1f43c868aa22 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -36,16 +36,10 @@ export type EachTestFn = ( // TODO: Get rid of this at some point type Jasmine = {_DEFAULT_TIMEOUT_INTERVAL?: number; addMatchers: Function}; -type Each = - | (( - table: EachTable, - ...taggedTemplateData: Array - ) => ( - title: string, - test: EachTestFn, - timeout?: number, - ) => void) - | (() => void); +type Each = ( + table: EachTable, + ...taggedTemplateData: Array +) => (title: string, test: EachTestFn, timeout?: number) => void; export interface ItBase { (testName: TestName, fn: TestFn, timeout?: number): void; From 9486ac8fed70b22a164411164000752d941e3b67 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Tue, 8 Sep 2020 09:17:28 -0700 Subject: [PATCH 2/7] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8951b25c58ee..aae8490876f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - `[jest-circus, jest-config, jest-runtime]` Add new `injectGlobals` config and CLI option to disable injecting global variables into the runtime ([#10484](https://github.com/facebook/jest/pull/10484)) +- `[jest-each]` Remove void return type of .each in globals ([#10447](https://github.com/facebook/jest/pull/10447)) ### Fixes From 9d6051509876072df6d485a47425cf21040f5568 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Tue, 8 Sep 2020 09:41:41 -0700 Subject: [PATCH 3/7] Allow no parameters as long as the return type is always callable --- CHANGELOG.md | 2 +- packages/jest-jasmine2/src/jasmineAsyncInstall.ts | 2 +- packages/jest-types/src/Global.ts | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aae8490876f2..14a21b4fc0ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Features - `[jest-circus, jest-config, jest-runtime]` Add new `injectGlobals` config and CLI option to disable injecting global variables into the runtime ([#10484](https://github.com/facebook/jest/pull/10484)) -- `[jest-each]` Remove void return type of .each in globals ([#10447](https://github.com/facebook/jest/pull/10447)) +- `[jest-each]` Fixes `.each` type to always be callable ([#10447](https://github.com/facebook/jest/pull/10447)) ### Fixes diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index f17288875fd7..db15f338ed75 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -192,7 +192,7 @@ function makeConcurrent( return spec; }; // each is binded after the function is made concurrent, so for now it is made noop - concurrentFn.each = () => {}; + concurrentFn.each = () => () => {}; return concurrentFn; } diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 1f43c868aa22..125c4cfb8d81 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -36,10 +36,16 @@ export type EachTestFn = ( // TODO: Get rid of this at some point type Jasmine = {_DEFAULT_TIMEOUT_INTERVAL?: number; addMatchers: Function}; -type Each = ( - table: EachTable, - ...taggedTemplateData: Array -) => (title: string, test: EachTestFn, timeout?: number) => void; +type Each = + | (( + table: EachTable, + ...taggedTemplateData: Array + ) => ( + title: string, + test: EachTestFn, + timeout?: number, + ) => void) + | (() => () => void); export interface ItBase { (testName: TestName, fn: TestFn, timeout?: number): void; From aac5b52bc2736e612dca4a8c3a4b2f00071d3da8 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Tue, 8 Sep 2020 10:00:45 -0700 Subject: [PATCH 4/7] prettier --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a21b4fc0ae..3de39f1bb2ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Features - `[jest-circus, jest-config, jest-runtime]` Add new `injectGlobals` config and CLI option to disable injecting global variables into the runtime ([#10484](https://github.com/facebook/jest/pull/10484)) -- `[jest-each]` Fixes `.each` type to always be callable ([#10447](https://github.com/facebook/jest/pull/10447)) +- `[jest-each]` Fixes `.each` type to always be callable ([#10447](https://github.com/facebook/jest/pull/10447)) ### Fixes From 394c34e94ceb7135a933ed5e1b96945c59e348b9 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Sat, 12 Sep 2020 20:14:12 -0700 Subject: [PATCH 5/7] add tests for each return types --- test-types/top-level-globals.test.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test-types/top-level-globals.test.ts b/test-types/top-level-globals.test.ts index d79fb931dd2b..ad0de4d9ba80 100644 --- a/test-types/top-level-globals.test.ts +++ b/test-types/top-level-globals.test.ts @@ -8,11 +8,19 @@ */ import {expectType} from 'mlh-tsd'; -//eslint-disable-next-line import/no-extraneous-dependencies -import {afterAll, afterEach, beforeAll, beforeEach} from '@jest/globals'; +import { + afterAll, + afterEach, + beforeAll, + beforeEach, + describe, + test, + //eslint-disable-next-line import/no-extraneous-dependencies +} from '@jest/globals'; const fn = () => {}; const timeout = 5; +const testTable = [[1, 2]]; // https://jestjs.io/docs/en/api#methods expectType(afterAll(fn)); @@ -23,3 +31,13 @@ expectType(beforeAll(fn)); expectType(beforeAll(fn, timeout)); expectType(beforeEach(fn)); expectType(beforeEach(fn, timeout)); + +expectType(test.each(testTable)); +expectType(test.only.each(testTable)); +expectType(test.skip.each(testTable)); +expectType(test.concurrent.each(testTable)); +expectType(test.concurrent.only.each(testTable)); +expectType(test.concurrent.skip.each(testTable)); +expectType(describe.each(testTable)); +expectType(describe.only.each(testTable)); +expectType(describe.skip.each(testTable)); From 843ebc69fa250e5cb5faf8b96b9788ab6babd0a4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 13 Sep 2020 08:57:46 +0200 Subject: [PATCH 6/7] tweak tests --- test-types/top-level-globals.test.ts | 38 +++++++++++++++++++++------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/test-types/top-level-globals.test.ts b/test-types/top-level-globals.test.ts index ad0de4d9ba80..a66021ee1135 100644 --- a/test-types/top-level-globals.test.ts +++ b/test-types/top-level-globals.test.ts @@ -19,25 +19,45 @@ import { } from '@jest/globals'; const fn = () => {}; +const asyncFn = async () => {}; const timeout = 5; const testTable = [[1, 2]]; // https://jestjs.io/docs/en/api#methods expectType(afterAll(fn)); +expectType(afterAll(asyncFn)); expectType(afterAll(fn, timeout)); expectType(afterEach(fn)); +expectType(afterEach(asyncFn)); expectType(afterEach(fn, timeout)); expectType(beforeAll(fn)); +expectType(beforeAll(asyncFn)); expectType(beforeAll(fn, timeout)); expectType(beforeEach(fn)); +expectType(beforeEach(asyncFn)); expectType(beforeEach(fn, timeout)); -expectType(test.each(testTable)); -expectType(test.only.each(testTable)); -expectType(test.skip.each(testTable)); -expectType(test.concurrent.each(testTable)); -expectType(test.concurrent.only.each(testTable)); -expectType(test.concurrent.skip.each(testTable)); -expectType(describe.each(testTable)); -expectType(describe.only.each(testTable)); -expectType(describe.skip.each(testTable)); +expectType(test.each(testTable)('Test name', fn)); +expectType(test.each(testTable)('Test name', fn, timeout)); +expectType(test.only.each(testTable)('Test name', fn)); +expectType(test.only.each(testTable)('Test name', fn, timeout)); +expectType(test.skip.each(testTable)('Test name', fn)); +expectType(test.skip.each(testTable)('Test name', fn, timeout)); +expectType(test.concurrent.each(testTable)('Test name', asyncFn)); +expectType( + test.concurrent.each(testTable)('Test name', asyncFn, timeout), +); +expectType(test.concurrent.only.each(testTable)('Test name', asyncFn)); +expectType( + test.concurrent.only.each(testTable)('Test name', asyncFn, timeout), +); +expectType(test.concurrent.skip.each(testTable)('Test name', asyncFn)); +expectType( + test.concurrent.skip.each(testTable)('Test name', asyncFn, timeout), +); +expectType(describe.each(testTable)('Test name', fn)); +expectType(describe.each(testTable)('Test name', fn, timeout)); +expectType(describe.only.each(testTable)('Test name', fn)); +expectType(describe.only.each(testTable)('Test name', fn, timeout)); +expectType(describe.skip.each(testTable)('Test name', fn)); +expectType(describe.skip.each(testTable)('Test name', fn, timeout)); From 5f481ccba94bb1f7eecb23e97b7da63ef930002d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 13 Sep 2020 09:27:50 +0200 Subject: [PATCH 7/7] constant --- test-types/top-level-globals.test.ts | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/test-types/top-level-globals.test.ts b/test-types/top-level-globals.test.ts index a66021ee1135..9b6499411362 100644 --- a/test-types/top-level-globals.test.ts +++ b/test-types/top-level-globals.test.ts @@ -21,6 +21,7 @@ import { const fn = () => {}; const asyncFn = async () => {}; const timeout = 5; +const testName = 'Test name'; const testTable = [[1, 2]]; // https://jestjs.io/docs/en/api#methods @@ -37,27 +38,25 @@ expectType(beforeEach(fn)); expectType(beforeEach(asyncFn)); expectType(beforeEach(fn, timeout)); -expectType(test.each(testTable)('Test name', fn)); -expectType(test.each(testTable)('Test name', fn, timeout)); -expectType(test.only.each(testTable)('Test name', fn)); -expectType(test.only.each(testTable)('Test name', fn, timeout)); -expectType(test.skip.each(testTable)('Test name', fn)); -expectType(test.skip.each(testTable)('Test name', fn, timeout)); -expectType(test.concurrent.each(testTable)('Test name', asyncFn)); +expectType(test.each(testTable)(testName, fn)); +expectType(test.each(testTable)(testName, fn, timeout)); +expectType(test.only.each(testTable)(testName, fn)); +expectType(test.only.each(testTable)(testName, fn, timeout)); +expectType(test.skip.each(testTable)(testName, fn)); +expectType(test.skip.each(testTable)(testName, fn, timeout)); +expectType(test.concurrent.each(testTable)(testName, asyncFn)); +expectType(test.concurrent.each(testTable)(testName, asyncFn, timeout)); +expectType(test.concurrent.only.each(testTable)(testName, asyncFn)); expectType( - test.concurrent.each(testTable)('Test name', asyncFn, timeout), + test.concurrent.only.each(testTable)(testName, asyncFn, timeout), ); -expectType(test.concurrent.only.each(testTable)('Test name', asyncFn)); +expectType(test.concurrent.skip.each(testTable)(testName, asyncFn)); expectType( - test.concurrent.only.each(testTable)('Test name', asyncFn, timeout), + test.concurrent.skip.each(testTable)(testName, asyncFn, timeout), ); -expectType(test.concurrent.skip.each(testTable)('Test name', asyncFn)); -expectType( - test.concurrent.skip.each(testTable)('Test name', asyncFn, timeout), -); -expectType(describe.each(testTable)('Test name', fn)); -expectType(describe.each(testTable)('Test name', fn, timeout)); -expectType(describe.only.each(testTable)('Test name', fn)); -expectType(describe.only.each(testTable)('Test name', fn, timeout)); -expectType(describe.skip.each(testTable)('Test name', fn)); -expectType(describe.skip.each(testTable)('Test name', fn, timeout)); +expectType(describe.each(testTable)(testName, fn)); +expectType(describe.each(testTable)(testName, fn, timeout)); +expectType(describe.only.each(testTable)(testName, fn)); +expectType(describe.only.each(testTable)(testName, fn, timeout)); +expectType(describe.skip.each(testTable)(testName, fn)); +expectType(describe.skip.each(testTable)(testName, fn, timeout));