diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index a25747da2a2d..c3053b6da00f 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -1,22 +1,7 @@ { + "extends": "../tsconfig.test.json", "compilerOptions": { - "noEmit": true, - - "target": "es2017", - "module": "commonjs", - "lib": ["dom", "es2017"], - "strict": true, - - /* Additional Checks */ - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - - /* Module Resolution Options */ - "moduleResolution": "node", - "isolatedModules": true, - "importsNotUsedAsValues": "error", - "resolveJsonModule": true - } + "rootDir": "./" + }, + "include": ["./**/*"] } diff --git a/examples/angular/package.json b/examples/angular/package.json index 6fbd7ff98032..cb64e7476e6d 100644 --- a/examples/angular/package.json +++ b/examples/angular/package.json @@ -23,6 +23,7 @@ "@babel/plugin-proposal-decorators": "*", "@babel/preset-env": "^7.1.0", "@babel/preset-typescript": "^7.0.0", + "@jest/globals": "workspace:^", "babel-jest": "workspace:^", "babel-plugin-transform-typescript-metadata": "*", "jest": "workspace:^", diff --git a/examples/typescript/__tests__/CheckboxWithLabel-test.tsx b/examples/typescript/__tests__/CheckboxWithLabel-test.tsx index 96f73fb3f381..bd0a00239ce1 100644 --- a/examples/typescript/__tests__/CheckboxWithLabel-test.tsx +++ b/examples/typescript/__tests__/CheckboxWithLabel-test.tsx @@ -2,7 +2,8 @@ import * as React from 'react'; import * as TestUtils from 'react-dom/test-utils'; -const CheckboxWithLabel = require('../CheckboxWithLabel').default; +import {expect, it} from '@jest/globals'; +import CheckboxWithLabel from '../CheckboxWithLabel'; it('CheckboxWithLabel changes the text after click', () => { const checkboxLabelRef: React.RefObject = React.createRef(); diff --git a/examples/typescript/__tests__/calc.test.ts b/examples/typescript/__tests__/calc.test.ts index 7ee93ef04678..81003d8292f2 100644 --- a/examples/typescript/__tests__/calc.test.ts +++ b/examples/typescript/__tests__/calc.test.ts @@ -1,6 +1,6 @@ // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. -import {jest} from '@jest/globals'; +import {describe, expect, it, jest} from '@jest/globals'; import Memory from '../Memory'; import makeCalc from '../calc'; import sub from '../sub'; diff --git a/examples/typescript/__tests__/sub-test.ts b/examples/typescript/__tests__/sub-test.ts index 98633bcd3ea3..b6ccb828f104 100644 --- a/examples/typescript/__tests__/sub-test.ts +++ b/examples/typescript/__tests__/sub-test.ts @@ -1,5 +1,6 @@ // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +import {expect, it} from '@jest/globals'; import sub from '../sub'; it('subtracts 5 - 1 to equal 4 in TypeScript', () => { diff --git a/examples/typescript/__tests__/sum-test.ts b/examples/typescript/__tests__/sum-test.ts index 2eb4f77dd7c5..a401c5d46ac0 100644 --- a/examples/typescript/__tests__/sum-test.ts +++ b/examples/typescript/__tests__/sum-test.ts @@ -1,5 +1,7 @@ // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. +import {expect, it} from '@jest/globals'; + it('adds 1 + 2 to equal 3 in TScript', () => { // Generally, `import` should be used for TypeScript // as using `require` will not return any type information. diff --git a/examples/typescript/__tests__/sum.test.js b/examples/typescript/__tests__/sum.test.js index 613234f54d3e..3bcb0749a939 100644 --- a/examples/typescript/__tests__/sum.test.js +++ b/examples/typescript/__tests__/sum.test.js @@ -1,5 +1,7 @@ // Copyright 2004-present Facebook. All Rights Reserved. +import {expect, it} from '@jest/globals'; + it('adds 1 + 2 to equal 3 in Typescript', () => { const sum = require('../sum.ts').default; expect(sum(1, 2)).toBe(3); diff --git a/examples/typescript/package.json b/examples/typescript/package.json index ba82fc707a0d..3ca4c4463cf5 100644 --- a/examples/typescript/package.json +++ b/examples/typescript/package.json @@ -12,7 +12,7 @@ "@babel/preset-env": "^7.1.0", "@babel/preset-react": "^7.12.1", "@babel/preset-typescript": "^7.0.0", - "@types/jest": "^27.4.0", + "@jest/globals": "workspace:^", "babel-jest": "workspace:^", "jest": "workspace:^" }, diff --git a/package.json b/package.json index 4f0964d13fbd..360c57ab4600 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "@types/babel__generator": "^7.0.0", "@types/babel__template": "^7.0.2", "@types/dedent": "^0.7.0", - "@types/jest": "^27.4.0", "@types/node": "~14.14.45", "@types/which": "^2.0.0", "@typescript-eslint/eslint-plugin": "^5.14.0", diff --git a/packages/babel-jest/src/__tests__/tsconfig.json b/packages/babel-jest/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/babel-jest/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/babel-plugin-jest-hoist/src/__tests__/tsconfig.json b/packages/babel-plugin-jest-hoist/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/babel-plugin-jest-hoist/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/diff-sequences/src/__tests__/tsconfig.json b/packages/diff-sequences/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/diff-sequences/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/expect-utils/src/__tests__/isError.test.ts b/packages/expect-utils/src/__tests__/isError.test.ts index bb6a77c47e6d..8a25e970f153 100644 --- a/packages/expect-utils/src/__tests__/isError.test.ts +++ b/packages/expect-utils/src/__tests__/isError.test.ts @@ -7,6 +7,8 @@ * @jest-environment jsdom */ +/// + /* eslint-env browser */ import {isError} from '../utils'; diff --git a/packages/expect-utils/src/__tests__/tsconfig.json b/packages/expect-utils/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/expect-utils/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/expect/src/__tests__/toEqual-dom.test.ts b/packages/expect/src/__tests__/toEqual-dom.test.ts index 605c7e628537..864536dc39ca 100644 --- a/packages/expect/src/__tests__/toEqual-dom.test.ts +++ b/packages/expect/src/__tests__/toEqual-dom.test.ts @@ -6,6 +6,9 @@ * * @jest-environment jsdom */ + +/// + /* eslint-env browser*/ describe('toEqual', () => { diff --git a/packages/expect/src/__tests__/tsconfig.json b/packages/expect/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/expect/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-circus/src/__tests__/tsconfig.json b/packages/jest-circus/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-circus/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-circus/tsconfig.json b/packages/jest-circus/tsconfig.json index 67941a37790e..5722ca1d21ac 100644 --- a/packages/jest-circus/tsconfig.json +++ b/packages/jest-circus/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../tsconfig", "compilerOptions": { "outDir": "build", - "rootDir": "src", - // we don't want `@types/jest` to be referenced - "types": [] + "rootDir": "src" }, "include": ["./src/**/*"], "exclude": ["./**/__mocks__/**/*", "./**/__tests__/**/*"], diff --git a/packages/jest-cli/src/__tests__/tsconfig.json b/packages/jest-cli/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-cli/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-cli/src/init/__tests__/tsconfig.json b/packages/jest-cli/src/init/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-cli/src/init/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-config/src/__tests__/tsconfig.json b/packages/jest-config/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-config/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-console/src/__tests__/tsconfig.json b/packages/jest-console/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-console/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-core/src/__tests__/tsconfig.json b/packages/jest-core/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-core/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-core/src/lib/__tests__/tsconfig.json b/packages/jest-core/src/lib/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-core/src/lib/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-core/src/plugins/__tests__/tsconfig.json b/packages/jest-core/src/plugins/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-core/src/plugins/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-create-cache-key-function/src/__tests__/tsconfig.json b/packages/jest-create-cache-key-function/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-create-cache-key-function/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-diff/src/__tests__/tsconfig.json b/packages/jest-diff/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-diff/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-docblock/src/__tests__/tsconfig.json b/packages/jest-docblock/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-docblock/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-each/src/__tests__/tsconfig.json b/packages/jest-each/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-each/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-environment-jsdom/src/__tests__/tsconfig.json b/packages/jest-environment-jsdom/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-environment-jsdom/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-environment-node/src/__tests__/tsconfig.json b/packages/jest-environment-node/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-environment-node/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-environment/tsconfig.json b/packages/jest-environment/tsconfig.json index 3b0f77d1c9c5..4ac228a90ddf 100644 --- a/packages/jest-environment/tsconfig.json +++ b/packages/jest-environment/tsconfig.json @@ -1,8 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - // we don't want `@types/jest` to be referenced - "types": ["node"], "rootDir": "src", "outDir": "build" }, diff --git a/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts b/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts index b7ccac600f93..f9480b63dff2 100644 --- a/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts +++ b/packages/jest-fake-timers/src/__tests__/legacyFakeTimers.test.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/// + import * as util from 'util'; import {runInNewContext} from 'vm'; import {ModuleMocker} from 'jest-mock'; diff --git a/packages/jest-fake-timers/src/__tests__/tsconfig.json b/packages/jest-fake-timers/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-fake-timers/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-get-type/src/__tests__/tsconfig.json b/packages/jest-get-type/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-get-type/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-globals/src/__tests__/tsconfig.json b/packages/jest-globals/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-globals/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-globals/tsconfig.json b/packages/jest-globals/tsconfig.json index 90f222531f6b..06c39bed1061 100644 --- a/packages/jest-globals/tsconfig.json +++ b/packages/jest-globals/tsconfig.json @@ -1,8 +1,6 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - // we don't want `@types/jest` to be referenced - "types": [], "rootDir": "src", "outDir": "build" }, diff --git a/packages/jest-haste-map/src/__tests__/tsconfig.json b/packages/jest-haste-map/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-haste-map/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-haste-map/src/crawlers/__tests__/tsconfig.json b/packages/jest-haste-map/src/crawlers/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-haste-map/src/crawlers/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-haste-map/src/lib/__tests__/tsconfig.json b/packages/jest-haste-map/src/lib/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-haste-map/src/lib/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-jasmine2/src/__tests__/tsconfig.json b/packages/jest-jasmine2/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-jasmine2/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-jasmine2/tsconfig.json b/packages/jest-jasmine2/tsconfig.json index 3d2268f04774..ecd8d01247bf 100644 --- a/packages/jest-jasmine2/tsconfig.json +++ b/packages/jest-jasmine2/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../tsconfig", "compilerOptions": { "rootDir": "src", - "outDir": "build", - // we don't want `@types/jest` to be referenced - "types": [] + "outDir": "build" }, "include": ["./src/**/*"], "exclude": ["./**/__tests__/**/*"], diff --git a/packages/jest-leak-detector/src/__tests__/tsconfig.json b/packages/jest-leak-detector/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-leak-detector/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-matcher-utils/src/__tests__/deepCyclicCopyReplaceableDom.test.ts b/packages/jest-matcher-utils/src/__tests__/deepCyclicCopyReplaceableDom.test.ts index 31536d9c4372..80c68367e27b 100644 --- a/packages/jest-matcher-utils/src/__tests__/deepCyclicCopyReplaceableDom.test.ts +++ b/packages/jest-matcher-utils/src/__tests__/deepCyclicCopyReplaceableDom.test.ts @@ -6,7 +6,11 @@ * * @jest-environment jsdom */ + +/// + /* eslint-env browser*/ + import deepCyclicCopyReplaceable from '../deepCyclicCopyReplaceable'; test('should copy dom element', () => { diff --git a/packages/jest-matcher-utils/src/__tests__/tsconfig.json b/packages/jest-matcher-utils/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-matcher-utils/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-message-util/src/__tests__/tsconfig.json b/packages/jest-message-util/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-message-util/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-mock/src/__tests__/tsconfig.json b/packages/jest-mock/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-mock/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-regex-util/src/__tests__/tsconfig.json b/packages/jest-regex-util/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-regex-util/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-repl/src/__tests__/tsconfig.json b/packages/jest-repl/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-repl/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-reporters/src/__tests__/tsconfig.json b/packages/jest-reporters/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-reporters/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json b/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-resolve-dependencies/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-resolve/src/__tests__/tsconfig.json b/packages/jest-resolve/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-resolve/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-runner/src/__tests__/tsconfig.json b/packages/jest-runner/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-runner/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-runtime/src/__tests__/tsconfig.json b/packages/jest-runtime/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-runtime/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-snapshot/src/__tests__/tsconfig.json b/packages/jest-snapshot/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-snapshot/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-source-map/src/__tests__/tsconfig.json b/packages/jest-source-map/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-source-map/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-test-result/src/__tests__/tsconfig.json b/packages/jest-test-result/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-test-result/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-test-sequencer/src/__tests__/tsconfig.json b/packages/jest-test-sequencer/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-test-sequencer/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-transform/src/__tests__/tsconfig.json b/packages/jest-transform/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-transform/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-util/src/__tests__/tsconfig.json b/packages/jest-util/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-util/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-validate/src/__tests__/tsconfig.json b/packages/jest-validate/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-validate/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-watcher/src/lib/__tests__/tsconfig.json b/packages/jest-watcher/src/lib/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-watcher/src/lib/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-worker/src/__tests__/tsconfig.json b/packages/jest-worker/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/jest-worker/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-worker/src/base/__tests__/tsconfig.json b/packages/jest-worker/src/base/__tests__/tsconfig.json new file mode 100644 index 000000000000..406e8d978e62 --- /dev/null +++ b/packages/jest-worker/src/base/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../../" + }, + "include": ["../**/*"] +} diff --git a/packages/jest-worker/src/workers/__tests__/tsconfig.json b/packages/jest-worker/src/workers/__tests__/tsconfig.json new file mode 100644 index 000000000000..3ed459489903 --- /dev/null +++ b/packages/jest-worker/src/workers/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/pretty-format/src/__tests__/DOMElement.test.ts b/packages/pretty-format/src/__tests__/DOMElement.test.ts index 6a39f2576512..c8e14e83dfa5 100644 --- a/packages/pretty-format/src/__tests__/DOMElement.test.ts +++ b/packages/pretty-format/src/__tests__/DOMElement.test.ts @@ -6,6 +6,9 @@ * * @jest-environment jsdom */ + +/// + /* eslint-env browser*/ import prettyFormat, {plugins} from '../'; diff --git a/packages/pretty-format/src/__tests__/setPrettyPrint.ts b/packages/pretty-format/src/__tests__/setPrettyPrint.ts index 5317d89f9cce..e82ce4f9b87e 100644 --- a/packages/pretty-format/src/__tests__/setPrettyPrint.ts +++ b/packages/pretty-format/src/__tests__/setPrettyPrint.ts @@ -8,12 +8,9 @@ import prettyFormat from '../'; import type {OptionsReceived, Plugins} from '../types'; -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace jest { - interface Matchers { - toPrettyPrintTo(expected: unknown, options?: OptionsReceived): R; - } +declare module 'expect' { + interface Matchers { + toPrettyPrintTo(expected: unknown, options?: OptionsReceived): R; } } diff --git a/packages/pretty-format/src/__tests__/tsconfig.json b/packages/pretty-format/src/__tests__/tsconfig.json new file mode 100644 index 000000000000..8ccc3083ffb0 --- /dev/null +++ b/packages/pretty-format/src/__tests__/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "rootDir": "../" + }, + "include": ["../**/*"] +} diff --git a/packages/test-globals/README.md b/packages/test-globals/README.md new file mode 100644 index 000000000000..4de287a67c19 --- /dev/null +++ b/packages/test-globals/README.md @@ -0,0 +1,3 @@ +# test-globals + +Private package which provides type declarations of Jest's global test APIs for tests of Jest repo. diff --git a/packages/test-globals/package.json b/packages/test-globals/package.json new file mode 100644 index 000000000000..55955f9434ca --- /dev/null +++ b/packages/test-globals/package.json @@ -0,0 +1,23 @@ +{ + "name": "@jest/test-globals", + "version": "29.1.0", + "private": true, + "main": "./build/index.js", + "types": "./build/index.d.ts", + "exports": { + ".": { + "types": "./build/index.d.ts", + "default": "./build/index.js" + }, + "./package.json": "./package.json" + }, + "dependencies": { + "@jest/environment": "workspace:^", + "@jest/expect": "workspace:^", + "@jest/types": "workspace:^", + "jest-mock": "workspace:^" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } +} diff --git a/packages/test-globals/src/index.ts b/packages/test-globals/src/index.ts new file mode 100644 index 000000000000..94eedd3e3520 --- /dev/null +++ b/packages/test-globals/src/index.ts @@ -0,0 +1,67 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import type {Jest} from '@jest/environment'; +import type {JestExpect} from '@jest/expect'; +import type {Global} from '@jest/types'; +import type { + ClassLike, + FunctionLike, + Mock as JestMock, + Mocked as JestMocked, + MockedClass as JestMockedClass, + MockedFunction as JestMockedFunction, + MockedObject as JestMockedObject, + UnknownFunction, +} from 'jest-mock'; + +declare global { + const beforeAll: Global.TestFrameworkGlobals['beforeAll']; + const beforeEach: Global.TestFrameworkGlobals['beforeEach']; + + const afterEach: Global.TestFrameworkGlobals['afterEach']; + const afterAll: Global.TestFrameworkGlobals['afterAll']; + + const describe: Global.TestFrameworkGlobals['describe']; + const fdescribe: Global.TestFrameworkGlobals['fdescribe']; + const xdescribe: Global.TestFrameworkGlobals['xdescribe']; + + const it: Global.TestFrameworkGlobals['it']; + const fit: Global.TestFrameworkGlobals['fit']; + const xit: Global.TestFrameworkGlobals['xit']; + + const test: Global.TestFrameworkGlobals['test']; + const xtest: Global.TestFrameworkGlobals['xtest']; + + const expect: JestExpect; + + const jest: Jest; + + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace jest { + /** + * Constructs the type of a mock function, e.g. the return type of `jest.fn()`. + */ + export type Mock = JestMock; + /** + * Wraps a class, function or object type with Jest mock type definitions. + */ + export type Mocked = JestMocked; + /** + * Wraps a class type with Jest mock type definitions. + */ + export type MockedClass = JestMockedClass; + /** + * Wraps a function type with Jest mock type definitions. + */ + export type MockedFunction = JestMockedFunction; + /** + * Wraps an object type with Jest mock type definitions. + */ + export type MockedObject = JestMockedObject; + } +} diff --git a/packages/test-globals/tsconfig.json b/packages/test-globals/tsconfig.json new file mode 100644 index 000000000000..5f17ca7fc22c --- /dev/null +++ b/packages/test-globals/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "include": ["./src/**/*"], + "references": [ + {"path": "../jest-environment"}, + {"path": "../jest-expect"}, + {"path": "../jest-mock"}, + {"path": "../jest-types"} + ] +} diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json index 081c80a123be..110097eb7fef 100644 --- a/packages/test-utils/tsconfig.json +++ b/packages/test-utils/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "rootDir": "src", - "outDir": "build", - // we don't want `@types/jest` to be referenced - "types": ["node"] + "outDir": "build" }, "include": ["./src/**/*"], "references": [{"path": "../jest-types"}, {"path": "../pretty-format"}] diff --git a/scripts/bundleTs.mjs b/scripts/bundleTs.mjs index f4a7805cd467..75b7f1e3f683 100644 --- a/scripts/bundleTs.mjs +++ b/scripts/bundleTs.mjs @@ -38,7 +38,7 @@ const copyrightSnippet = ` const typesNodeReferenceDirective = '/// '; -const excludedPackages = new Set(['@jest/globals']); +const excludedPackages = new Set(['@jest/globals', '@jest/test-globals']); (async () => { const packages = getPackages(); diff --git a/tsconfig.test.json b/tsconfig.test.json new file mode 100644 index 000000000000..69a0977f451e --- /dev/null +++ b/tsconfig.test.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "composite": false, + "emitDeclarationOnly": false, + "noEmit": true, + "types": ["@jest/test-globals"] + } +} diff --git a/yarn.lock b/yarn.lock index a8b28875b679..ed6b150b11a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2759,7 +2759,6 @@ __metadata: "@types/babel__generator": ^7.0.0 "@types/babel__template": ^7.0.2 "@types/dedent": ^0.7.0 - "@types/jest": ^27.4.0 "@types/node": ~14.14.45 "@types/which": ^2.0.0 "@typescript-eslint/eslint-plugin": ^5.14.0 @@ -2905,6 +2904,17 @@ __metadata: languageName: unknown linkType: soft +"@jest/test-globals@workspace:packages/test-globals": + version: 0.0.0-use.local + resolution: "@jest/test-globals@workspace:packages/test-globals" + dependencies: + "@jest/environment": "workspace:^" + "@jest/expect": "workspace:^" + "@jest/types": "workspace:^" + jest-mock: "workspace:^" + languageName: unknown + linkType: soft + "@jest/test-result@npm:^28.1.3": version: 28.1.3 resolution: "@jest/test-result@npm:28.1.3" @@ -4612,16 +4622,6 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^27.4.0": - version: 27.5.2 - resolution: "@types/jest@npm:27.5.2" - dependencies: - jest-matcher-utils: ^27.0.0 - pretty-format: ^27.0.0 - checksum: 7e11c6826aa429ad990dc262e4e4b54aa36573287fddf15773e4137f07d11d3105f0dd9f1baff73252160a057df23f5529bb83b1bf83cd3f45f9460a5ca5c22e - languageName: node - linkType: hard - "@types/jsdom@npm:^20.0.0": version: 20.0.0 resolution: "@types/jsdom@npm:20.0.0" @@ -5661,6 +5661,7 @@ __metadata: "@babel/plugin-proposal-decorators": "*" "@babel/preset-env": ^7.1.0 "@babel/preset-typescript": ^7.0.0 + "@jest/globals": "workspace:^" babel-jest: "workspace:^" babel-plugin-transform-typescript-metadata: "*" core-js: ^3.2.1 @@ -8346,13 +8347,6 @@ __metadata: languageName: node linkType: hard -"diff-sequences@npm:^27.5.1": - version: 27.5.1 - resolution: "diff-sequences@npm:27.5.1" - checksum: a00db5554c9da7da225db2d2638d85f8e41124eccbd56cbaefb3b276dcbb1c1c2ad851c32defe2055a54a4806f030656cbf6638105fd6ce97bb87b90b32a33ca - languageName: node - linkType: hard - "diff-sequences@workspace:^, diff-sequences@workspace:packages/diff-sequences": version: 0.0.0-use.local resolution: "diff-sequences@workspace:packages/diff-sequences" @@ -9562,7 +9556,7 @@ __metadata: "@babel/preset-env": ^7.1.0 "@babel/preset-react": ^7.12.1 "@babel/preset-typescript": ^7.0.0 - "@types/jest": ^27.4.0 + "@jest/globals": "workspace:^" babel-jest: "workspace:^" jest: "workspace:^" react: 17.0.2 @@ -12377,18 +12371,6 @@ __metadata: languageName: unknown linkType: soft -"jest-diff@npm:^27.5.1": - version: 27.5.1 - resolution: "jest-diff@npm:27.5.1" - dependencies: - chalk: ^4.0.0 - diff-sequences: ^27.5.1 - jest-get-type: ^27.5.1 - pretty-format: ^27.5.1 - checksum: 8be27c1e1ee57b2bb2bef9c0b233c19621b4c43d53a3c26e2c00a4e805eb4ea11fe1694a06a9fb0e80ffdcfdc0d2b1cb0b85920b3f5c892327ecd1e7bd96b865 - languageName: node - linkType: hard - "jest-diff@workspace:^, jest-diff@workspace:packages/jest-diff": version: 0.0.0-use.local resolution: "jest-diff@workspace:packages/jest-diff" @@ -12460,13 +12442,6 @@ __metadata: languageName: node linkType: hard -"jest-get-type@npm:^27.5.1": - version: 27.5.1 - resolution: "jest-get-type@npm:27.5.1" - checksum: 63064ab70195c21007d897c1157bf88ff94a790824a10f8c890392e7d17eda9c3900513cb291ca1c8d5722cad79169764e9a1279f7c8a9c4cd6e9109ff04bbc0 - languageName: node - linkType: hard - "jest-get-type@workspace:^, jest-get-type@workspace:packages/jest-get-type": version: 0.0.0-use.local resolution: "jest-get-type@workspace:packages/jest-get-type" @@ -12545,18 +12520,6 @@ __metadata: languageName: unknown linkType: soft -"jest-matcher-utils@npm:^27.0.0": - version: 27.5.1 - resolution: "jest-matcher-utils@npm:27.5.1" - dependencies: - chalk: ^4.0.0 - jest-diff: ^27.5.1 - jest-get-type: ^27.5.1 - pretty-format: ^27.5.1 - checksum: bb2135fc48889ff3fe73888f6cc7168ddab9de28b51b3148f820c89fdfd2effdcad005f18be67d0b9be80eda208ad47290f62f03d0a33f848db2dd0273c8217a - languageName: node - linkType: hard - "jest-matcher-utils@workspace:^, jest-matcher-utils@workspace:packages/jest-matcher-utils": version: 0.0.0-use.local resolution: "jest-matcher-utils@workspace:packages/jest-matcher-utils" @@ -16885,7 +16848,7 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^27.0.0, pretty-format@npm:^27.0.2, pretty-format@npm:^27.5.1": +"pretty-format@npm:^27.0.2": version: 27.5.1 resolution: "pretty-format@npm:27.5.1" dependencies: