Skip to content

Commit 0d4d36b

Browse files
committed
feat: run Node.js ESM tests on commit
1 parent 33e9c66 commit 0d4d36b

20 files changed

+123
-88
lines changed

.eslintignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
.DS_Store
2+
13
node_modules
4+
coverage
25
lib
36
es
47
es-legacy
8+
umd
59
tslib
10+
tses
611
public
7-
coverage
8-
.DS_Store
12+
913
.vscode
1014
*.md

.github/workflows/reusable-test.yml

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ on:
1616
default: false
1717

1818
jobs:
19-
node-modules-cache:
19+
# This job is used to cache node_modules and build output
20+
# 1. Install latest dependencies
21+
# 2. Cache node_modules
22+
# 3. Build package
23+
# 4. Cache build output
24+
install-and-build:
2025
if: ${{ inputs.use-matrix == true }}
2126
runs-on: ubuntu-latest
2227
steps:
@@ -63,29 +68,6 @@ jobs:
6368
name: modern-node-modules-${{ hashFiles('**/package-lock.json') }}
6469
path: node_modules
6570

66-
# This job is used to run tests on modern Node.js versions
67-
# 1. Use default Node.js
68-
# 2. Install latest dependencies
69-
# 3. Cache node_modules
70-
build-modern-node:
71-
if: ${{ inputs.use-matrix == true }}
72-
runs-on: ubuntu-latest
73-
needs: node-modules-cache
74-
steps:
75-
- uses: actions/checkout@v4
76-
77-
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
78-
uses: actions/setup-node@v4
79-
with:
80-
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
81-
82-
- name: Restore modern node_modules cache
83-
id: node_modules_cache
84-
uses: actions/cache@v4
85-
with:
86-
path: node_modules
87-
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
88-
8971
- name: Build package
9072
run: npm run build
9173

@@ -94,6 +76,7 @@ jobs:
9476
with:
9577
path: |
9678
tslib
79+
tses
9780
lib
9881
es
9982
es-legacy
@@ -106,12 +89,12 @@ jobs:
10689
name: ${{ runner.os }}-modern-build-output-${{ github.sha }}
10790
path: |
10891
tslib
92+
tses
10993
lib
11094
es
11195
es-legacy
11296
umd
113-
114-
build-legacy-node:
97+
node-modules-legacy-cache:
11598
if: ${{ inputs.use-matrix == true }}
11699
runs-on: ubuntu-latest
117100
steps:
@@ -137,14 +120,37 @@ jobs:
137120
if: steps.node_modules_cache.outputs.cache-hit != 'true'
138121
run: npm install --legacy-peer-deps --ignore-scripts --no-package-lock
139122

140-
# Run tests on multiple matrix Node.js versions
141-
run-jest-lib-modern:
123+
# Run ts-tests on default Node.js version
124+
run-jest-ts:
142125
if: ${{ inputs.use-matrix == true }}
143126
runs-on: ubuntu-latest
144-
needs: build-modern-node
127+
needs: install-and-build
128+
steps:
129+
- uses: actions/checkout@v4
130+
131+
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
132+
uses: actions/setup-node@v4
133+
with:
134+
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
135+
136+
- name: Restore modern node_modules cache
137+
uses: actions/cache@v4
138+
with:
139+
path: |
140+
node_modules
141+
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
142+
143+
- name: Run jest tests from source codes
144+
run: npm test
145+
146+
# Run Node.js CJS unit tests on multiple modern node versions
147+
run-jest-cjs:
148+
if: ${{ inputs.use-matrix == true }}
149+
runs-on: ubuntu-latest
150+
needs: install-and-build
145151
strategy:
146152
matrix:
147-
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x]
153+
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x, 24.x]
148154
steps:
149155
- uses: actions/checkout@v4
150156

@@ -165,20 +171,21 @@ jobs:
165171
with:
166172
path: |
167173
tslib
174+
tses
168175
lib
169176
es
170177
es-legacy
171178
umd
172179
key: ${{ runner.os }}-modern-build-output-${{ github.sha }}
173180

174-
- name: Run jest tests from lib directory
175-
run: npm run task:jest:lib
181+
- name: Run jest tests from tslib directory
182+
run: npm run task:jest-cjs
176183

177-
# Run legacy tests on multiple matrix Node.js versions
178-
run-jest-lib-legacy:
184+
# Run CJS unit tests on multiple legacy node versions
185+
run-jest-cjs-legacy:
179186
if: ${{ inputs.use-matrix == true }}
180187
runs-on: ubuntu-latest
181-
needs: [build-modern-node, build-legacy-node]
188+
needs: [install-and-build, node-modules-legacy-cache]
182189
strategy:
183190
matrix:
184191
node-version: [7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x]
@@ -202,27 +209,31 @@ jobs:
202209
with:
203210
path: |
204211
tslib
212+
tses
205213
lib
206214
es
207215
es-legacy
208216
umd
209217
key: ${{ runner.os }}-modern-build-output-${{ github.sha }}
210218

211-
- name: Run jest tests from lib directory
212-
run: npm run task:jest:lib
219+
- name: Run jest tests from tslib directory
220+
run: npm run task:jest-cjs
213221

214-
# Run ts-tests on default Node.js version
215-
run-jest-ts:
222+
# Run ESM unit tests on node versions that support Node.js ESM
223+
run-jest-esm:
216224
if: ${{ inputs.use-matrix == true }}
217225
runs-on: ubuntu-latest
218-
needs: build-modern-node
226+
needs: install-and-build
227+
strategy:
228+
matrix:
229+
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x, 24.x]
219230
steps:
220231
- uses: actions/checkout@v4
221232

222-
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
233+
- name: Use Node.js ${{ matrix.node-version }}
223234
uses: actions/setup-node@v4
224235
with:
225-
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
236+
node-version: ${{ matrix.node-version }}
226237

227238
- name: Restore modern node_modules cache
228239
uses: actions/cache@v4
@@ -231,13 +242,25 @@ jobs:
231242
node_modules
232243
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
233244

234-
- name: Run jest tests from source codes
235-
run: npm test
245+
- name: Restore modern build output cache
246+
uses: actions/cache@v4
247+
with:
248+
path: |
249+
tslib
250+
tses
251+
lib
252+
es
253+
es-legacy
254+
umd
255+
key: ${{ runner.os }}-modern-build-output-${{ github.sha }}
256+
257+
- name: Run jest tests from tses directory
258+
run: npm run task:jest-esm
236259

237-
run-e2e-tests:
260+
# Run e2e tests
261+
run-e2e:
238262
if: ${{ inputs.use-matrix == true }}
239263
runs-on: ubuntu-latest
240-
# needs: build-modern-node
241264
steps:
242265
- uses: actions/checkout@v4
243266

@@ -273,7 +296,7 @@ jobs:
273296
name: ${{ runner.os }}-modern-build-output-${{ github.sha }}
274297

275298
- name: Build package
276-
# if: steps.download_build_output.outcome != 'success'
299+
if: steps.download_build_output.outcome != 'success'
277300
run: npm run build
278301

279302
- name: Run e2e tests

.prettierignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
.DS_Store
2+
coverage
3+
14
node_modules
25
lib
36
es
47
es-legacy
8+
umd
59
tslib
10+
tses
611
public
7-
coverage
8-
.DS_Store
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ const config = {
55
testEnvironment: 'node',
66
testMatch: ['<rootDir>/tslib/test/**/*.{spec,test}.js'],
77
collectCoverage: true,
8-
collectCoverageFrom: ['<rootDir>/tslib/src/**/*.js'],
8+
collectCoverageFrom: ['<rootDir>/lib/**/*.js'],
99
coverageReporters: ['json', 'lcov', 'text', 'clover'],
10-
coveragePathIgnorePatterns: ['<rootDir>/tslib/src/types.js', '<rootDir>/tslib/src/localize-interface.js'],
10+
coveragePathIgnorePatterns: ['<rootDir>/lib/types.js', '<rootDir>/lib/localize-interface.js'],
11+
moduleNameMapper: {
12+
'^@enum-plus/(.*)$': '<rootDir>/lib/$1',
13+
'^@enum-plus': '<rootDir>/lib/index.js',
14+
},
1115
coverageThreshold: {
1216
global: {
1317
branches: 100,
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
const nodeVersion = process.versions.node.split('.').map(Number)[0];
2-
31
/** @type {import('jest').Config} */
42
const config = {
53
testEnvironment: 'node',
64
extensionsToTreatAsEsm: ['.ts'],
75
testMatch: ['<rootDir>/tses/test/**/*.{spec,test}.js'],
86
collectCoverage: true,
9-
collectCoverageFrom: ['<rootDir>/tses/src/**/*.js'],
7+
collectCoverageFrom: ['<rootDir>/es/**/*.js'],
108
coverageReporters: ['json', 'lcov', 'text', 'clover'],
119
coveragePathIgnorePatterns: ['<rootDir>/es/types.js', '<rootDir>/es/localize-interface.js'],
10+
setupFilesAfterEnv: ['<rootDir>/tses/test/jest.setup.js'],
11+
moduleNameMapper: {
12+
'^@enum-plus/(.*)$': '<rootDir>/es/$1',
13+
'^@enum-plus': '<rootDir>/es/index.js',
14+
},
1215
transform: {
1316
'^.+\\.(ts|js)$': ['ts-jest', { useESM: true }],
1417
},
@@ -21,11 +24,5 @@ const config = {
2124
},
2225
},
2326
};
24-
if (nodeVersion <= 15) {
25-
// @ts-expect-error: because setupTestFrameworkScriptFile is a deprecated API
26-
config.setupTestFrameworkScriptFile = '<rootDir>/tses/test/jest.setup.js';
27-
} else {
28-
config.setupFilesAfterEnv = ['<rootDir>/tses/test/jest.setup.js'];
29-
}
3027

31-
export default config;
28+
module.exports = config;

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module.exports = {
88
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
99
coverageReporters: ['json', 'lcov', 'text', 'clover'],
1010
coveragePathIgnorePatterns: ['src/types.ts', 'src/localize-interface.ts', 'src/extension.d.ts'],
11+
moduleNameMapper: {
12+
'^@enum-plus/(.*)$': '<rootDir>/src/$1',
13+
'^@enum-plus': '<rootDir>/src',
14+
},
1115
coverageThreshold: {
1216
global: {
1317
branches: 100,

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"build:es": "run-s task:build-es task:add-umd-banner task:add-es-extensions",
9191
"build:es-legacy": "cross-env LEGACY=1 run-s task:build-es-legacy task:add-umd-banner task:add-es-legacy-extensions",
9292
"build:lib": "run-s ts2lib task:copy-dts task:copy-lib",
93+
"build:tses": "run-s ts2es task:add-tses-extensions",
9394
"e2e": "run-s task:bundle-e2e task:run-e2e",
9495
"e2e:debug": "run-s task:bundle-e2e task:run-e2e-debug",
9596
"e2e:ui": "run-s task:bundle-e2e task:run-e2e-ui",
@@ -106,19 +107,14 @@
106107
"task:copy-dts": "shx cp ./src/*.d.ts ./lib",
107108
"task:copy-lib": "tsx scripts/copy-lib.ts",
108109
"task:jest": "jest --coverage",
109-
"task:jest:es": "jest --coverage -c jest-es.config.js",
110-
"task:jest:lib": "jest --coverage -c jest-lib.config.js",
110+
"task:jest-cjs": "jest --coverage -c jest-cjs.config.js",
111+
"task:jest-esm": "jest --coverage -c jest-esm.config.js",
111112
"task:run-e2e": "playwright test",
112113
"task:run-e2e-debug": "playwright test --debug",
113114
"task:run-e2e-ui": "playwright test --ui",
114-
"task:run-e2e:chrome": "playwright test --project=chrome",
115-
"task:run-e2e:chromium-legacy": "playwright test --project=chromium-legacy",
116-
"task:run-e2e:edge": "playwright test --project=edge",
117-
"task:run-e2e:firefox": "playwright test --project=firefox",
118-
"task:run-e2e:webkit": "playwright test --project=webkit",
119115
"test": "npm run task:jest",
120-
"test-node-cjs": "run-s ts2lib task:jest:lib",
121-
"test-node-esm": "run-s ts2es task:add-tses-extensions task:jest:es",
116+
"test-node-cjs": "run-s ts2lib task:jest-cjs",
117+
"test-node-esm": "run-s build:tses task:jest-esm",
122118
"ts2es": "tsc -p tsconfig.es.json",
123119
"ts2lib": "tsc -p tsconfig.lib.json"
124120
},

test/data/week-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { defaultLocalize as defaultLocalizeType, Enum as EnumType } from '../../src/index';
1+
import type { defaultLocalize as defaultLocalizeType, Enum as EnumType } from '@enum-plus';
22

33
export const localeEN = {
44
'weekDay.name': 'Week Days',

test/engines/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type * as EnumPlusNamespace from '../../src/index';
1+
import type * as EnumPlusNamespace from '@enum-plus';
22
import type * as WeekConfigNamespace from '../data/week-config';
33
import type * as WeekDataNamespace from '../data/week-data';
44
import type * as SerializeJavascriptNamespace from '../utils/serialize-javascript';

test/engines/jest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as EnumPlus from '../../src/index';
1+
import * as EnumPlus from '@enum-plus';
22
import * as WeekConfig from '../data/week-config';
33
import * as WeekData from '../data/week-data';
44
import * as SerializeJavascript from '../utils/serialize-javascript';

0 commit comments

Comments
 (0)