Skip to content

Commit c2891d5

Browse files
committed
ci: improve e2e tests
1 parent 3634c9c commit c2891d5

File tree

7 files changed

+101
-27
lines changed

7 files changed

+101
-27
lines changed

.github/workflows/reusable-test.yml

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ jobs:
4040
if: steps.node_modules_cache.outputs.cache-hit != 'true'
4141
run: npm ci
4242

43+
- name: Check if artifact exists
44+
id: check_node_modules_artifact
45+
run: |
46+
ARTIFACT_NAME="modern-node-modules-${{ hashFiles('**/package-lock.json') }}"
47+
ARTIFACT_EXISTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
48+
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts" | \
49+
jq --arg name "$ARTIFACT_NAME" '.artifacts[] | select(.name == $name) | .id' | wc -l)
50+
51+
echo "artifact_exists=$ARTIFACT_EXISTS" >> $GITHUB_ENV
52+
53+
if [ "$ARTIFACT_EXISTS" -gt "0" ]; then
54+
echo "artifact_exists=true" >> $GITHUB_OUTPUT
55+
else
56+
echo "artifact_exists=false" >> $GITHUB_OUTPUT
57+
fi
58+
59+
- name: Upload node_modules to artifacts
60+
if: steps.check_node_modules_artifact.outputs.artifact_exists == 'false'
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: modern-node-modules-${{ hashFiles('**/package-lock.json') }}
64+
path: node_modules
65+
4366
# This job is used to run tests on modern Node.js versions
4467
# 1. Use default Node.js
4568
# 2. Install latest dependencies
@@ -77,6 +100,17 @@ jobs:
77100
umd
78101
key: ${{ runner.os }}-modern-build-output-${{ github.sha }}
79102

103+
- name: Upload build output to artifacts
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: ${{ runner.os }}-modern-build-output-${{ github.sha }}
107+
path: |
108+
tslib
109+
lib
110+
es
111+
es-legacy
112+
umd
113+
80114
build-legacy-node:
81115
if: ${{ inputs.use-matrix == true }}
82116
runs-on: ubuntu-latest
@@ -203,11 +237,15 @@ jobs:
203237
run-e2e-tests:
204238
if: ${{ inputs.use-matrix == true }}
205239
runs-on: ubuntu-latest
240+
# needs: build-modern-node
206241
# Use Playwright container for E2E tests, which has all dependencies and all browsers installed
207-
container: mcr.microsoft.com/playwright:v1.52.0-jammy
208-
env:
209-
# fix Firefox permission issue (Firefox is unable to launch if the $HOME folder isn't owned by the current user)
210-
HOME: /root
242+
# container: mcr.microsoft.com/playwright:v1.52.0-jammy
243+
# env:
244+
# # fix Firefox permission issue (Firefox is unable to launch if the $HOME folder isn't owned by the current user)
245+
# HOME: /root
246+
# strategy:
247+
# matrix:
248+
# browser: [chrome, firefox, webkit, edge]
211249
steps:
212250
- uses: actions/checkout@v4
213251

@@ -216,16 +254,36 @@ jobs:
216254
with:
217255
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
218256
cache: 'npm'
219-
cache-dependency-path: '**/package-lock.json'
257+
258+
- name: Install Playwright dependencies
259+
run: npx playwright install-deps webkit
260+
261+
# - name: Restore modern node_modules cache
262+
# uses: actions/cache@v4
263+
# with:
264+
# path: |
265+
# node_modules
266+
# key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
220267

221268
- name: Install dependencies
222269
run: npm ci
223270

271+
- name: Install playwright browsers
272+
run: npx playwright install
273+
274+
# - name: Download build output from artifacts
275+
# id: download_build_output
276+
# uses: actions/download-artifact@v4
277+
# continue-on-error: true
278+
# with:
279+
# name: ${{ runner.os }}-modern-build-output-${{ github.sha }}
280+
224281
- name: Build package
282+
# if: steps.download_build_output.outcome != 'success'
225283
run: npm run build
226284

227285
- name: Run e2e tests
228-
run: npm run e2e
286+
run: npm run task:run-e2e
229287

230288
# Run tests on single specified Node.js version
231289
run-jest-single:

.github/workflows/test-on-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
test:
1919
uses: ./.github/workflows/reusable-test.yml
2020
with:
21-
use-matrix: false
21+
use-matrix: true

e2e/fixtures/EnumPage.ts

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ export default class EnumPage {
44
constructor(public readonly page: Page) {}
55

66
async gotoModern() {
7-
await this.page.goto('/modern.html');
7+
await this.page.goto('/modern.html', { waitUntil: 'domcontentloaded' });
88
}
99
async gotoLegacy() {
10-
await this.page.goto('/legacy.html');
10+
await this.page.goto('/legacy.html', { waitUntil: 'domcontentloaded' });
1111
}
1212
async setupLang() {
13+
await this.page.waitForLoadState('domcontentloaded');
1314
await this.page.evaluate(() => {
1415
const {
1516
EnumPlus: { Enum, defaultLocalize },
@@ -20,6 +21,7 @@ export default class EnumPage {
2021
});
2122
}
2223
async resetLang() {
24+
await this.page.waitForLoadState('domcontentloaded');
2325
await this.page.evaluate(() => {
2426
const {
2527
EnumPlus: { Enum },

e2e/fixtures/EnumTest.ts

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export const test = base.extend<{
99
enumPage: async ({ page }, use) => {
1010
const enumPage = new EnumPage(page);
1111
await enumPage.gotoModern();
12-
12+
// delay to ensure the page is fully loaded
13+
await page.waitForLoadState('domcontentloaded');
1314
await use(enumPage);
1415
},
1516
});

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "enum-plus",
3-
"version": "3.0.0-alpha.2",
3+
"version": "3.0.0-alpha.1",
44
"description": "A drop-in replacement for native enum. Like native enum but much better!",
55
"keywords": [
66
"enum",
@@ -107,6 +107,11 @@
107107
"task:run-e2e": "playwright test",
108108
"task:run-e2e-debug": "playwright test --debug",
109109
"task:run-e2e-ui": "playwright test --ui",
110+
"task:run-e2e:chrome": "playwright test --project=chrome",
111+
"task:run-e2e:chromium-legacy": "playwright test --project=chromium-legacy",
112+
"task:run-e2e:edge": "playwright test --project=edge",
113+
"task:run-e2e:firefox": "playwright test --project=firefox",
114+
"task:run-e2e:webkit": "playwright test --project=webkit",
110115
"test": "npm run task:jest",
111116
"test-lib": "run-s ts2lib task:jest:lib",
112117
"ts2lib": "tsc -p tsconfig.lib.json"

playwright.config.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,58 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { devices } from '@playwright/test';
33

4-
// todo: 支持legacy浏览器的测试
4+
const port = 7080;
5+
56
const config: PlaywrightTestConfig = {
67
testDir: './e2e/specs',
78
testMatch: '**/*.spec.ts',
89
outputDir: './e2e/test-results',
910
globalSetup: require.resolve('./e2e/global.setup.ts'),
1011
globalTeardown: require.resolve('./e2e/global.teardown.ts'),
11-
workers: 16,
1212
forbidOnly: !!process.env.CI,
1313
retries: 2,
1414
use: {
15-
baseURL: 'http://localhost:7080',
15+
baseURL: `http://localhost:${port}`,
1616
headless: true,
1717
},
1818
projects: [
1919
// Modern browsers
2020
{
21-
name: 'chromium',
21+
name: 'chrome',
2222
use: devices['Desktop Chrome'],
23+
workers: 1,
2324
},
2425
{
2526
name: 'firefox',
2627
use: devices['Desktop Firefox'],
28+
workers: 1,
2729
},
2830
{
2931
name: 'webkit',
3032
use: devices['Desktop Safari'],
33+
workers: 1,
3134
},
32-
// Legacy browsers (simulated)
3335
{
34-
name: 'chromium-legacy',
35-
use: {
36-
browserName: 'chromium',
37-
// Use specific flags to simulate legacy browser behavior
38-
launchOptions: {
39-
args: ['--js-flags=--noturbo'],
40-
},
41-
},
36+
name: 'edge',
37+
use: devices['Desktop Edge'],
38+
workers: 1,
4239
},
40+
// Legacy browsers (simulated)
41+
// {
42+
// name: 'chromium-legacy',
43+
// use: {
44+
// browserName: 'chromium',
45+
// // Use specific flags to simulate legacy browser behavior
46+
// launchOptions: {
47+
// args: ['--js-flags=--noturbo'],
48+
// },
49+
// },
50+
// },
4351
],
4452
webServer: {
45-
command: 'npx http-server ./e2e/fixtures -p 7080',
53+
command: `npx http-server ./e2e/fixtures -p ${port}`,
4654
port: 7080,
47-
reuseExistingServer: !process.env.CI,
55+
reuseExistingServer: false,
4856
},
4957
};
5058

test/engines/playwright.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class PlaywrightEngine extends TestEngineBase {
3030
WeekData,
3131
SerializeJavascript,
3232
};
33-
console.log('window', runtimeContext);
33+
// console.log('window', runtimeContext);
3434
const { serializeJavascript: serialize, deserializeJavascript: deserialize } = SerializeJavascript;
3535
const args = deserialize(contextStr) as { evaluateFn: typeof evaluate };
3636
const { evaluateFn, ...rest } = args;

0 commit comments

Comments
 (0)