Skip to content

Commit

Permalink
ci: skip ts esm testing on node 20
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Dec 2, 2023
1 parent c4890a0 commit 1ba441a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ jobs:

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

- name: Codecov
uses: codecov/codecov-action@v3
if: ${{ matrix.node != 20 }}
10 changes: 7 additions & 3 deletions test/fn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path'

import { jest } from '@jest/globals'

import { _dirname } from './helpers.js'
import { _dirname, testIf, tsUseEsmSupported } from './helpers.js'
import type { AsyncWorkerFn } from './types.js'

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

test('ts as esm', () => {
testIf(tsUseEsmSupported)('ts as esm', () => {
const syncFn = createSyncFn<AsyncWorkerFn>(workerEsmTsPath)
/* eslint-disable jest/no-standalone-expect */
expect(syncFn(1)).toBe(1)
expect(syncFn(2)).toBe(2)
expect(syncFn(5)).toBe(5)
/* eslint-enable jest/no-standalone-expect */
})

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

test('js as ts (as esm)', () => {
testIf(tsUseEsmSupported)('js as ts (as esm)', () => {
const syncFn = createSyncFn<AsyncWorkerFn>(workerJsAsTsPath)
/* eslint-disable jest/no-standalone-expect */
expect(syncFn(1)).toBe(1)
expect(syncFn(2)).toBe(2)
expect(syncFn(5)).toBe(5)
/* eslint-enable jest/no-standalone-expect */
})

test('createSyncFn', () => {
Expand Down
11 changes: 11 additions & 0 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import { MTS_SUPPORTED_NODE_VERSION } from 'synckit'

export const _dirname = path.dirname(fileURLToPath(import.meta.url))

export const nodeVersion = Number.parseFloat(process.versions.node)

export const tsUseEsmSupported =
nodeVersion >= MTS_SUPPORTED_NODE_VERSION &&
// ts-jest limitation
nodeVersion < 20

export const testIf = (condition: boolean) => (condition ? it : it.skip)
47 changes: 30 additions & 17 deletions test/ts-runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'node:path'

import { jest } from '@jest/globals'

import { _dirname } from './helpers.js'
import { _dirname, nodeVersion, tsUseEsmSupported } from './helpers.js'
import type { AsyncWorkerFn } from './types.js'

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

expect(() =>
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.EsbuildRegister,
}),
).toThrow('esbuild-register is not supported for .mts files yet')
if (tsUseEsmSupported) {
// eslint-disable-next-line jest/no-conditional-expect
expect(() =>
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.EsbuildRegister,
}),
).toThrow('esbuild-register is not supported for .mts files yet')
}
})

test(TsRunner.EsbuildRunner, async () => {
Expand All @@ -58,11 +61,14 @@ test(TsRunner.EsbuildRunner, async () => {
expect(syncFn(2)).toBe(2)
expect(syncFn(5)).toBe(5)

expect(() =>
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.EsbuildRunner,
}),
).toThrow('esbuild-runner is not supported for .mts files yet')
if (tsUseEsmSupported) {
// eslint-disable-next-line jest/no-conditional-expect
expect(() =>
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.EsbuildRunner,
}),
).toThrow('esbuild-runner is not supported for .mts files yet')
}
})

test(TsRunner.SWC, async () => {
Expand All @@ -82,11 +88,14 @@ test(TsRunner.SWC, async () => {
expect(syncFn(2)).toBe(2)
expect(syncFn(5)).toBe(5)

expect(() =>
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.SWC,
}),
).toThrow('swc is not supported for .mts files yet')
if (tsUseEsmSupported) {
// eslint-disable-next-line jest/no-conditional-expect
expect(() =>
createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.SWC,
}),
).toThrow('swc is not supported for .mts files yet')
}
})

test(TsRunner.TSX, async () => {
Expand All @@ -99,7 +108,7 @@ test(TsRunner.TSX, async () => {
expect(syncFn(2)).toBe(2)
expect(syncFn(5)).toBe(5)

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

if (!tsUseEsmSupported) {
return
}

syncFn = createSyncFn<AsyncWorkerFn>(workerMtsPath, {
tsRunner: TsRunner.TSX,
})
Expand Down

0 comments on commit 1ba441a

Please sign in to comment.