Skip to content

Commit 1ba441a

Browse files
committed
ci: skip ts esm testing on node 20
1 parent c4890a0 commit 1ba441a

File tree

4 files changed

+50
-21
lines changed

4 files changed

+50
-21
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939

4040
- name: Benchmark
4141
run: yarn benchmark
42-
continue-on-error: ${{ matrix.os == 'windows-latest' }}
42+
continue-on-error: ${{ matrix.node == 20 }}
4343

4444
- name: Codecov
4545
uses: codecov/codecov-action@v3
46+
if: ${{ matrix.node != 20 }}

test/fn.spec.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path'
33

44
import { jest } from '@jest/globals'
55

6-
import { _dirname } from './helpers.js'
6+
import { _dirname, testIf, tsUseEsmSupported } from './helpers.js'
77
import type { AsyncWorkerFn } from './types.js'
88

99
import { createSyncFn, extractProperties } from 'synckit'
@@ -32,11 +32,13 @@ test('ts as cjs', () => {
3232
expect(syncFn(5)).toBe(5)
3333
})
3434

35-
test('ts as esm', () => {
35+
testIf(tsUseEsmSupported)('ts as esm', () => {
3636
const syncFn = createSyncFn<AsyncWorkerFn>(workerEsmTsPath)
37+
/* eslint-disable jest/no-standalone-expect */
3738
expect(syncFn(1)).toBe(1)
3839
expect(syncFn(2)).toBe(2)
3940
expect(syncFn(5)).toBe(5)
41+
/* eslint-enable jest/no-standalone-expect */
4042
})
4143

4244
test('no ext as js (as esm)', () => {
@@ -46,11 +48,13 @@ test('no ext as js (as esm)', () => {
4648
expect(syncFn(5)).toBe(5)
4749
})
4850

49-
test('js as ts (as esm)', () => {
51+
testIf(tsUseEsmSupported)('js as ts (as esm)', () => {
5052
const syncFn = createSyncFn<AsyncWorkerFn>(workerJsAsTsPath)
53+
/* eslint-disable jest/no-standalone-expect */
5154
expect(syncFn(1)).toBe(1)
5255
expect(syncFn(2)).toBe(2)
5356
expect(syncFn(5)).toBe(5)
57+
/* eslint-enable jest/no-standalone-expect */
5458
})
5559

5660
test('createSyncFn', () => {

test/helpers.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import path from 'node:path'
22
import { fileURLToPath } from 'node:url'
33

4+
import { MTS_SUPPORTED_NODE_VERSION } from 'synckit'
5+
46
export const _dirname = path.dirname(fileURLToPath(import.meta.url))
7+
8+
export const nodeVersion = Number.parseFloat(process.versions.node)
9+
10+
export const tsUseEsmSupported =
11+
nodeVersion >= MTS_SUPPORTED_NODE_VERSION &&
12+
// ts-jest limitation
13+
nodeVersion < 20
14+
15+
export const testIf = (condition: boolean) => (condition ? it : it.skip)

test/ts-runner.spec.ts

+30-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'node:path'
44

55
import { jest } from '@jest/globals'
66

7-
import { _dirname } from './helpers.js'
7+
import { _dirname, nodeVersion, tsUseEsmSupported } from './helpers.js'
88
import type { AsyncWorkerFn } from './types.js'
99

1010
import { MTS_SUPPORTED_NODE_VERSION, TsRunner } from 'synckit'
@@ -34,11 +34,14 @@ test(TsRunner.EsbuildRegister, async () => {
3434
expect(syncFn(2)).toBe(2)
3535
expect(syncFn(5)).toBe(5)
3636

37-
expect(() =>
38-
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
39-
tsRunner: TsRunner.EsbuildRegister,
40-
}),
41-
).toThrow('esbuild-register is not supported for .mts files yet')
37+
if (tsUseEsmSupported) {
38+
// eslint-disable-next-line jest/no-conditional-expect
39+
expect(() =>
40+
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
41+
tsRunner: TsRunner.EsbuildRegister,
42+
}),
43+
).toThrow('esbuild-register is not supported for .mts files yet')
44+
}
4245
})
4346

4447
test(TsRunner.EsbuildRunner, async () => {
@@ -58,11 +61,14 @@ test(TsRunner.EsbuildRunner, async () => {
5861
expect(syncFn(2)).toBe(2)
5962
expect(syncFn(5)).toBe(5)
6063

61-
expect(() =>
62-
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
63-
tsRunner: TsRunner.EsbuildRunner,
64-
}),
65-
).toThrow('esbuild-runner is not supported for .mts files yet')
64+
if (tsUseEsmSupported) {
65+
// eslint-disable-next-line jest/no-conditional-expect
66+
expect(() =>
67+
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
68+
tsRunner: TsRunner.EsbuildRunner,
69+
}),
70+
).toThrow('esbuild-runner is not supported for .mts files yet')
71+
}
6672
})
6773

6874
test(TsRunner.SWC, async () => {
@@ -82,11 +88,14 @@ test(TsRunner.SWC, async () => {
8288
expect(syncFn(2)).toBe(2)
8389
expect(syncFn(5)).toBe(5)
8490

85-
expect(() =>
86-
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
87-
tsRunner: TsRunner.SWC,
88-
}),
89-
).toThrow('swc is not supported for .mts files yet')
91+
if (tsUseEsmSupported) {
92+
// eslint-disable-next-line jest/no-conditional-expect
93+
expect(() =>
94+
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
95+
tsRunner: TsRunner.SWC,
96+
}),
97+
).toThrow('swc is not supported for .mts files yet')
98+
}
9099
})
91100

92101
test(TsRunner.TSX, async () => {
@@ -99,7 +108,7 @@ test(TsRunner.TSX, async () => {
99108
expect(syncFn(2)).toBe(2)
100109
expect(syncFn(5)).toBe(5)
101110

102-
if (Number.parseFloat(process.versions.node) < MTS_SUPPORTED_NODE_VERSION) {
111+
if (nodeVersion < MTS_SUPPORTED_NODE_VERSION) {
103112
// eslint-disable-next-line jest/no-conditional-expect
104113
expect(() =>
105114
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
@@ -109,6 +118,10 @@ test(TsRunner.TSX, async () => {
109118
return
110119
}
111120

121+
if (!tsUseEsmSupported) {
122+
return
123+
}
124+
112125
syncFn = createSyncFn<AsyncWorkerFn>(workerMtsPath, {
113126
tsRunner: TsRunner.TSX,
114127
})

0 commit comments

Comments
 (0)