diff --git a/.circleci/config.yml b/.circleci/config.yml index b28f93ee3a3c..34b8da8592e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,5 +54,5 @@ workflows: name: test-node-partial-<< matrix.node-version >> matrix: parameters: - node-version: ['12', '14', '16', '17', '18'] + node-version: ['14', '16', '18'] - test-jest-jasmine diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0133043a6624..d7060b18db3a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [12.x, 14.x, 16.x, 17.x, 18.x] + node-version: [14.x, 16.x, 18.x] shard: ['1/4', '2/4', '3/4', '4/4'] name: Node v${{ matrix.node-version }} on ${{ inputs.os }} (${{ matrix.shard }}) runs-on: ${{ inputs.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index cac05ca24b0d..683a94544110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Chore & Maintenance +- `[*]` [**BREAKING**] Drop support for Node v12 and v17 ([#13033](https://github.com/facebook/jest/pull/13033)) + ### Performance ## 28.1.3 diff --git a/constraints.pro b/constraints.pro index 82805f8b481f..a3ce99af0e0e 100644 --- a/constraints.pro +++ b/constraints.pro @@ -27,7 +27,7 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, Depende 'react', 'react-dom', % Only RN should be bumped to react 18 'react-test-renderer', - % @types/node in the root need to stay on ~12.12.0 + % @types/node in the root need to stay on ~14.14.45 '@types/node', % upgrading the entire repository is a breaking change 'glob' @@ -61,7 +61,7 @@ gen_enforced_field(WorkspaceCwd, 'publishConfig.access', null) :- workspace_field(WorkspaceCwd, 'private', true). % Enforces the engines.node field for public workspace -gen_enforced_field(WorkspaceCwd, 'engines.node', '^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0') :- +gen_enforced_field(WorkspaceCwd, 'engines.node', '^14.15.0 || ^16.10.0 || >=18.0.0') :- \+ workspace_field(WorkspaceCwd, 'private', true). % Enforces the main and types field to start with ./ diff --git a/docs/UpgradingToJest28.md b/docs/UpgradingToJest28.md deleted file mode 100644 index 6f858e0fd9ac..000000000000 --- a/docs/UpgradingToJest28.md +++ /dev/null @@ -1,222 +0,0 @@ ---- -id: upgrading-to-jest28 -title: From v27 to v28 ---- - -Upgrading Jest from v27 to v28? This guide aims to help refactoring your configuration and tests. - -:::info - -See [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md#2800) for the full list of changes. - -::: - -## Compatibility - -The supported Node versions are 12.13, 14.15, 16.10 and above. - -If you plan to use type definitions of Jest (or any of its packages), make sure to install TypeScript version 4.3 or above. - -## Configuration Options - -### `extraGlobals` - -The `extraGlobals` option was renamed to [`sandboxInjectedGlobals`](Configuration.md#sandboxinjectedglobals-arraystring): - -```diff -- extraGlobals: ['Math'] -+ sandboxInjectedGlobals: ['Math'] -``` - -### `timers` - -The `timers` option was renamed to [`fakeTimers`](Configuration.md#faketimers-object). See [Fake Timers](#fake-timers) section below for details. - -### `testURL` - -The `testURL` option is removed. Now you should use [`testEnvironmentOptions`](Configuration.md#testenvironmentoptions-object) to pass `url` option to JSDOM environment: - -```diff -- testURL: 'https://jestjs.io' -+ testEnvironmentOptions: { -+ url: 'https://jestjs.io' -+ } -``` - -### Babel config - -`babel-jest` now passes `root: config.rootDir` to Babel when resolving configuration. This improves compatibility when using `projects` with differing configuration, but it might mean your babel config isn't picked up in the same way anymore. You can override this option by passing options to `babel-jest` in your [configuration](Configuration.md#transform-objectstring-pathtotransformer--pathtotransformer-object). - -## `expect` - -In versions prior to Jest 28, `toHaveProperty` checked for equality instead of existence, which means that e.g. `expect({}).toHaveProperty('a', undefined)` is a passing test. This has been changed in Jest 28 to fail. - -Additionally, if you import `expect` directly, it has been changed from default export to a named export. - -```diff -- import expect from 'expect'; -+ import {expect} from 'expect'; -``` - -```diff -- const expect = require('expect'); -+ const {expect} = require('expect'); -``` - -## Fake Timers - -Fake timers were refactored to allow passing options to the underlying [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers). - -### `fakeTimers` - -The `timers` configuration option was renamed to [`fakeTimers`](Configuration.md#faketimers-object) and now takes an object with options: - -```diff -- timers: 'real' -+ fakeTimers: { -+ enableGlobally: false -+ } -``` - -```diff -- timers: 'fake' -+ fakeTimers: { -+ enableGlobally: true -+ } -``` - -```diff -- timers: 'modern' -+ fakeTimers: { -+ enableGlobally: true -+ } -``` - -```diff -- timers: 'legacy' -+ fakeTimers: { -+ enableGlobally: true, -+ legacyFakeTimers: true -+ } -``` - -### `jest.useFakeTimers()` - -An object with options now should be passed to [`jest.useFakeTimers()`](JestObjectAPI.md#jestusefaketimersfaketimersconfig) as well: - -```diff -- jest.useFakeTimers('modern') -+ jest.useFakeTimers() -``` - -```diff -- jest.useFakeTimers('legacy') -+ jest.useFakeTimers({ -+ legacyFakeTimers: true -+ }) -``` - -If legacy fake timers are enabled in Jest config file, but you would like to disable them in a particular test file: - -```diff -- jest.useFakeTimers('modern') -+ jest.useFakeTimers({ -+ legacyFakeTimers: false -+ }) -``` - -## Test Environment - -### Custom Environment - -The constructor of [test environment](Configuration.md#testenvironment-string) class now receives an object with Jest's `globalConfig` and `projectConfig` as its first argument. The second argument is now mandatory. - -```diff - class CustomEnvironment extends NodeEnvironment { -- constructor(config) { -- super(config); -+ constructor({globalConfig, projectConfig}, context) { -+ super({globalConfig, projectConfig}, context); -+ const config = projectConfig; -``` - -In addition, test environments are now exported with the name `TestEnvironment`, instead of simply exporting the class directly: - -```diff -- const TestEnvironment = require('jest-environment-node'); -+ const {TestEnvironment} = require('jest-environment-node'); - -- const TestEnvironment = require('jest-environment-jsdom'); -+ const {TestEnvironment} = require('jest-environment-jsdom'); -``` - -### `jsdom` - -If you are using JSDOM [test environment](Configuration.md#testenvironment-string), `jest-environment-jsdom` package now must be installed separately: - -```bash npm2yarn -npm install --save-dev jest-environment-jsdom -``` - -## Test Runner - -If you are using Jasmine [test runner](Configuration.md#testrunner-string), `jest-jasmine2` package now must be installed separately: - -```bash npm2yarn -npm install --save-dev jest-jasmine2 -``` - -## Transformer - -`process()` and `processAsync()` methods of a custom [transformer module](CodeTransformation.md) cannot return a string anymore. They must always return an object: - -```diff - process(sourceText, sourcePath, options) { -- return `module.exports = ${JSON.stringify(path.basename(sourcePath))};`; -+ return { -+ code: `module.exports = ${JSON.stringify(path.basename(sourcePath))};`, -+ }; - } -``` - -## `package.json` `exports` - -Jest now includes full support for [package `exports`](https://nodejs.org/api/packages.html#exports), which might mean that files you import are not resolved correctly. - -Additionally, Jest now supplies more conditions. `jest-environment-node` has `node` and `node-addons`, while `jest-environment-jsdom` has `browser`. As a result, you might e.g. get browser code which assumes ESM, when Jest provides `['require', 'browser']`. You can either report a bug to the library (or Jest, the implementation is new and might have bugs!), override the conditions Jest passes (by passing the `customExportConditions` option to the test environment), or use a custom resolver or `moduleMapper`. Lots of options, and you'll need to pick the correct one for your project. - -Known examples of packages that fails in Jest 28 are [`uuid`](https://npmjs.com/package/uuid) and [`nanoid`](https://npmjs.com/package/nanoid) when using the `jest-environment-jsdom` environment. For an analysis, and a potential workaround, see [this comment](https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149). - -## TypeScript - -:::info - -The TypeScript examples from this page will only work as documented if you import `jest` from `'@jest/globals'`: - -```ts -import {jest} from '@jest/globals'; -``` - -::: - -### `jest.fn()` - -`jest.fn()` now takes only one generic type argument. See [Mock Functions API](MockFunctionAPI.md) page for more usage examples. - -```diff - import add from './add'; -- const mockAdd = jest.fn, Parameters>(); -+ const mockAdd = jest.fn(); -``` - -```diff -- const mock = jest.fn() -+ const mock = jest.fn<() => number>() - .mockReturnValue(42) - .mockReturnValueOnce(12); - -- const asyncMock = jest.fn, []>() -+ const asyncMock = jest.fn<() => Promise>() - .mockResolvedValue('default') - .mockResolvedValueOnce('first call'); -``` diff --git a/docs/UpgradingToJest29.md b/docs/UpgradingToJest29.md new file mode 100644 index 000000000000..e589f35880e4 --- /dev/null +++ b/docs/UpgradingToJest29.md @@ -0,0 +1,16 @@ +--- +id: upgrading-to-jest29 +title: From v28 to v29 +--- + +Upgrading Jest from v28 to v29? This guide aims to help refactoring your configuration and tests. + +:::info + +See [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md#2900) for the full list of changes. + +::: + +## Compatibility + +The supported Node versions are 14.15, 16.10, 18.0 and above. diff --git a/e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap b/e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap index 01767d172899..f24e97dce582 100644 --- a/e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap +++ b/e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap @@ -1,64 +1,64 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`on node >=12.16.0 prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test 1`] = ` +exports[`prints correct coverage report, if a CJS module is put under test without transformation 1`] = ` " console.log this will print - at covered (module.ts:13:11) + at covered (module.js:11:11) --------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- -All files | 50 | 25 | 25 | 50 | - module.ts | 80.76 | 50 | 50 | 80.76 | 16-18,21-22 - types.ts | 0 | 0 | 0 | 0 | 1-8 - uncovered.ts | 0 | 0 | 0 | 0 | 1-8 +All files | 59.37 | 60 | 50 | 59.37 | + module.js | 79.16 | 75 | 66.66 | 79.16 | 14-16,19-20 + uncovered.js | 0 | 0 | 0 | 0 | 1-8 --------------|---------|----------|---------|---------|-------------------" `; -exports[`on node >=12.16.0 prints correct coverage report, if an ESM module is put under test without transformation 1`] = ` +exports[`prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test 1`] = ` " console.log this will print - at covered (module.js:11:11) + at log (module.ts:13:11) --------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- -All files | 59.37 | 50 | 33.33 | 59.37 | - module.js | 79.16 | 66.66 | 50 | 79.16 | 14-16,19-20 - uncovered.js | 0 | 0 | 0 | 0 | 1-8 +All files | 50 | 25 | 25 | 50 | + module.ts | 80.76 | 50 | 50 | 80.76 | 16-18,21-22 + types.ts | 0 | 0 | 0 | 0 | 1-8 + uncovered.ts | 0 | 0 | 0 | 0 | 1-8 --------------|---------|----------|---------|---------|-------------------" `; -exports[`prints correct coverage report, if a CJS module is put under test without transformation 1`] = ` +exports[`prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test 1`] = ` " console.log this will print - at covered (module.js:11:11) + at covered (module.ts:13:11) --------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- -All files | 59.37 | 60 | 50 | 59.37 | - module.js | 79.16 | 75 | 66.66 | 79.16 | 14-16,19-20 - uncovered.js | 0 | 0 | 0 | 0 | 1-8 +All files | 50 | 25 | 25 | 50 | + module.ts | 80.76 | 50 | 50 | 80.76 | 16-18,21-22 + types.ts | 0 | 0 | 0 | 0 | 1-8 + uncovered.ts | 0 | 0 | 0 | 0 | 1-8 --------------|---------|----------|---------|---------|-------------------" `; -exports[`prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test 1`] = ` +exports[`prints correct coverage report, if an ESM module is put under test without transformation 1`] = ` " console.log this will print - at log (module.ts:13:11) + at covered (module.js:11:11) --------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s --------------|---------|----------|---------|---------|------------------- -All files | 50 | 25 | 25 | 50 | - module.ts | 80.76 | 50 | 50 | 80.76 | 16-18,21-22 - types.ts | 0 | 0 | 0 | 0 | 1-8 - uncovered.ts | 0 | 0 | 0 | 0 | 1-8 +All files | 59.37 | 50 | 33.33 | 59.37 | + module.js | 79.16 | 66.66 | 50 | 79.16 | 14-16,19-20 + uncovered.js | 0 | 0 | 0 | 0 | 1-8 --------------|---------|----------|---------|---------|-------------------" `; diff --git a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap index f9808e71e029..62553cf7f7aa 100644 --- a/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap +++ b/e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap @@ -41,7 +41,7 @@ exports[`moduleNameMapper wrong array configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:900:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:896:17) at Object.require (index.js:10:1)" `; @@ -70,6 +70,6 @@ exports[`moduleNameMapper wrong configuration 1`] = ` 12 | module.exports = () => 'test'; 13 | - at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:900:17) + at createNoMappedModuleFoundError (../../packages/jest-resolve/build/resolver.js:896:17) at Object.require (index.js:10:1)" `; diff --git a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap index aac14c4f8678..d4cc559e7386 100644 --- a/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap +++ b/e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`on node >=12.16.0 runs test with native ESM 1`] = ` +exports[`runs test with native ESM 1`] = ` "Test Suites: 1 passed, 1 total Tests: 33 passed, 33 total Snapshots: 0 total @@ -8,7 +8,7 @@ Time: <> Ran all test suites matching /native-esm.test.js/i." `; -exports[`on node >=14.3.0 supports top-level await 1`] = ` +exports[`supports top-level await 1`] = ` "Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total diff --git a/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap b/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap index 8b2c6acb57fd..edfad21176f6 100644 --- a/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap +++ b/e2e/__tests__/__snapshots__/resolveAsync.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`on node >=12.16.0 runs test with native ESM 1`] = ` +exports[`runs test with native ESM 1`] = ` "Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total diff --git a/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap b/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap index 8ee95a4ed134..62ed2a7e4489 100644 --- a/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap +++ b/e2e/__tests__/__snapshots__/resolveNoFileExtensions.test.ts.snap @@ -37,6 +37,6 @@ exports[`show error message with matching files 1`] = ` | ^ 9 | - at Resolver._throwModNotFoundError (../../packages/jest-resolve/build/resolver.js:491:11) + at Resolver._throwModNotFoundError (../../packages/jest-resolve/build/resolver.js:487:11) at Object.require (index.js:8:18)" `; diff --git a/e2e/__tests__/coverageProviderV8.test.ts b/e2e/__tests__/coverageProviderV8.test.ts index a11ac7676cf5..260ae254a31b 100644 --- a/e2e/__tests__/coverageProviderV8.test.ts +++ b/e2e/__tests__/coverageProviderV8.test.ts @@ -6,7 +6,6 @@ */ import * as path from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../coverage-provider-v8'); @@ -76,37 +75,34 @@ test('prints correct coverage report, if a TS module is transpiled by Babel to C expect(stdout).toMatchSnapshot(); }); -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - test('prints correct coverage report, if an ESM module is put under test without transformation', () => { - const sourcemapDir = path.join(DIR, 'esm-native-without-sourcemap'); - - const {stdout, exitCode} = runJest( - sourcemapDir, - ['--coverage', '--coverage-provider', 'v8', '--no-cache'], - { - nodeOptions: '--experimental-vm-modules --no-warnings', - stripAnsi: true, - }, - ); - - expect(exitCode).toBe(0); - expect(stdout).toMatchSnapshot(); - }); - - test('prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test', () => { - const sourcemapDir = path.join(DIR, 'esm-with-custom-transformer'); - - const {stdout, exitCode} = runJest( - sourcemapDir, - ['--coverage', '--coverage-provider', 'v8', '--no-cache'], - { - nodeOptions: '--experimental-vm-modules --no-warnings', - stripAnsi: true, - }, - ); - - expect(exitCode).toBe(0); - expect(stdout).toMatchSnapshot(); - }); +test('prints correct coverage report, if an ESM module is put under test without transformation', () => { + const sourcemapDir = path.join(DIR, 'esm-native-without-sourcemap'); + + const {stdout, exitCode} = runJest( + sourcemapDir, + ['--coverage', '--coverage-provider', 'v8', '--no-cache'], + { + nodeOptions: '--experimental-vm-modules --no-warnings', + stripAnsi: true, + }, + ); + + expect(exitCode).toBe(0); + expect(stdout).toMatchSnapshot(); +}); + +test('prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test', () => { + const sourcemapDir = path.join(DIR, 'esm-with-custom-transformer'); + + const {stdout, exitCode} = runJest( + sourcemapDir, + ['--coverage', '--coverage-provider', 'v8', '--no-cache'], + { + nodeOptions: '--experimental-vm-modules --no-warnings', + stripAnsi: true, + }, + ); + + expect(exitCode).toBe(0); + expect(stdout).toMatchSnapshot(); }); diff --git a/e2e/__tests__/customEsmTestSequencers.test.ts b/e2e/__tests__/customEsmTestSequencers.test.ts index 706df262b620..134dd26e19f1 100644 --- a/e2e/__tests__/customEsmTestSequencers.test.ts +++ b/e2e/__tests__/customEsmTestSequencers.test.ts @@ -6,27 +6,24 @@ */ import * as path from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import {extractSummary} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '../custom-esm-test-sequencer'); -onNodeVersions('>=12.16.0', () => { - test('run prioritySequence', () => { - const result = runJest(dir, ['-i'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - - expect(result.exitCode).toBe(0); - const sequence = extractSummary(result.stderr) - .rest.replace(/PASS /g, '') - .split('\n'); - expect(sequence).toEqual([ - './a.test.js', - './b.test.js', - './c.test.js', - './d.test.js', - './e.test.js', - ]); +test('run prioritySequence', () => { + const result = runJest(dir, ['-i'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + + expect(result.exitCode).toBe(0); + const sequence = extractSummary(result.stderr) + .rest.replace(/PASS /g, '') + .split('\n'); + expect(sequence).toEqual([ + './a.test.js', + './b.test.js', + './c.test.js', + './d.test.js', + './e.test.js', + ]); }); diff --git a/e2e/__tests__/customReporters.test.ts b/e2e/__tests__/customReporters.test.ts index 90aca200027b..f76647fd5758 100644 --- a/e2e/__tests__/customReporters.test.ts +++ b/e2e/__tests__/customReporters.test.ts @@ -7,7 +7,6 @@ import {tmpdir} from 'os'; import * as path from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import {cleanup, extractSummary, writeFiles} from '../Utils'; import runJest from '../runJest'; @@ -159,27 +158,25 @@ describe('Custom Reporters Integration', () => { expect(exitCode).toBe(1); }); - onNodeVersions('>=12.17.0', () => { - test('supports reporter written in ESM', () => { - writeFiles(DIR, { - '__tests__/test.test.js': "test('test', () => {});", - 'package.json': JSON.stringify({ - jest: { - reporters: ['default', '/reporter.mjs'], - }, - }), - 'reporter.mjs': ` + test('supports reporter written in ESM', () => { + writeFiles(DIR, { + '__tests__/test.test.js': "test('test', () => {});", + 'package.json': JSON.stringify({ + jest: { + reporters: ['default', '/reporter.mjs'], + }, + }), + 'reporter.mjs': ` export default class Reporter { onRunStart() { throw new Error('ON_RUN_START_ERROR'); } }; `, - }); - - const {stderr, exitCode} = runJest(DIR); - expect(stderr).toMatch(/ON_RUN_START_ERROR/); - expect(exitCode).toBe(1); }); + + const {stderr, exitCode} = runJest(DIR); + expect(stderr).toMatch(/ON_RUN_START_ERROR/); + expect(exitCode).toBe(1); }); }); diff --git a/e2e/__tests__/esmConfigFile.test.ts b/e2e/__tests__/esmConfigFile.test.ts index 690d7e509f19..6f9ead12672e 100644 --- a/e2e/__tests__/esmConfigFile.test.ts +++ b/e2e/__tests__/esmConfigFile.test.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import {onNodeVersions} from '@jest/test-utils'; import {getConfig} from '../runJest'; test('reads config from cjs file', () => { @@ -20,40 +19,38 @@ test('reads config from cjs file', () => { }); }); -onNodeVersions('>=12.17.0', () => { - test('reads config from mjs file', () => { - const {configs} = getConfig('esm-config/mjs', [], { - skipPkgJsonCheck: true, - }); - - expect(configs).toHaveLength(1); - expect(configs[0].displayName).toEqual({ - color: 'white', - name: 'Config from mjs file', - }); - }); - - test('reads config from js file when package.json#type=module', () => { - const {configs} = getConfig('esm-config/js', [], { - skipPkgJsonCheck: true, - }); - - expect(configs).toHaveLength(1); - expect(configs[0].displayName).toEqual({ - color: 'white', - name: 'Config from js file', - }); - }); - - test('reads config from ts file when package.json#type=module', () => { - const {configs} = getConfig('esm-config/ts', [], { - skipPkgJsonCheck: true, - }); - - expect(configs).toHaveLength(1); - expect(configs[0].displayName).toEqual({ - color: 'white', - name: 'Config from ts file', - }); +test('reads config from mjs file', () => { + const {configs} = getConfig('esm-config/mjs', [], { + skipPkgJsonCheck: true, + }); + + expect(configs).toHaveLength(1); + expect(configs[0].displayName).toEqual({ + color: 'white', + name: 'Config from mjs file', + }); +}); + +test('reads config from js file when package.json#type=module', () => { + const {configs} = getConfig('esm-config/js', [], { + skipPkgJsonCheck: true, + }); + + expect(configs).toHaveLength(1); + expect(configs[0].displayName).toEqual({ + color: 'white', + name: 'Config from js file', + }); +}); + +test('reads config from ts file when package.json#type=module', () => { + const {configs} = getConfig('esm-config/ts', [], { + skipPkgJsonCheck: true, + }); + + expect(configs).toHaveLength(1); + expect(configs[0].displayName).toEqual({ + color: 'white', + name: 'Config from ts file', }); }); diff --git a/e2e/__tests__/globalSetup.test.ts b/e2e/__tests__/globalSetup.test.ts index 05dee3a4cdfa..bd87d29806c4 100644 --- a/e2e/__tests__/globalSetup.test.ts +++ b/e2e/__tests__/globalSetup.test.ts @@ -8,7 +8,6 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; -import {onNodeVersions} from '@jest/test-utils'; import { cleanup, createEmptyPackage, @@ -199,12 +198,10 @@ test('properly handle rejections', () => { expect(stderr).toContain('reason: undefined'); }); -onNodeVersions('>=12.17.0', () => { - test('globalSetup works with ESM modules', () => { - const {exitCode} = runJest('global-setup-esm', ['--no-cache'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - - expect(exitCode).toBe(0); +test('globalSetup works with ESM modules', () => { + const {exitCode} = runJest('global-setup-esm', ['--no-cache'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + + expect(exitCode).toBe(0); }); diff --git a/e2e/__tests__/globalTeardown.test.ts b/e2e/__tests__/globalTeardown.test.ts index 5f43bc4ecf84..811ddcf3749a 100644 --- a/e2e/__tests__/globalTeardown.test.ts +++ b/e2e/__tests__/globalTeardown.test.ts @@ -8,7 +8,6 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; -import {onNodeVersions} from '@jest/test-utils'; import {createDirectory} from 'jest-util'; import {cleanup, runYarnInstall} from '../Utils'; import runJest, {json as runWithJson} from '../runJest'; @@ -138,12 +137,10 @@ test('globalTeardown throws with named export', () => { ); }); -onNodeVersions('>=12.17.0', () => { - test('globalTeardown works with ESM modules', () => { - const {exitCode} = runJest('global-teardown-esm', ['--no-cache'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - - expect(exitCode).toBe(0); +test('globalTeardown works with ESM modules', () => { + const {exitCode} = runJest('global-teardown-esm', ['--no-cache'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + + expect(exitCode).toBe(0); }); diff --git a/e2e/__tests__/nativeEsm.test.ts b/e2e/__tests__/nativeEsm.test.ts index f1e9eed31f07..a0a22af661e8 100644 --- a/e2e/__tests__/nativeEsm.test.ts +++ b/e2e/__tests__/nativeEsm.test.ts @@ -6,7 +6,6 @@ */ import {resolve} from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import {extractSummary} from '../Utils'; import runJest, {getConfig} from '../runJest'; @@ -19,34 +18,26 @@ test('test config is without transform', () => { expect(configs[0].transform).toEqual([]); }); -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - test('runs test with native ESM', () => { - const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.test.js'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); +test('runs test with native ESM', () => { + const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.test.js'], { + nodeOptions: '--experimental-vm-modules --no-warnings', + }); - const {summary} = extractSummary(stderr); + const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); - expect(stdout).toBe(''); - expect(exitCode).toBe(0); - }); + expect(summary).toMatchSnapshot(); + expect(stdout).toBe(''); + expect(exitCode).toBe(0); }); -// The versions where TLA is supported -onNodeVersions('>=14.3.0', () => { - test('supports top-level await', () => { - const {exitCode, stderr, stdout} = runJest( - DIR, - ['native-esm.tla.test.js'], - {nodeOptions: '--experimental-vm-modules --no-warnings'}, - ); +test('supports top-level await', () => { + const {exitCode, stderr, stdout} = runJest(DIR, ['native-esm.tla.test.js'], { + nodeOptions: '--experimental-vm-modules --no-warnings', + }); - const {summary} = extractSummary(stderr); + const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); - expect(stdout).toBe(''); - expect(exitCode).toBe(0); - }); + expect(summary).toMatchSnapshot(); + expect(stdout).toBe(''); + expect(exitCode).toBe(0); }); diff --git a/e2e/__tests__/nativeEsmTypescript.test.ts b/e2e/__tests__/nativeEsmTypescript.test.ts index ad1d817f8a16..199c1705e27c 100644 --- a/e2e/__tests__/nativeEsmTypescript.test.ts +++ b/e2e/__tests__/nativeEsmTypescript.test.ts @@ -6,21 +6,17 @@ */ import {resolve} from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import {json as runJest} from '../runJest'; const DIR = resolve(__dirname, '../native-esm-typescript'); -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - test('runs TS test with native ESM', () => { - const {exitCode, json} = runJest(DIR, [], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); +test('runs TS test with native ESM', () => { + const {exitCode, json} = runJest(DIR, [], { + nodeOptions: '--experimental-vm-modules --no-warnings', + }); - expect(exitCode).toBe(0); + expect(exitCode).toBe(0); - expect(json.numTotalTests).toBe(2); - expect(json.numPassedTests).toBe(2); - }); + expect(json.numTotalTests).toBe(2); + expect(json.numPassedTests).toBe(2); }); diff --git a/e2e/__tests__/presets.test.ts b/e2e/__tests__/presets.test.ts index ec820f298b03..cedd77880e86 100644 --- a/e2e/__tests__/presets.test.ts +++ b/e2e/__tests__/presets.test.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import {onNodeVersions} from '@jest/test-utils'; import runJest from '../runJest'; test('supports json preset', () => { @@ -19,10 +18,8 @@ test.each(['js', 'cjs'])('supports %s preset', presetDir => { expect(result.exitCode).toBe(0); }); -onNodeVersions('>=12.17.0', () => { - test.each(['mjs', 'js-type-module'])('supports %s preset', presetDir => { - const result = runJest(`presets/${presetDir}`); +test.each(['mjs', 'js-type-module'])('supports %s preset', presetDir => { + const result = runJest(`presets/${presetDir}`); - expect(result.exitCode).toBe(0); - }); + expect(result.exitCode).toBe(0); }); diff --git a/e2e/__tests__/resolveAsync.test.ts b/e2e/__tests__/resolveAsync.test.ts index a5588985f235..ab4f09775708 100644 --- a/e2e/__tests__/resolveAsync.test.ts +++ b/e2e/__tests__/resolveAsync.test.ts @@ -5,21 +5,17 @@ * LICENSE file in the root directory of this source tree. */ -import {onNodeVersions} from '@jest/test-utils'; import {extractSummary} from '../Utils'; import runJest from '../runJest'; -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - test('runs test with native ESM', () => { - const {exitCode, stderr, stdout} = runJest('resolve-async', [], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); +test('runs test with native ESM', () => { + const {exitCode, stderr, stdout} = runJest('resolve-async', [], { + nodeOptions: '--experimental-vm-modules --no-warnings', + }); - const {summary} = extractSummary(stderr); + const {summary} = extractSummary(stderr); - expect(summary).toMatchSnapshot(); - expect(stdout).toBe(''); - expect(exitCode).toBe(0); - }); + expect(summary).toMatchSnapshot(); + expect(stdout).toBe(''); + expect(exitCode).toBe(0); }); diff --git a/e2e/__tests__/resolveConditions.test.ts b/e2e/__tests__/resolveConditions.test.ts index d1b8dd644a99..7bb47817454e 100644 --- a/e2e/__tests__/resolveConditions.test.ts +++ b/e2e/__tests__/resolveConditions.test.ts @@ -6,25 +6,21 @@ */ import {resolve} from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import runJest from '../runJest'; const dir = resolve(__dirname, '..', 'resolve-conditions'); -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - test('resolves package exports correctly with custom resolver', () => { - // run multiple times to ensure there are no caching errors - for (let i = 0; i < 5; i++) { - const {exitCode} = runJest(dir, [], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - try { - expect(exitCode).toBe(0); - } catch (error) { - console.log(`Test failed on iteration ${i + 1}`); - throw error; - } +test('resolves package exports correctly with custom resolver', () => { + // run multiple times to ensure there are no caching errors + for (let i = 0; i < 5; i++) { + const {exitCode} = runJest(dir, [], { + nodeOptions: '--experimental-vm-modules --no-warnings', + }); + try { + expect(exitCode).toBe(0); + } catch (error) { + console.log(`Test failed on iteration ${i + 1}`); + throw error; } - }); + } }); diff --git a/e2e/__tests__/testEnvironmentEsm.ts b/e2e/__tests__/testEnvironmentEsm.ts index cb41ad429934..ac8977839e98 100644 --- a/e2e/__tests__/testEnvironmentEsm.ts +++ b/e2e/__tests__/testEnvironmentEsm.ts @@ -6,15 +6,11 @@ */ import {resolve} from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import runJest from '../runJest'; -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - it('support test environment written in ESM', () => { - const DIR = resolve(__dirname, '../test-environment-esm'); - const {exitCode} = runJest(DIR); +it('support test environment written in ESM', () => { + const DIR = resolve(__dirname, '../test-environment-esm'); + const {exitCode} = runJest(DIR); - expect(exitCode).toBe(0); - }); + expect(exitCode).toBe(0); }); diff --git a/e2e/__tests__/testResultsProcessor.test.ts b/e2e/__tests__/testResultsProcessor.test.ts index c3724b6fe92e..9c62291ba28a 100644 --- a/e2e/__tests__/testResultsProcessor.test.ts +++ b/e2e/__tests__/testResultsProcessor.test.ts @@ -6,7 +6,6 @@ */ import * as path from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import {json as runWithJson} from '../runJest'; test('testResultsProcessor', () => { @@ -21,17 +20,14 @@ test('testResultsProcessor', () => { expect(json.processed).toBe(true); }); -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=12.16.0', () => { - test('testResultsProcessor written in ESM', () => { - const processorPath = path.resolve( - __dirname, - '../test-results-processor/processor.mjs', - ); - const {json} = runWithJson('test-results-processor', [ - '--json', - `--testResultsProcessor=${processorPath}`, - ]); - expect(json.processed).toBe(true); - }); +test('testResultsProcessor written in ESM', () => { + const processorPath = path.resolve( + __dirname, + '../test-results-processor/processor.mjs', + ); + const {json} = runWithJson('test-results-processor', [ + '--json', + `--testResultsProcessor=${processorPath}`, + ]); + expect(json.processed).toBe(true); }); diff --git a/e2e/__tests__/transform.test.ts b/e2e/__tests__/transform.test.ts index 6569de347b9d..b171f6dc7528 100644 --- a/e2e/__tests__/transform.test.ts +++ b/e2e/__tests__/transform.test.ts @@ -8,7 +8,6 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; -import {onNodeVersions} from '@jest/test-utils'; import { cleanup, copyDir, @@ -278,74 +277,69 @@ describe('transform-testrunner', () => { }); }); -onNodeVersions('>=12.17.0', () => { - describe('esm-transformer', () => { - const dir = path.resolve(__dirname, '../transform/esm-transformer'); +describe('esm-transformer', () => { + const dir = path.resolve(__dirname, '../transform/esm-transformer'); - it('should transform with transformer written in ESM', () => { - const {json, stderr} = runWithJson(dir, ['--no-cache']); - expect(stderr).toMatch(/PASS/); - expect(json.success).toBe(true); - expect(json.numPassedTests).toBe(1); - }); + it('should transform with transformer written in ESM', () => { + const {json, stderr} = runWithJson(dir, ['--no-cache']); + expect(stderr).toMatch(/PASS/); + expect(json.success).toBe(true); + expect(json.numPassedTests).toBe(1); }); +}); - describe('async-transformer', () => { - const dir = path.resolve(__dirname, '../transform/async-transformer'); +describe('async-transformer', () => { + const dir = path.resolve(__dirname, '../transform/async-transformer'); - it('should transform with transformer with only async transforms', () => { - const {json, stderr} = runWithJson(dir, ['--no-cache'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - expect(stderr).toMatch(/PASS/); - expect(json.success).toBe(true); - expect(json.numPassedTests).toBe(2); + it('should transform with transformer with only async transforms', () => { + const {json, stderr} = runWithJson(dir, ['--no-cache'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + expect(stderr).toMatch(/PASS/); + expect(json.success).toBe(true); + expect(json.numPassedTests).toBe(2); }); +}); - describe('babel-jest-async', () => { - const dir = path.resolve(__dirname, '../transform/babel-jest-async'); +describe('babel-jest-async', () => { + const dir = path.resolve(__dirname, '../transform/babel-jest-async'); - beforeAll(() => { - runYarnInstall(dir); - }); + beforeAll(() => { + runYarnInstall(dir); + }); - it("should use babel-jest's async transforms", () => { - const {json, stderr} = runWithJson(dir, ['--no-cache'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - expect(stderr).toMatch(/PASS/); - expect(json.success).toBe(true); - expect(json.numPassedTests).toBe(1); + it("should use babel-jest's async transforms", () => { + const {json, stderr} = runWithJson(dir, ['--no-cache'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + expect(stderr).toMatch(/PASS/); + expect(json.success).toBe(true); + expect(json.numPassedTests).toBe(1); }); +}); - describe('transform-esm-runner', () => { - const dir = path.resolve(__dirname, '../transform/transform-esm-runner'); - test('runs test with native ESM', () => { - const {json, stderr} = runWithJson(dir, ['--no-cache'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - - expect(stderr).toMatch(/PASS/); - expect(json.success).toBe(true); - expect(json.numPassedTests).toBe(1); +describe('transform-esm-runner', () => { + const dir = path.resolve(__dirname, '../transform/transform-esm-runner'); + test('runs test with native ESM', () => { + const {json, stderr} = runWithJson(dir, ['--no-cache'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + + expect(stderr).toMatch(/PASS/); + expect(json.success).toBe(true); + expect(json.numPassedTests).toBe(1); }); +}); - describe('transform-esm-testrunner', () => { - const dir = path.resolve( - __dirname, - '../transform/transform-esm-testrunner', - ); - test('runs test with native ESM', () => { - const {json, stderr} = runWithJson(dir, ['--no-cache'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }); - - expect(stderr).toMatch(/PASS/); - expect(json.success).toBe(true); - expect(json.numPassedTests).toBe(1); +describe('transform-esm-testrunner', () => { + const dir = path.resolve(__dirname, '../transform/transform-esm-testrunner'); + test('runs test with native ESM', () => { + const {json, stderr} = runWithJson(dir, ['--no-cache'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }); + + expect(stderr).toMatch(/PASS/); + expect(json.success).toBe(true); + expect(json.numPassedTests).toBe(1); }); }); diff --git a/e2e/__tests__/tsIntegration.test.ts b/e2e/__tests__/tsIntegration.test.ts index 953ee0aaa5ab..44870f4d369d 100644 --- a/e2e/__tests__/tsIntegration.test.ts +++ b/e2e/__tests__/tsIntegration.test.ts @@ -6,7 +6,6 @@ */ import * as path from 'path'; -import {onNodeVersions} from '@jest/test-utils'; import {cleanup, writeFiles} from '../Utils'; import runJest, {getConfig} from '../runJest'; @@ -93,30 +92,28 @@ describe('when `Config` type is imported from "@jest/types"', () => { expect(exitCode).toBe(1); }); - // The versions where vm.Module exists and commonjs with "exports" is not broken - onNodeVersions('>=12.16.0', () => { - test('works with object config exported from TS file when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", - 'jest.config.ts': ` + test('works with object config exported from TS file when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", + 'jest.config.ts': ` import type {Config} from '@jest/types'; const config: Config.InitialOptions = {displayName: 'ts-esm-object-config', verbose: true}; export default config; `, - 'package.json': '{"type": "module"}', - }); + 'package.json': '{"type": "module"}', + }); - const {configs, globalConfig} = getConfig(path.join(DIR)); + const {configs, globalConfig} = getConfig(path.join(DIR)); - expect(configs).toHaveLength(1); - expect(configs[0].displayName?.name).toBe('ts-esm-object-config'); - expect(globalConfig.verbose).toBe(true); - }); + expect(configs).toHaveLength(1); + expect(configs[0].displayName?.name).toBe('ts-esm-object-config'); + expect(globalConfig.verbose).toBe(true); + }); - test('works with function config exported from TS file when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", - 'jest.config.ts': ` + test('works with function config exported from TS file when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", + 'jest.config.ts': ` import type {Config} from '@jest/types'; async function getVerbose() {return true;} export default async (): Promise => { @@ -124,54 +121,52 @@ describe('when `Config` type is imported from "@jest/types"', () => { return {displayName: 'ts-esm-async-function-config', verbose}; }; `, - 'package.json': '{"type": "module"}', - }); + 'package.json': '{"type": "module"}', + }); - const {configs, globalConfig} = getConfig(path.join(DIR)); + const {configs, globalConfig} = getConfig(path.join(DIR)); - expect(configs).toHaveLength(1); - expect(configs[0].displayName?.name).toBe('ts-esm-async-function-config'); - expect(globalConfig.verbose).toBe(true); - }); + expect(configs).toHaveLength(1); + expect(configs[0].displayName?.name).toBe('ts-esm-async-function-config'); + expect(globalConfig.verbose).toBe(true); + }); - test('throws if type errors are encountered when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", - 'jest.config.ts': ` + test('throws if type errors are encountered when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", + 'jest.config.ts': ` import type {Config} from '@jest/types'; const config: Config.InitialOptions = {testTimeout: '10000'}; export default config; `, - 'package.json': '{"type": "module"}', - }); + 'package.json': '{"type": "module"}', + }); - const {stderr, exitCode} = runJest(DIR); + const {stderr, exitCode} = runJest(DIR); - expect(stderr).toMatch( - "jest.config.ts(2,40): error TS2322: Type 'string' is not assignable to type 'number'.", - ); - expect(exitCode).toBe(1); - }); + expect(stderr).toMatch( + "jest.config.ts(2,40): error TS2322: Type 'string' is not assignable to type 'number'.", + ); + expect(exitCode).toBe(1); + }); - test('throws if syntax errors are encountered when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': - "test('dummy', () => expect(123).toBe(123));", - 'jest.config.ts': ` + test('throws if syntax errors are encountered when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", + 'jest.config.ts': ` import type {Config} from '@jest/types'; const config: Config.InitialOptions = {verbose: true}; export default get config; `, - 'package.json': '{}', - }); + 'package.json': '{}', + }); - const {stderr, exitCode} = runJest(DIR); + const {stderr, exitCode} = runJest(DIR); - expect(stderr).toMatch( - "jest.config.ts(3,16): error TS2304: Cannot find name 'get'.", - ); - expect(exitCode).toBe(1); - }); + expect(stderr).toMatch( + "jest.config.ts(3,16): error TS2304: Cannot find name 'get'.", + ); + expect(exitCode).toBe(1); }); }); @@ -253,30 +248,28 @@ describe('when `Config` type is imported from "jest"', () => { expect(exitCode).toBe(1); }); - // The versions where vm.Module exists and commonjs with "exports" is not broken - onNodeVersions('>=12.16.0', () => { - test('works with object config exported from TS file when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", - 'jest.config.ts': ` + test('works with object config exported from TS file when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", + 'jest.config.ts': ` import type {Config} from 'jest'; const config: Config = {displayName: 'ts-esm-object-config', verbose: true}; export default config; `, - 'package.json': '{"type": "module"}', - }); + 'package.json': '{"type": "module"}', + }); - const {configs, globalConfig} = getConfig(path.join(DIR)); + const {configs, globalConfig} = getConfig(path.join(DIR)); - expect(configs).toHaveLength(1); - expect(configs[0].displayName?.name).toBe('ts-esm-object-config'); - expect(globalConfig.verbose).toBe(true); - }); + expect(configs).toHaveLength(1); + expect(configs[0].displayName?.name).toBe('ts-esm-object-config'); + expect(globalConfig.verbose).toBe(true); + }); - test('works with function config exported from TS file when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", - 'jest.config.ts': ` + test('works with function config exported from TS file when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", + 'jest.config.ts': ` import type {Config} from 'jest'; async function getVerbose() {return true;} export default async (): Promise => { @@ -284,53 +277,51 @@ describe('when `Config` type is imported from "jest"', () => { return {displayName: 'ts-esm-async-function-config', verbose}; }; `, - 'package.json': '{"type": "module"}', - }); + 'package.json': '{"type": "module"}', + }); - const {configs, globalConfig} = getConfig(path.join(DIR)); + const {configs, globalConfig} = getConfig(path.join(DIR)); - expect(configs).toHaveLength(1); - expect(configs[0].displayName?.name).toBe('ts-esm-async-function-config'); - expect(globalConfig.verbose).toBe(true); - }); + expect(configs).toHaveLength(1); + expect(configs[0].displayName?.name).toBe('ts-esm-async-function-config'); + expect(globalConfig.verbose).toBe(true); + }); - test('throws if type errors are encountered when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", - 'jest.config.ts': ` + test('throws if type errors are encountered when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(12).toBe(12));", + 'jest.config.ts': ` import type {Config} from 'jest'; const config: Config = {testTimeout: '10000'}; export default config; `, - 'package.json': '{"type": "module"}', - }); + 'package.json': '{"type": "module"}', + }); - const {stderr, exitCode} = runJest(DIR); + const {stderr, exitCode} = runJest(DIR); - expect(stderr).toMatch( - "jest.config.ts(2,25): error TS2322: Type 'string' is not assignable to type 'number'.", - ); - expect(exitCode).toBe(1); - }); + expect(stderr).toMatch( + "jest.config.ts(2,25): error TS2322: Type 'string' is not assignable to type 'number'.", + ); + expect(exitCode).toBe(1); + }); - test('throws if syntax errors are encountered when package.json#type=module', () => { - writeFiles(DIR, { - '__tests__/dummy.test.js': - "test('dummy', () => expect(123).toBe(123));", - 'jest.config.ts': ` + test('throws if syntax errors are encountered when package.json#type=module', () => { + writeFiles(DIR, { + '__tests__/dummy.test.js': "test('dummy', () => expect(123).toBe(123));", + 'jest.config.ts': ` import type {Config} from 'jest'; const config: Config = {verbose: true}; export default get config; `, - 'package.json': '{}', - }); + 'package.json': '{}', + }); - const {stderr, exitCode} = runJest(DIR); + const {stderr, exitCode} = runJest(DIR); - expect(stderr).toMatch( - "jest.config.ts(3,16): error TS2304: Cannot find name 'get'.", - ); - expect(exitCode).toBe(1); - }); + expect(stderr).toMatch( + "jest.config.ts(3,16): error TS2304: Cannot find name 'get'.", + ); + expect(exitCode).toBe(1); }); }); diff --git a/e2e/__tests__/watch-plugins.test.ts b/e2e/__tests__/watch-plugins.test.ts index 3120c64bd58e..5a485f8d9183 100644 --- a/e2e/__tests__/watch-plugins.test.ts +++ b/e2e/__tests__/watch-plugins.test.ts @@ -4,7 +4,6 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import {onNodeVersions} from '@jest/test-utils'; import {runContinuous} from '../runJest'; const testCompletedRE = /Ran all test suites./g; @@ -26,20 +25,18 @@ test.each(['js', 'cjs'])('supports %s watch plugins', async watchPluginDir => { await testRun.end(); }); -onNodeVersions('>=12.17.0', () => { - test.each(['mjs', 'js-type-module'])( - 'supports %s watch plugins', - async watchPluginDir => { - const testRun = runContinuous(`watch-plugins/${watchPluginDir}`, [ - '--watchAll', - '--no-watchman', - ]); +test.each(['mjs', 'js-type-module'])( + 'supports %s watch plugins', + async watchPluginDir => { + const testRun = runContinuous(`watch-plugins/${watchPluginDir}`, [ + '--watchAll', + '--no-watchman', + ]); - await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 1); + await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 1); - expect(testRun.getCurrentOutput().stdout.trim()).toBe('getUsageInfo'); + expect(testRun.getCurrentOutput().stdout.trim()).toBe('getUsageInfo'); - await testRun.end(); - }, - ); -}); + await testRun.end(); + }, +); diff --git a/package.json b/package.json index c9b674865bb2..c9e040cd5867 100644 --- a/package.json +++ b/package.json @@ -13,14 +13,14 @@ "@jest/globals": "workspace:*", "@jest/test-utils": "workspace:*", "@microsoft/api-extractor": "^7.28.4", - "@tsconfig/node12": "^1.0.9", + "@tsconfig/node14": "^1.0.3", "@tsd/typescript": "~4.7.4", "@types/babel__core": "^7.1.14", "@types/babel__generator": "^7.0.0", "@types/babel__template": "^7.0.2", "@types/dedent": "^0.7.0", "@types/jest": "^27.4.0", - "@types/node": "~12.12.0", + "@types/node": "~14.14.45", "@types/which": "^2.0.0", "@typescript-eslint/eslint-plugin": "^5.14.0", "@typescript-eslint/parser": "^5.14.0", @@ -167,10 +167,10 @@ "logo": "https://opencollective.com/jest/logo.txt" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "resolutions": { - "@types/node": "~12.12.0", + "@types/node": "~14.14.45", "babel-jest": "workspace:*", "enzyme/cheerio": "=1.0.0-rc.3", "jest": "workspace:*", diff --git a/packages/babel-jest/package.json b/packages/babel-jest/package.json index b503a93c6e46..818ee354a7e0 100644 --- a/packages/babel-jest/package.json +++ b/packages/babel-jest/package.json @@ -35,7 +35,7 @@ "@babel/core": "^7.8.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/babel-plugin-jest-hoist/package.json b/packages/babel-plugin-jest-hoist/package.json index 6cb385ac8545..ed9f609d1425 100644 --- a/packages/babel-plugin-jest-hoist/package.json +++ b/packages/babel-plugin-jest-hoist/package.json @@ -7,7 +7,7 @@ "directory": "packages/babel-plugin-jest-hoist" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/babel-preset-jest/package.json b/packages/babel-preset-jest/package.json index 20345e04b9f7..a55934d5c0f6 100644 --- a/packages/babel-preset-jest/package.json +++ b/packages/babel-preset-jest/package.json @@ -20,7 +20,7 @@ "@babel/core": "^7.0.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/diff-sequences/package.json b/packages/diff-sequences/package.json index 03b3cb3c7952..a8200180b2bc 100644 --- a/packages/diff-sequences/package.json +++ b/packages/diff-sequences/package.json @@ -16,7 +16,7 @@ "diff" ], "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "main": "./build/index.js", "types": "./build/index.d.ts", diff --git a/packages/expect-utils/package.json b/packages/expect-utils/package.json index 1ddd71bfa22c..e3b7d944499c 100644 --- a/packages/expect-utils/package.json +++ b/packages/expect-utils/package.json @@ -24,7 +24,7 @@ "jest-matcher-utils": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/expect/package.json b/packages/expect/package.json index a5f66f59ee8d..7dde3e385268 100644 --- a/packages/expect/package.json +++ b/packages/expect/package.json @@ -33,7 +33,7 @@ "tsd-lite": "^0.5.6" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-changed-files/package.json b/packages/jest-changed-files/package.json index 7c4f0a307dbc..f3e939f2b8d7 100644 --- a/packages/jest-changed-files/package.json +++ b/packages/jest-changed-files/package.json @@ -21,7 +21,7 @@ "p-limit": "^3.1.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index eee96aa2c10a..be9a3a5b8d18 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -49,7 +49,7 @@ "graceful-fs": "^4.2.9" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index 5059f21d3a0b..1f83e40b142f 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -44,7 +44,7 @@ "jest": "./bin/jest.js" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "repository": { "type": "git", diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index b23d6b72f616..60d64ce2f057 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -61,7 +61,7 @@ "typescript": "^4.7.4" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-console/package.json b/packages/jest-console/package.json index e6fa106d96e5..1f39f9e1a13c 100644 --- a/packages/jest-console/package.json +++ b/packages/jest-console/package.json @@ -28,7 +28,7 @@ "@jest/test-utils": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-core/package.json b/packages/jest-core/package.json index 41c67431a3b8..d6f8dafeacfb 100644 --- a/packages/jest-core/package.json +++ b/packages/jest-core/package.json @@ -59,7 +59,7 @@ } }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "repository": { "type": "git", diff --git a/packages/jest-create-cache-key-function/package.json b/packages/jest-create-cache-key-function/package.json index 04a334b75872..f980e3f06b86 100644 --- a/packages/jest-create-cache-key-function/package.json +++ b/packages/jest-create-cache-key-function/package.json @@ -14,7 +14,7 @@ "jest-util": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-diff/package.json b/packages/jest-diff/package.json index 4e7b9960cf5d..ff14356c591a 100644 --- a/packages/jest-diff/package.json +++ b/packages/jest-diff/package.json @@ -27,7 +27,7 @@ "strip-ansi": "^6.0.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-docblock/package.json b/packages/jest-docblock/package.json index 37260009bbd2..e5854cccf8a5 100644 --- a/packages/jest-docblock/package.json +++ b/packages/jest-docblock/package.json @@ -23,7 +23,7 @@ "@types/node": "*" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-each/package.json b/packages/jest-each/package.json index d51bbf83588f..70ddc5d62c50 100644 --- a/packages/jest-each/package.json +++ b/packages/jest-each/package.json @@ -32,7 +32,7 @@ "pretty-format": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-environment-jsdom/package.json b/packages/jest-environment-jsdom/package.json index fd4f1f26aeb8..f7beb56fd63b 100644 --- a/packages/jest-environment-jsdom/package.json +++ b/packages/jest-environment-jsdom/package.json @@ -30,7 +30,7 @@ "@jest/test-utils": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-environment-node/package.json b/packages/jest-environment-node/package.json index 53c87b7a9c49..d4f648ef8987 100644 --- a/packages/jest-environment-node/package.json +++ b/packages/jest-environment-node/package.json @@ -28,7 +28,7 @@ "@jest/test-utils": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-environment/package.json b/packages/jest-environment/package.json index fdbafc95f05e..e0312c547c0b 100644 --- a/packages/jest-environment/package.json +++ b/packages/jest-environment/package.json @@ -23,7 +23,7 @@ "jest-mock": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-expect/package.json b/packages/jest-expect/package.json index 1eeab67627bf..16c675b1667d 100644 --- a/packages/jest-expect/package.json +++ b/packages/jest-expect/package.json @@ -25,7 +25,7 @@ "tsd-lite": "^0.5.6" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-fake-timers/package.json b/packages/jest-fake-timers/package.json index c6edc398af14..5db2790345f0 100644 --- a/packages/jest-fake-timers/package.json +++ b/packages/jest-fake-timers/package.json @@ -29,7 +29,7 @@ "@types/sinonjs__fake-timers": "^8.1.2" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-get-type/package.json b/packages/jest-get-type/package.json index 778b67b70ab1..267de7d80f3c 100644 --- a/packages/jest-get-type/package.json +++ b/packages/jest-get-type/package.json @@ -8,7 +8,7 @@ "directory": "packages/jest-get-type" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-globals/package.json b/packages/jest-globals/package.json index 41e21c2ff367..cd29214e3d78 100644 --- a/packages/jest-globals/package.json +++ b/packages/jest-globals/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-globals" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-haste-map/package.json b/packages/jest-haste-map/package.json index 7823d1cb910e..12160cac68b0 100644 --- a/packages/jest-haste-map/package.json +++ b/packages/jest-haste-map/package.json @@ -39,7 +39,7 @@ "fsevents": "^2.3.2" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index b3585c29d52e..c3f65c495ef4 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -746,7 +746,6 @@ export default class HasteMap extends EventEmitter { } else { this._worker = new Worker(require.resolve('./worker'), { exposedMethods: ['getSha1', 'worker'], - // @ts-expect-error: option does not exist on the node 12 types forkOptions: {serialization: 'json'}, maxRetries: 3, numWorkers: this._options.maxWorkers, diff --git a/packages/jest-jasmine2/package.json b/packages/jest-jasmine2/package.json index f53cb3952a2b..6598e136bd15 100644 --- a/packages/jest-jasmine2/package.json +++ b/packages/jest-jasmine2/package.json @@ -39,7 +39,7 @@ "@types/co": "^4.6.2" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-leak-detector/package.json b/packages/jest-leak-detector/package.json index 98db4119936b..21748ff3895d 100644 --- a/packages/jest-leak-detector/package.json +++ b/packages/jest-leak-detector/package.json @@ -25,7 +25,7 @@ "weak-napi": "^2.0.1" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-matcher-utils/package.json b/packages/jest-matcher-utils/package.json index cf30dbc403e4..4f7eea14836c 100644 --- a/packages/jest-matcher-utils/package.json +++ b/packages/jest-matcher-utils/package.json @@ -8,7 +8,7 @@ "directory": "packages/jest-matcher-utils" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index 8f23e35a703c..f8b7983a9386 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-message-util" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-mock/package.json b/packages/jest-mock/package.json index 79d7e9f2ded5..37194c118651 100644 --- a/packages/jest-mock/package.json +++ b/packages/jest-mock/package.json @@ -25,7 +25,7 @@ "tsd-lite": "^0.5.6" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-phabricator/package.json b/packages/jest-phabricator/package.json index 7128dc5d4380..9817198a3912 100644 --- a/packages/jest-phabricator/package.json +++ b/packages/jest-phabricator/package.json @@ -18,7 +18,7 @@ "@jest/test-result": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-regex-util/package.json b/packages/jest-regex-util/package.json index 0416358f5577..6d9be48684c7 100644 --- a/packages/jest-regex-util/package.json +++ b/packages/jest-regex-util/package.json @@ -10,7 +10,7 @@ "@types/node": "*" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-repl/package.json b/packages/jest-repl/package.json index c53533ef7df1..4cc29e6b2462 100644 --- a/packages/jest-repl/package.json +++ b/packages/jest-repl/package.json @@ -40,7 +40,7 @@ "jest-runtime": "./bin/jest-runtime-cli.js" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index c3b6c8b91471..4dfa67de4877 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -63,7 +63,7 @@ } }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "repository": { "type": "git", diff --git a/packages/jest-reporters/src/CoverageReporter.ts b/packages/jest-reporters/src/CoverageReporter.ts index 3c7c21e89ede..a09e0f9b3f1b 100644 --- a/packages/jest-reporters/src/CoverageReporter.ts +++ b/packages/jest-reporters/src/CoverageReporter.ts @@ -148,7 +148,6 @@ export default class CoverageReporter extends BaseReporter { } else { worker = new Worker(require.resolve('./CoverageWorker'), { exposedMethods: ['worker'], - // @ts-expect-error: option does not exist on the node 12 types forkOptions: {serialization: 'json'}, maxRetries: 2, numWorkers: this._globalConfig.maxWorkers, diff --git a/packages/jest-resolve-dependencies/package.json b/packages/jest-resolve-dependencies/package.json index 4eb41b4bfa44..fdc7a27a7050 100644 --- a/packages/jest-resolve-dependencies/package.json +++ b/packages/jest-resolve-dependencies/package.json @@ -28,7 +28,7 @@ "jest-runtime": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 1c4369c2ee42..0e91f5d84941 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -35,7 +35,7 @@ "tsd-lite": "^0.5.6" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index 66d3fde19525..9dcb7267bbf5 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -48,7 +48,7 @@ "tsd-lite": "^0.5.6" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index 46233f1a60b5..d43f899f796d 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -106,7 +106,6 @@ export default class TestRunner extends EmittingTestRunner { const worker = new Worker(require.resolve('./testWorker'), { exposedMethods: ['worker'], - // @ts-expect-error: option does not exist on the node 12 types forkOptions: {serialization: 'json', stdio: 'pipe'}, maxRetries: 3, numWorkers: this._globalConfig.maxWorkers, diff --git a/packages/jest-runtime/package.json b/packages/jest-runtime/package.json index 66b47bfd977f..e978068c8779 100644 --- a/packages/jest-runtime/package.json +++ b/packages/jest-runtime/package.json @@ -27,7 +27,6 @@ "chalk": "^4.0.0", "cjs-module-lexer": "^1.0.0", "collect-v8-coverage": "^1.0.0", - "execa": "^5.0.0", "glob": "^7.1.3", "graceful-fs": "^4.2.9", "jest-haste-map": "^28.1.3", @@ -48,7 +47,7 @@ "jest-environment-node": "^28.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 5b9f869bc55a..5a4b38af6b06 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -20,7 +20,6 @@ import { } from 'vm'; import {parse as parseCjs} from 'cjs-module-lexer'; import {CoverageInstrumenter, V8Coverage} from 'collect-v8-coverage'; -import execa = require('execa'); import * as fs from 'graceful-fs'; import slash = require('slash'); import stripBOM = require('strip-bom'); @@ -144,19 +143,6 @@ type RunScriptEvalResult = {[EVAL_RESULT_VARIABLE]: ModuleWrapper}; const runtimeSupportsVmModules = typeof SyntheticModule === 'function'; -const supportsTopLevelAwait = - runtimeSupportsVmModules && - (() => { - try { - // eslint-disable-next-line no-new - new SourceTextModule('await Promise.resolve()'); - - return true; - } catch { - return false; - } - })(); - const supportsNodeColonModulePrefixInRequire = (() => { try { require('node:fs'); @@ -167,19 +153,6 @@ const supportsNodeColonModulePrefixInRequire = (() => { } })(); -const supportsNodeColonModulePrefixInImport = (() => { - const {stdout} = execa.sync( - 'node', - [ - '--eval', - 'import("node:fs").then(() => console.log(true), () => console.log(false));', - ], - {reject: false}, - ); - - return stdout === 'true'; -})(); - export default class Runtime { private readonly _cacheFS: Map; private readonly _config: Config.ProjectConfig; @@ -479,7 +452,7 @@ export default class Runtime { supportsDynamicImport: true, supportsExportNamespaceFrom: true, supportsStaticESM: true, - supportsTopLevelAwait, + supportsTopLevelAwait: true, }); try { @@ -1663,10 +1636,7 @@ export default class Runtime { } private _importCoreModule(moduleName: string, context: VMContext) { - const required = this._requireCoreModule( - moduleName, - supportsNodeColonModulePrefixInImport, - ); + const required = this._requireCoreModule(moduleName, true); const module = new SyntheticModule( ['default', ...Object.keys(required)], diff --git a/packages/jest-schemas/package.json b/packages/jest-schemas/package.json index a47599199010..b64075515202 100644 --- a/packages/jest-schemas/package.json +++ b/packages/jest-schemas/package.json @@ -20,7 +20,7 @@ "@sinclair/typebox": "^0.24.1" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index 02107054fe89..0c67254a4774 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -55,7 +55,7 @@ "tsd-lite": "^0.5.6" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-source-map/package.json b/packages/jest-source-map/package.json index 6d0b49879516..6cdc7d997ffe 100644 --- a/packages/jest-source-map/package.json +++ b/packages/jest-source-map/package.json @@ -25,7 +25,7 @@ "@types/graceful-fs": "^4.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-test-result/package.json b/packages/jest-test-result/package.json index a1331a527796..b66fea2c29a4 100644 --- a/packages/jest-test-result/package.json +++ b/packages/jest-test-result/package.json @@ -23,7 +23,7 @@ "collect-v8-coverage": "^1.0.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json index 57a98ce17b78..16dc99de01a7 100644 --- a/packages/jest-test-sequencer/package.json +++ b/packages/jest-test-sequencer/package.json @@ -27,7 +27,7 @@ "@types/graceful-fs": "^4.1.3" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-transform/package.json b/packages/jest-transform/package.json index 972ff6686bad..1ab0e080c29e 100644 --- a/packages/jest-transform/package.json +++ b/packages/jest-transform/package.json @@ -44,7 +44,7 @@ "dedent": "^0.7.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-types/package.json b/packages/jest-types/package.json index 46470ec6c454..9cda9ae0a178 100644 --- a/packages/jest-types/package.json +++ b/packages/jest-types/package.json @@ -7,7 +7,7 @@ "directory": "packages/jest-types" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "license": "MIT", "main": "./build/index.js", diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index eb630efc570b..12cc9acf48f7 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -29,7 +29,7 @@ "@types/picomatch": "^2.2.2" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-validate/package.json b/packages/jest-validate/package.json index 3f57b71d1a11..5ed18b8a10ca 100644 --- a/packages/jest-validate/package.json +++ b/packages/jest-validate/package.json @@ -28,7 +28,7 @@ "@types/yargs": "^17.0.8" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-watcher/package.json b/packages/jest-watcher/package.json index 21e9467de31d..cdaa3e53061d 100644 --- a/packages/jest-watcher/package.json +++ b/packages/jest-watcher/package.json @@ -30,7 +30,7 @@ "url": "https://github.com/facebook/jest/issues" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "homepage": "https://jestjs.io/", "license": "MIT", diff --git a/packages/jest-worker/package.json b/packages/jest-worker/package.json index 45b662d79331..6044e9a68252 100644 --- a/packages/jest-worker/package.json +++ b/packages/jest-worker/package.json @@ -31,7 +31,7 @@ "worker-farm": "^1.6.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.ts b/packages/jest-worker/src/workers/ChildProcessWorker.ts index 39d2109fa168..aa724124545b 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.ts +++ b/packages/jest-worker/src/workers/ChildProcessWorker.ts @@ -93,7 +93,6 @@ export default class ChildProcessWorker implements WorkerInterface { // Suppress --debug / --inspect flags while preserving others (like --harmony). execArgv: process.execArgv.filter(v => !/^--(debug|inspect)/.test(v)), // default to advanced serialization in order to match worker threads - // @ts-expect-error: option does not exist on the node 12 types serialization: 'advanced', silent: true, ...this._options.forkOptions, diff --git a/packages/jest/package.json b/packages/jest/package.json index 19ec20c25967..948381025fbb 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -32,7 +32,7 @@ }, "bin": "./bin/jest.js", "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "repository": { "type": "git", diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index 2146c8a00bcb..357760b02749 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -37,7 +37,7 @@ "react-test-renderer": "17.0.2" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" }, "publishConfig": { "access": "public" diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 36bc18c403f2..4f3415f3ec54 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -23,6 +23,6 @@ "@types/semver": "^7.1.0" }, "engines": { - "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } } diff --git a/scripts/verifyOldTs.mjs b/scripts/verifyOldTs.mjs index 9ad40b74fe6a..00ec841a1161 100644 --- a/scripts/verifyOldTs.mjs +++ b/scripts/verifyOldTs.mjs @@ -51,7 +51,7 @@ function smoketest() { execa.sync('yarn', ['init', '--yes'], {cwd, stdio: 'inherit'}); execa.sync( 'yarn', - ['add', `typescript@~${tsVersion}`, '@tsconfig/node12'], + ['add', `typescript@~${tsVersion}`, '@tsconfig/node14'], {cwd, stdio: 'inherit'}, ); fs.writeFileSync( diff --git a/tsconfig.json b/tsconfig.json index 574e1e6ec482..62d5dc50bd2c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "@tsconfig/node12/tsconfig.json", + "extends": "@tsconfig/node14/tsconfig.json", "compilerOptions": { "composite": true, "declaration": true, diff --git a/website/sidebars.json b/website/sidebars.json index 7e109761b982..72f8506cbd5d 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -34,7 +34,7 @@ "testing-frameworks" ], "Upgrade Guides": [ - "upgrading-to-jest28" + "upgrading-to-jest29" ] }, "api": [ diff --git a/yarn.lock b/yarn.lock index 7d76a0d2fbe7..8db66fee7ef6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2706,14 +2706,14 @@ __metadata: "@jest/globals": "workspace:*" "@jest/test-utils": "workspace:*" "@microsoft/api-extractor": ^7.28.4 - "@tsconfig/node12": ^1.0.9 + "@tsconfig/node14": ^1.0.3 "@tsd/typescript": ~4.7.4 "@types/babel__core": ^7.1.14 "@types/babel__generator": ^7.0.0 "@types/babel__template": ^7.0.2 "@types/dedent": ^0.7.0 "@types/jest": ^27.4.0 - "@types/node": ~12.12.0 + "@types/node": ~14.14.45 "@types/which": ^2.0.0 "@typescript-eslint/eslint-plugin": ^5.14.0 "@typescript-eslint/parser": ^5.14.0 @@ -4789,30 +4789,30 @@ __metadata: linkType: hard "@tsconfig/node10@npm:^1.0.7": - version: 1.0.8 - resolution: "@tsconfig/node10@npm:1.0.8" - checksum: b8d5fffbc6b17ef64ef74f7fdbccee02a809a063ade785c3648dae59406bc207f70ea2c4296f92749b33019fa36a5ae716e42e49cc7f1bbf0fd147be0d6b970a + version: 1.0.9 + resolution: "@tsconfig/node10@npm:1.0.9" + checksum: a33ae4dc2a621c0678ac8ac4bceb8e512ae75dac65417a2ad9b022d9b5411e863c4c198b6ba9ef659e14b9fb609bbec680841a2e84c1172df7a5ffcf076539df languageName: node linkType: hard -"@tsconfig/node12@npm:^1.0.7, @tsconfig/node12@npm:^1.0.9": - version: 1.0.9 - resolution: "@tsconfig/node12@npm:1.0.9" - checksum: a01b2400ab3582b86b589c6d31dcd0c0656f333adecde85d6d7d4086adb059808b82692380bb169546d189bf771ae21d02544a75b57bd6da4a5dd95f8567bec9 +"@tsconfig/node12@npm:^1.0.7": + version: 1.0.11 + resolution: "@tsconfig/node12@npm:1.0.11" + checksum: 5ce29a41b13e7897a58b8e2df11269c5395999e588b9a467386f99d1d26f6c77d1af2719e407621412520ea30517d718d5192a32403b8dfcc163bf33e40a338a languageName: node linkType: hard -"@tsconfig/node14@npm:^1.0.0": - version: 1.0.1 - resolution: "@tsconfig/node14@npm:1.0.1" - checksum: 976345e896c0f059867f94f8d0f6ddb8b1844fb62bf36b727de8a9a68f024857e5db97ed51d3325e23e0616a5e48c034ff51a8d595b3fe7e955f3587540489be +"@tsconfig/node14@npm:^1.0.0, @tsconfig/node14@npm:^1.0.3": + version: 1.0.3 + resolution: "@tsconfig/node14@npm:1.0.3" + checksum: 19275fe80c4c8d0ad0abed6a96dbf00642e88b220b090418609c4376e1cef81bf16237bf170ad1b341452feddb8115d8dd2e5acdfdea1b27422071163dc9ba9d languageName: node linkType: hard "@tsconfig/node16@npm:^1.0.2": - version: 1.0.2 - resolution: "@tsconfig/node16@npm:1.0.2" - checksum: ca94d3639714672bbfd55f03521d3f56bb6a25479bd425da81faf21f13e1e9d15f40f97377dedbbf477a5841c5b0c8f4cd1b391f33553d750b9202c54c2c07aa + version: 1.0.3 + resolution: "@tsconfig/node16@npm:1.0.3" + checksum: 3a8b657dd047495b7ad23437d6afd20297ce90380ff0bdee93fc7d39a900dbd8d9e26e53ff6b465e7967ce2adf0b218782590ce9013285121e6a5928fbd6819f languageName: node linkType: hard @@ -5286,10 +5286,10 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:~12.12.0": - version: 12.12.70 - resolution: "@types/node@npm:12.12.70" - checksum: 69c193e0bce8fa914d478f829bd923ee662b220e069a2e00ffbe109f27d0b38fbf2a9fe78c99eb4d4ccb294248ff8de68019a2c7fadb032d301c6feca25f3d22 +"@types/node@npm:~14.14.45": + version: 14.14.45 + resolution: "@types/node@npm:14.14.45" + checksum: 3870a0128011b01c6fb6655e0f682b1b660e141f84d76c70fe503f5c7cf38bd06fc7b9a7d3c760601bce0598421f552695de40f095863ede29a6e22a13213b3e languageName: node linkType: hard @@ -13604,7 +13604,6 @@ __metadata: chalk: ^4.0.0 cjs-module-lexer: ^1.0.0 collect-v8-coverage: ^1.0.0 - execa: ^5.0.0 glob: ^7.1.3 graceful-fs: ^4.2.9 jest-environment-node: ^28.1.3