Skip to content

Commit

Permalink
test(e2e): remove onNodeVersions function
Browse files Browse the repository at this point in the history
Since we support only Node 16+, we can safely remove this function
  • Loading branch information
Anh Pham authored and ahnpnl committed Jan 19, 2024
1 parent 0861a66 commit 2d16f4a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 80 deletions.
8 changes: 4 additions & 4 deletions e2e/__tests__/__snapshots__/native-esm-js.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// 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
Time: <<REPLACED>>
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
Time: <<REPLACED>>
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
Time: <<REPLACED>>
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
Expand Down
17 changes: 7 additions & 10 deletions e2e/__tests__/extend-ts-jest.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
72 changes: 33 additions & 39 deletions e2e/__tests__/native-esm-js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
19 changes: 8 additions & 11 deletions e2e/__tests__/native-esm-ts.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
16 changes: 0 additions & 16 deletions e2e/run-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
})
}
}

0 comments on commit 2d16f4a

Please sign in to comment.