Skip to content

Commit 2d16f4a

Browse files
Anh Phamahnpnl
Anh Pham
authored andcommitted
test(e2e): remove onNodeVersions function
Since we support only Node 16+, we can safely remove this function
1 parent 0861a66 commit 2d16f4a

File tree

5 files changed

+52
-80
lines changed

5 files changed

+52
-80
lines changed

e2e/__tests__/__snapshots__/native-esm-js.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`on node >=14.15.0 runs test with native ESM and isolatedModules: false 1`] = `
3+
exports[`runs test with native ESM and isolatedModules: false 1`] = `
44
Test Suites: 1 passed, 1 total
55
Tests: 21 passed, 21 total
66
Snapshots: 0 total
77
Time: <<REPLACED>>
88
Ran all test suites matching /native-esm.spec.ts/i.
99
`;
1010
11-
exports[`on node >=14.15.0 runs test with native ESM and isolatedModules: true 1`] = `
11+
exports[`runs test with native ESM and isolatedModules: true 1`] = `
1212
Test Suites: 1 passed, 1 total
1313
Tests: 21 passed, 21 total
1414
Snapshots: 0 total
1515
Time: <<REPLACED>>
1616
Ran all test suites matching /native-esm.spec.ts/i.
1717
`;
1818
19-
exports[`on node >=14.3.0 supports top-level await and isolatedModules: false 1`] = `
19+
exports[`supports top-level await and isolatedModules: false 1`] = `
2020
Test Suites: 1 passed, 1 total
2121
Tests: 1 passed, 1 total
2222
Snapshots: 0 total
2323
Time: <<REPLACED>>
2424
Ran all test suites matching /native-esm-tla.spec.ts/i.
2525
`;
2626
27-
exports[`on node >=14.3.0 supports top-level await and isolatedModules: true 1`] = `
27+
exports[`supports top-level await and isolatedModules: true 1`] = `
2828
Test Suites: 1 passed, 1 total
2929
Tests: 1 passed, 1 total
3030
Snapshots: 0 total

e2e/__tests__/extend-ts-jest.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import { json as runWithJson, onNodeVersions } from '../run-jest'
1+
import { json as runWithJson } from '../run-jest'
22

33
const DIR = 'extend-ts-jest'
44

5-
// Only need to test in ESM because ESM makes `this` context become `undefined`
6-
onNodeVersions('>=14.15.0', () => {
7-
test(`successfully runs the tests inside ${DIR}`, () => {
8-
const { json } = runWithJson(DIR, undefined, {
9-
nodeOptions: '--experimental-vm-modules --no-warnings',
10-
})
11-
12-
expect(json.success).toBe(true)
13-
expect(json.numTotalTestSuites).toBe(1)
5+
test(`successfully runs the tests inside ${DIR}`, () => {
6+
const { json } = runWithJson(DIR, undefined, {
7+
nodeOptions: '--experimental-vm-modules --no-warnings',
148
})
9+
10+
expect(json.success).toBe(true)
11+
expect(json.numTotalTestSuites).toBe(1)
1512
})

e2e/__tests__/native-esm-js.test.ts

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,52 @@ import path from 'path'
22

33
import { wrap } from 'jest-snapshot-serializer-raw'
44

5-
import runJest, { onNodeVersions } from '../run-jest'
5+
import runJest from '../run-jest'
66
import { extractSummary } from '../utils'
77

88
const DIR = path.resolve(__dirname, '..', 'native-esm-js', 'non-isolated')
99
const ISOLATED_MODULES_DIR = path.resolve(__dirname, '..', 'native-esm-js', 'isolated')
1010

11-
// The versions where vm.Module exists and commonjs with "exports" is not broken
12-
onNodeVersions('>=14.15.0', () => {
13-
test('runs test with native ESM and isolatedModules: false', () => {
14-
const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm.spec.ts'], {
15-
nodeOptions: '--experimental-vm-modules --no-warnings',
16-
})
17-
const { summary } = extractSummary(stderr)
18-
19-
expect(wrap(summary)).toMatchSnapshot()
20-
expect(stdout).toBe('')
21-
expect(exitCode).toBe(0)
11+
test('runs test with native ESM and isolatedModules: false', () => {
12+
const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm.spec.ts'], {
13+
nodeOptions: '--experimental-vm-modules --no-warnings',
2214
})
15+
const { summary } = extractSummary(stderr)
2316

24-
test('runs test with native ESM and isolatedModules: true', () => {
25-
const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm.spec.ts'], {
26-
nodeOptions: '--experimental-vm-modules --no-warnings',
27-
})
28-
const { summary } = extractSummary(stderr)
17+
expect(wrap(summary)).toMatchSnapshot()
18+
expect(stdout).toBe('')
19+
expect(exitCode).toBe(0)
20+
})
2921

30-
expect(wrap(summary)).toMatchSnapshot()
31-
expect(stdout).toBe('')
32-
expect(exitCode).toBe(0)
22+
test('runs test with native ESM and isolatedModules: true', () => {
23+
const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm.spec.ts'], {
24+
nodeOptions: '--experimental-vm-modules --no-warnings',
3325
})
26+
const { summary } = extractSummary(stderr)
27+
28+
expect(wrap(summary)).toMatchSnapshot()
29+
expect(stdout).toBe('')
30+
expect(exitCode).toBe(0)
3431
})
3532

36-
// The versions where Top-Level Await is supported
37-
onNodeVersions('>=14.3.0', () => {
38-
test('supports top-level await and isolatedModules: false', () => {
39-
const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm-tla.spec.ts'], {
40-
nodeOptions: '--experimental-vm-modules --no-warnings',
41-
})
42-
const { summary } = extractSummary(stderr)
43-
44-
expect(wrap(summary)).toMatchSnapshot()
45-
expect(stdout).toBe('')
46-
expect(exitCode).toBe(0)
33+
test('supports top-level await and isolatedModules: false', () => {
34+
const { exitCode, stderr, stdout } = runJest(DIR, ['native-esm-tla.spec.ts'], {
35+
nodeOptions: '--experimental-vm-modules --no-warnings',
4736
})
37+
const { summary } = extractSummary(stderr)
4838

49-
test('supports top-level await and isolatedModules: true', () => {
50-
const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm-tla.spec.ts'], {
51-
nodeOptions: '--experimental-vm-modules --no-warnings',
52-
})
53-
const { summary } = extractSummary(stderr)
39+
expect(wrap(summary)).toMatchSnapshot()
40+
expect(stdout).toBe('')
41+
expect(exitCode).toBe(0)
42+
})
5443

55-
expect(wrap(summary)).toMatchSnapshot()
56-
expect(stdout).toBe('')
57-
expect(exitCode).toBe(0)
44+
test('supports top-level await and isolatedModules: true', () => {
45+
const { exitCode, stderr, stdout } = runJest(ISOLATED_MODULES_DIR, ['native-esm-tla.spec.ts'], {
46+
nodeOptions: '--experimental-vm-modules --no-warnings',
5847
})
48+
const { summary } = extractSummary(stderr)
49+
50+
expect(wrap(summary)).toMatchSnapshot()
51+
expect(stdout).toBe('')
52+
expect(exitCode).toBe(0)
5953
})

e2e/__tests__/native-esm-ts.test.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { onNodeVersions, json as runWithJson } from '../run-jest'
1+
import { json as runWithJson } from '../run-jest'
22

3-
// The versions where vm.Module exists and commonjs with "exports" is not broken
4-
onNodeVersions('>=14.15.0', () => {
5-
test('runs TS test with native ESM', () => {
6-
const { exitCode, json } = runWithJson('native-esm-ts', [], {
7-
nodeOptions: '--experimental-vm-modules --no-warnings',
8-
})
9-
10-
expect(exitCode).toBe(0)
11-
expect(json.numTotalTests).toBe(4)
12-
expect(json.numPassedTests).toBe(4)
3+
test('runs TS test with native ESM', () => {
4+
const { exitCode, json } = runWithJson('native-esm-ts', [], {
5+
nodeOptions: '--experimental-vm-modules --no-warnings',
136
})
7+
8+
expect(exitCode).toBe(0)
9+
expect(json.numTotalTests).toBe(4)
10+
expect(json.numPassedTests).toBe(4)
1411
})

e2e/run-jest.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as path from 'path'
33
import type { FormattedTestResults } from '@jest/test-result'
44
import execa from 'execa'
55
import * as fs from 'graceful-fs'
6-
import semver from 'semver'
76
import stripAnsi from 'strip-ansi'
87

98
import { normalizeIcons } from './utils'
@@ -116,18 +115,3 @@ export const json = function (dir: string, args?: string[], options: RunJestOpti
116115
)
117116
}
118117
}
119-
120-
export const onNodeVersions = (versionRange: string, testBody: () => void): void => {
121-
const description = `on node ${versionRange}`
122-
if (semver.satisfies(process.versions.node, versionRange)) {
123-
// eslint-disable-next-line jest/valid-title
124-
describe(description, () => {
125-
testBody()
126-
})
127-
} else {
128-
// eslint-disable-next-line jest/valid-title,jest/no-disabled-tests
129-
describe.skip(description, () => {
130-
testBody()
131-
})
132-
}
133-
}

0 commit comments

Comments
 (0)