diff --git a/e2e/__tests__/__snapshots__/native-esm-js.test.ts.snap b/e2e/__tests__/__snapshots__/native-esm-js.test.ts.snap index d300a7b3a6..15f70279ba 100644 --- a/e2e/__tests__/__snapshots__/native-esm-js.test.ts.snap +++ b/e2e/__tests__/__snapshots__/native-esm-js.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`on node >=14.15.0 runs test with native ESM and isolatedModules: false 1`] = ` +exports[`runs test with native ESM and isolatedModules: false 1`] = ` Test Suites: 1 passed, 1 total Tests: 21 passed, 21 total Snapshots: 0 total @@ -8,7 +8,7 @@ Time: <> Ran all test suites matching /native-esm.spec.ts/i. `; -exports[`on node >=14.15.0 runs test with native ESM and isolatedModules: true 1`] = ` +exports[`runs test with native ESM and isolatedModules: true 1`] = ` Test Suites: 1 passed, 1 total Tests: 21 passed, 21 total Snapshots: 0 total @@ -16,7 +16,7 @@ Time: <> Ran all test suites matching /native-esm.spec.ts/i. `; -exports[`on node >=14.3.0 supports top-level await and isolatedModules: false 1`] = ` +exports[`supports top-level await and isolatedModules: false 1`] = ` Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total @@ -24,7 +24,7 @@ Time: <> Ran all test suites matching /native-esm-tla.spec.ts/i. `; -exports[`on node >=14.3.0 supports top-level await and isolatedModules: true 1`] = ` +exports[`supports top-level await and isolatedModules: true 1`] = ` Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total diff --git a/e2e/__tests__/extend-ts-jest.test.ts b/e2e/__tests__/extend-ts-jest.test.ts index 58ce217a6d..8622ed92ef 100644 --- a/e2e/__tests__/extend-ts-jest.test.ts +++ b/e2e/__tests__/extend-ts-jest.test.ts @@ -1,15 +1,12 @@ -import { json as runWithJson, onNodeVersions } from '../run-jest' +import { json as runWithJson } from '../run-jest' const DIR = 'extend-ts-jest' -// Only need to test in ESM because ESM makes `this` context become `undefined` -onNodeVersions('>=14.15.0', () => { - test(`successfully runs the tests inside ${DIR}`, () => { - const { json } = runWithJson(DIR, undefined, { - nodeOptions: '--experimental-vm-modules --no-warnings', - }) - - expect(json.success).toBe(true) - expect(json.numTotalTestSuites).toBe(1) +test(`successfully runs the tests inside ${DIR}`, () => { + const { json } = runWithJson(DIR, undefined, { + nodeOptions: '--experimental-vm-modules --no-warnings', }) + + expect(json.success).toBe(true) + expect(json.numTotalTestSuites).toBe(1) }) diff --git a/e2e/__tests__/native-esm-js.test.ts b/e2e/__tests__/native-esm-js.test.ts index 9c84f9b70c..16dcc44efe 100644 --- a/e2e/__tests__/native-esm-js.test.ts +++ b/e2e/__tests__/native-esm-js.test.ts @@ -2,58 +2,52 @@ import path from 'path' import { wrap } from 'jest-snapshot-serializer-raw' -import runJest, { onNodeVersions } from '../run-jest' +import runJest from '../run-jest' import { extractSummary } from '../utils' const DIR = path.resolve(__dirname, '..', 'native-esm-js', 'non-isolated') const ISOLATED_MODULES_DIR = path.resolve(__dirname, '..', 'native-esm-js', 'isolated') -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=14.15.0', () => { - test('runs test with native ESM and isolatedModules: false', () => { - const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm.spec.ts'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }) - const { summary } = extractSummary(stderr) - - expect(wrap(summary)).toMatchSnapshot() - expect(stdout).toBe('') - expect(exitCode).toBe(0) +test('runs test with native ESM and isolatedModules: false', () => { + const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm.spec.ts'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }) + const { summary } = extractSummary(stderr) - test('runs test with native ESM and isolatedModules: true', () => { - const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm.spec.ts'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }) - const { summary } = extractSummary(stderr) + expect(wrap(summary)).toMatchSnapshot() + expect(stdout).toBe('') + expect(exitCode).toBe(0) +}) - expect(wrap(summary)).toMatchSnapshot() - expect(stdout).toBe('') - expect(exitCode).toBe(0) +test('runs test with native ESM and isolatedModules: true', () => { + const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm.spec.ts'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }) + const { summary } = extractSummary(stderr) + + expect(wrap(summary)).toMatchSnapshot() + expect(stdout).toBe('') + expect(exitCode).toBe(0) }) -// The versions where Top-Level Await is supported -onNodeVersions('>=14.3.0', () => { - test('supports top-level await and isolatedModules: false', () => { - const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm-tla.spec.ts'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }) - const { summary } = extractSummary(stderr) - - expect(wrap(summary)).toMatchSnapshot() - expect(stdout).toBe('') - expect(exitCode).toBe(0) +test('supports top-level await and isolatedModules: false', () => { + const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm-tla.spec.ts'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }) + const { summary } = extractSummary(stderr) - test('supports top-level await and isolatedModules: true', () => { - const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm-tla.spec.ts'], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }) - const { summary } = extractSummary(stderr) + expect(wrap(summary)).toMatchSnapshot() + expect(stdout).toBe('') + expect(exitCode).toBe(0) +}) - expect(wrap(summary)).toMatchSnapshot() - expect(stdout).toBe('') - expect(exitCode).toBe(0) +test('supports top-level await and isolatedModules: true', () => { + const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm-tla.spec.ts'], { + nodeOptions: '--experimental-vm-modules --no-warnings', }) + const { summary } = extractSummary(stderr) + + expect(wrap(summary)).toMatchSnapshot() + expect(stdout).toBe('') + expect(exitCode).toBe(0) }) diff --git a/e2e/__tests__/native-esm-ts.test.ts b/e2e/__tests__/native-esm-ts.test.ts index 3eb3189ca0..223fbc3890 100644 --- a/e2e/__tests__/native-esm-ts.test.ts +++ b/e2e/__tests__/native-esm-ts.test.ts @@ -1,14 +1,11 @@ -import { onNodeVersions, json as runWithJson } from '../run-jest' +import { json as runWithJson } from '../run-jest' -// The versions where vm.Module exists and commonjs with "exports" is not broken -onNodeVersions('>=14.15.0', () => { - test('runs TS test with native ESM', () => { - const { exitCode, json } = runWithJson('native-esm-ts', [], { - nodeOptions: '--experimental-vm-modules --no-warnings', - }) - - expect(exitCode).toBe(0) - expect(json.numTotalTests).toBe(4) - expect(json.numPassedTests).toBe(4) +test('runs TS test with native ESM', () => { + const { exitCode, json } = runWithJson('native-esm-ts', [], { + nodeOptions: '--experimental-vm-modules --no-warnings', }) + + expect(exitCode).toBe(0) + expect(json.numTotalTests).toBe(4) + expect(json.numPassedTests).toBe(4) }) diff --git a/e2e/run-jest.ts b/e2e/run-jest.ts index e77c2aea03..82a8a81e56 100644 --- a/e2e/run-jest.ts +++ b/e2e/run-jest.ts @@ -3,7 +3,6 @@ import * as path from 'path' import type { FormattedTestResults } from '@jest/test-result' import execa from 'execa' import * as fs from 'graceful-fs' -import semver from 'semver' import stripAnsi from 'strip-ansi' import { normalizeIcons } from './utils' @@ -116,18 +115,3 @@ export const json = function (dir: string, args?: string[], options: RunJestOpti ) } } - -export const onNodeVersions = (versionRange: string, testBody: () => void): void => { - const description = `on node ${versionRange}` - if (semver.satisfies(process.versions.node, versionRange)) { - // eslint-disable-next-line jest/valid-title - describe(description, () => { - testBody() - }) - } else { - // eslint-disable-next-line jest/valid-title,jest/no-disabled-tests - describe.skip(description, () => { - testBody() - }) - } -}