From 1ba441ac9de778875587947faa2ddb5f15543d8d Mon Sep 17 00:00:00 2001 From: JounQin Date: Sat, 2 Dec 2023 10:28:50 +0800 Subject: [PATCH] ci: skip ts esm testing on node 20 --- .github/workflows/ci.yml | 3 ++- test/fn.spec.ts | 10 ++++++--- test/helpers.ts | 11 ++++++++++ test/ts-runner.spec.ts | 47 +++++++++++++++++++++++++--------------- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bdd03cf5d..39c2dc6e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} diff --git a/test/fn.spec.ts b/test/fn.spec.ts index a7de2fa53..70b857598 100644 --- a/test/fn.spec.ts +++ b/test/fn.spec.ts @@ -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' @@ -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(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)', () => { @@ -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(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', () => { diff --git a/test/helpers.ts b/test/helpers.ts index 2ee292b32..ac197def9 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -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) diff --git a/test/ts-runner.spec.ts b/test/ts-runner.spec.ts index c849ae416..cdb6601a8 100644 --- a/test/ts-runner.spec.ts +++ b/test/ts-runner.spec.ts @@ -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' @@ -34,11 +34,14 @@ test(TsRunner.EsbuildRegister, async () => { expect(syncFn(2)).toBe(2) expect(syncFn(5)).toBe(5) - expect(() => - createSyncFn(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(workerMtsPath, { + tsRunner: TsRunner.EsbuildRegister, + }), + ).toThrow('esbuild-register is not supported for .mts files yet') + } }) test(TsRunner.EsbuildRunner, async () => { @@ -58,11 +61,14 @@ test(TsRunner.EsbuildRunner, async () => { expect(syncFn(2)).toBe(2) expect(syncFn(5)).toBe(5) - expect(() => - createSyncFn(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(workerMtsPath, { + tsRunner: TsRunner.EsbuildRunner, + }), + ).toThrow('esbuild-runner is not supported for .mts files yet') + } }) test(TsRunner.SWC, async () => { @@ -82,11 +88,14 @@ test(TsRunner.SWC, async () => { expect(syncFn(2)).toBe(2) expect(syncFn(5)).toBe(5) - expect(() => - createSyncFn(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(workerMtsPath, { + tsRunner: TsRunner.SWC, + }), + ).toThrow('swc is not supported for .mts files yet') + } }) test(TsRunner.TSX, async () => { @@ -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(workerMtsPath, { @@ -109,6 +118,10 @@ test(TsRunner.TSX, async () => { return } + if (!tsUseEsmSupported) { + return + } + syncFn = createSyncFn(workerMtsPath, { tsRunner: TsRunner.TSX, })