Skip to content

Commit af904f8

Browse files
committed
ci: update CI workflows to enable e2e tests
1 parent 6e506dc commit af904f8

12 files changed

+114
-89
lines changed

.github/workflows/npm-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
- name: Build package
3131
run: npm run build
3232

33-
- name: Run jest tests
34-
run: npm run jest
33+
- name: Run tests
34+
run: npm test
3535

3636
- name: Upload coverage reports to Codecov
3737
uses: codecov/codecov-action@v5

.github/workflows/reusable-test.yml

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ jobs:
3232
- name: Install dependencies
3333
run: npm ci
3434

35-
- name: Run tests
35+
- name: Run modern jest tests
3636
run: npm run task:jest
3737

38-
# Run legacy tests on multiple matrix Node.js versions
39-
run-tests-legacy-node13:
38+
# Run tests on multiple matrix Node.js versions
39+
run-tests-modern-nodes:
4040
if: ${{ inputs.use-matrix == true }}
4141
runs-on: ubuntu-latest
42-
needs: build-node13
42+
needs: build-modern
4343
strategy:
4444
matrix:
45-
node-version: [7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x]
45+
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x]
4646
steps:
4747
- uses: actions/checkout@v4
4848

@@ -51,27 +51,53 @@ jobs:
5151
with:
5252
path: |
5353
node_modules
54-
tslib
55-
key: ${{ runner.os }}-build-node13-${{ github.sha }}
56-
restore-keys: |
57-
${{ runner.os }}-build-node13-
54+
key: ${{ runner.os }}-build-modern-${{ github.sha }}
5855

5956
- name: Use Node.js ${{ matrix.node-version }}
6057
uses: actions/setup-node@v4
6158
with:
6259
node-version: ${{ matrix.node-version }}
6360

64-
- name: Build typescript to tslib
65-
run: npm run ts2lib
61+
- name: Run modern jest tests
62+
run: npm run task:jest
6663

67-
- name: Run tests
68-
run: npm run task:jest:legacy
64+
# Run e2e tests
65+
run-e2e-tests:
66+
if: ${{ inputs.use-matrix == true }}
67+
runs-on: ubuntu-latest
68+
needs: build-modern
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Restore cache
73+
uses: actions/cache@v4
74+
with:
75+
path: |
76+
node_modules
77+
key: ${{ runner.os }}-build-modern-${{ github.sha }}
78+
79+
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
80+
uses: actions/setup-node@v4
81+
with:
82+
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
83+
84+
- name: Install Playwright dependencies
85+
run: npx playwright install-deps webkit
86+
87+
- name: Install playwright browsers
88+
run: npx playwright install
89+
90+
- name: Build package
91+
run: npm run build
92+
93+
- name: Run e2e tests
94+
run: npm run e2e
6995

7096
# Run legacy tests on multiple matrix Node.js versions
71-
run-tests-legacy-node15:
97+
run-tests-legacy-node14-15:
7298
if: ${{ inputs.use-matrix == true }}
7399
runs-on: ubuntu-latest
74-
needs: build-node15
100+
needs: build-node14-15
75101
strategy:
76102
matrix:
77103
node-version: [14.x, 15.x]
@@ -84,29 +110,25 @@ jobs:
84110
path: |
85111
node_modules
86112
tslib
87-
key: ${{ runner.os }}-build-node15-${{ github.sha }}
88-
restore-keys: |
89-
${{ runner.os }}-build-node15-
113+
lib
114+
key: ${{ runner.os }}-build-node14-15-${{ github.sha }}
90115

91116
- name: Use Node.js ${{ matrix.node-version }}
92117
uses: actions/setup-node@v4
93118
with:
94119
node-version: ${{ matrix.node-version }}
95120

96-
- name: Build typescript to tslib
97-
run: npm run ts2lib
98-
99-
- name: Run tests
121+
- name: Run legacy jest tests
100122
run: npm run task:jest:legacy
101123

102-
# Run tests on multiple matrix Node.js versions
103-
run-tests-modern-nodes:
124+
# Run legacy tests on multiple matrix Node.js versions
125+
run-tests-legacy-node7-13:
104126
if: ${{ inputs.use-matrix == true }}
105127
runs-on: ubuntu-latest
106-
needs: build-modern
128+
needs: build-node7-13
107129
strategy:
108130
matrix:
109-
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x]
131+
node-version: [7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x]
110132
steps:
111133
- uses: actions/checkout@v4
112134

@@ -115,24 +137,24 @@ jobs:
115137
with:
116138
path: |
117139
node_modules
118-
key: ${{ runner.os }}-build-modern-${{ github.sha }}
119-
restore-keys: |
120-
${{ runner.os }}-build-modern-
140+
tslib
141+
lib
142+
key: ${{ runner.os }}-build-node7-13-${{ github.sha }}
121143

122144
- name: Use Node.js ${{ matrix.node-version }}
123145
uses: actions/setup-node@v4
124146
with:
125147
node-version: ${{ matrix.node-version }}
126148

127-
- name: Run tests
128-
run: npm run task:jest
149+
- name: Run legacy jest tests
150+
run: npm run task:jest:legacy
129151

130152
# This job is used to run tests on legacy Node.js versions
131153
# 1. Use default Node.js
132154
# 2. Install older versions of jest and ts-jest
133155
# 3. Build the project
134156
# 4. Cache node_modules and tslib
135-
build-node13:
157+
build-node7-13:
136158
if: ${{ inputs.use-matrix == true }}
137159
runs-on: ubuntu-latest
138160
steps:
@@ -145,12 +167,12 @@ jobs:
145167
cache: 'npm'
146168

147169
- name: Downgrade legacy dependencies
148-
run: npm run prepare-legacy-node13
170+
run: npm run prepare-legacy-node7-13
149171

150172
- name: Install dependencies
151173
run: npm install --legacy-peer-deps --ignore-scripts --no-package-lock
152174

153-
- name: Build
175+
- name: Build lib
154176
run: npm run build:lib
155177

156178
- name: Cache build output
@@ -159,16 +181,15 @@ jobs:
159181
path: |
160182
node_modules
161183
tslib
162-
key: ${{ runner.os }}-build-node13-${{ github.sha }}
163-
restore-keys: |
164-
${{ runner.os }}-build-node13-
184+
lib
185+
key: ${{ runner.os }}-build-node7-13-${{ github.sha }}
165186

166187
# This job is used to run tests on legacy Node.js versions
167188
# 1. Use default Node.js
168189
# 2. Install older versions of jest and ts-jest
169190
# 3. Build the project
170191
# 4. Cache node_modules and tslib
171-
build-node15:
192+
build-node14-15:
172193
if: ${{ inputs.use-matrix == true }}
173194
runs-on: ubuntu-latest
174195
steps:
@@ -181,12 +202,12 @@ jobs:
181202
cache: 'npm'
182203

183204
- name: Downgrade legacy dependencies
184-
run: npm run prepare-legacy-node15
205+
run: npm run prepare-legacy-node14-15
185206

186207
- name: Install dependencies
187208
run: npm install --legacy-peer-deps --ignore-scripts --no-package-lock
188209

189-
- name: Build
210+
- name: Build lib
190211
run: npm run build:lib
191212

192213
- name: Cache build output
@@ -195,9 +216,8 @@ jobs:
195216
path: |
196217
node_modules
197218
tslib
198-
key: ${{ runner.os }}-build-node15-${{ github.sha }}
199-
restore-keys: |
200-
${{ runner.os }}-build-node15-
219+
lib
220+
key: ${{ runner.os }}-build-node14-15-${{ github.sha }}
201221

202222
# This job is used to run tests on modern Node.js versions
203223
# 1. Use default Node.js
@@ -224,5 +244,3 @@ jobs:
224244
path: |
225245
node_modules
226246
key: ${{ runner.os }}-build-modern-${{ github.sha }}
227-
restore-keys: |
228-
${{ runner.os }}-build-modern-

jest-legacy.config.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
'use strict';
22

3-
/** @type {import('ts-jest').JestConfigWithTsJest} */
4-
module.exports = {
5-
preset: 'ts-jest',
3+
const nodeVersion = process.versions.node.split('.').map(Number)[0];
4+
5+
/** @type {import('jest').Config} */
6+
const config = {
67
testEnvironment: 'node',
78
testMatch: ['<rootDir>/tslib/test/**/*.{spec,test}.js'],
8-
setupFilesAfterEnv: ['<rootDir>/tslib/test/jest.setup.js'],
99
collectCoverage: true,
1010
collectCoverageFrom: ['<rootDir>/lib/**/*.js'],
1111
coveragePathIgnorePatterns: ['<rootDir>/lib/types.js'],
1212
moduleNameMapper: {
13-
'^@enum-plus': '<rootDir>/lib',
1413
'^@enum-plus/(.*)$': '<rootDir>/lib/$1',
14+
'^@enum-plus': '<rootDir>/lib',
1515
},
1616
};
17+
if (nodeVersion < 14) {
18+
// @ts-expect-error: because setupTestFrameworkScriptFile is a deprecated API
19+
config.setupTestFrameworkScriptFile = '<rootDir>/tslib/test/jest.setup.js';
20+
} else {
21+
config.setupFilesAfterEnv = ['<rootDir>/tslib/test/jest.setup.js'];
22+
}
23+
24+
module.exports = config;

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
2727
coveragePathIgnorePatterns: ['src/types.ts', 'src/extension.d.ts'],
2828
moduleNameMapper: {
29-
'^@enum-plus': '<rootDir>/src',
3029
'^@enum-plus/(.*)$': '<rootDir>/src/$1',
30+
'^@enum-plus': '<rootDir>/src',
3131
},
3232
};

package-legacy-node13.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

package-legacy-node14-15.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"devDependencies": {
3+
"@playwright/test": "1.34.3",
4+
"@swc/core": "1.3.53",
5+
"@tiny-codes/code-style-all-in-one": "1.1.4",
6+
"@types/jest": "24.0.25",
7+
"cross-env": "5.2.1",
8+
"father": "4.5.2",
9+
"jest": "24.9.0",
10+
"npm-run-all": "4.1.5",
11+
"shx": "0.3.4",
12+
"tsx": "3.14.0",
13+
"typescript": "5.8.3"
14+
}
15+
}

package-legacy-node15.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

package-legacy-node7-13.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"devDependencies": {
3+
"@playwright/test": "1.34.3",
4+
"@swc/core": "1.3.53",
5+
"@tiny-codes/code-style-all-in-one": "1.1.4",
6+
"@types/jest": "24.0.25",
7+
"cross-env": "5.2.1",
8+
"father": "4.5.2",
9+
"jest": "23.6.0",
10+
"npm-run-all": "4.1.5",
11+
"shx": "0.3.4",
12+
"tsx": "3.14.0"
13+
}
14+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
"e2e:debug": "run-s task:bundle-e2e task:run-e2e-debug",
9595
"e2e:ui": "run-s task:bundle-e2e task:run-e2e-ui",
9696
"prepare": "husky",
97-
"prepare-legacy-node13": "node ./scripts/prepare-legacy.js node13",
98-
"prepare-legacy-node15": "node ./scripts/prepare-legacy.js node15",
97+
"prepare-legacy-node14-15": "node ./scripts/prepare-legacy.js node14-15",
98+
"prepare-legacy-node7-13": "node ./scripts/prepare-legacy.js node7-13",
9999
"prepublishOnly": "run-s build test",
100100
"task:add-umd-banner": "tsx scripts/add-umd-banner.ts",
101101
"task:build-es": "father build",

test/engines/playwright.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class PlaywrightEngine extends TestEngineBase {
6868
// eslint-disable-next-line @typescript-eslint/ban-types
6969
override expect<ActualType = unknown>(actual: ActualType): MakeMatchers<void, ActualType, {}> {
7070
// eslint-disable-next-line @typescript-eslint/ban-types
71-
return expect(actual) as MakeMatchers<void, ActualType, {}>;
71+
return expect(actual) as unknown as MakeMatchers<void, ActualType, {}>;
7272
}
7373
override describe(name: string, fn: () => void): void {
7474
test.describe(name, fn);

0 commit comments

Comments
 (0)