Skip to content

Commit 131b2ab

Browse files
committed
Refactor web-test-runner configuration to use ES module syntax, enhance timeout settings, and integrate visual regression plugin. Update GitHub Actions workflow to use specific versions for actions and streamline dependency installation, improving CI performance and compatibility.
1 parent dd67562 commit 131b2ab

File tree

2 files changed

+62
-84
lines changed

2 files changed

+62
-84
lines changed

.github/workflows/deployment.yml

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,41 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [ubuntu-22.04]
20+
os: [ubuntu-20.04]
2121
runs-on: ${{ matrix.os }}
2222
steps:
23-
- uses: actions/checkout@v4
24-
- uses: actions/setup-node@v3
23+
- uses: actions/checkout@v2
24+
- uses: actions/setup-node@v1
2525
with:
2626
node-version: 18
27-
cache: 'npm'
27+
- uses: microsoft/playwright-github-action@v1
28+
- uses: actions/cache@v3
29+
with:
30+
path: ~/.npm
31+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
32+
restore-keys: |
33+
${{ runner.os }}-node-
2834
- name: Install dependencies
29-
run: |
30-
npm install -g [email protected]
31-
if [ ! -f "package-lock.json" ]; then
32-
npm install
33-
else
34-
npm ci
35-
fi
36-
- name: Generate AMF models
37-
run: npm run prepare
38-
- name: Install Playwright browsers
39-
run: |
40-
npx playwright install --with-deps chromium firefox webkit
35+
run: npm ci
4136
- name: Run tests
4237
run: npm test
4338
test_win:
4439
name: "Windows"
4540
runs-on: windows-latest
4641
steps:
47-
- uses: actions/checkout@v4
48-
- uses: actions/setup-node@v3
42+
- uses: actions/checkout@v2
43+
- uses: actions/setup-node@v1
4944
with:
5045
node-version: 18
51-
cache: 'npm'
46+
- uses: microsoft/playwright-github-action@v1
47+
- uses: actions/cache@v3
48+
with:
49+
path: ~/.npm
50+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
51+
restore-keys: |
52+
${{ runner.os }}-node-
5253
- name: Install dependencies
53-
run: |
54-
npm install -g [email protected]
55-
if (!(Test-Path "package-lock.json")) {
56-
npm install
57-
} else {
58-
npm ci
59-
}
60-
- name: Generate AMF models
61-
run: npm run prepare
62-
- name: Install Playwright browsers
63-
run: |
64-
npx playwright install --with-deps chromium firefox webkit
54+
run: npm ci
6555
- name: Run tests
6656
run: npm test
6757
tag:
@@ -73,22 +63,20 @@ jobs:
7363
runs-on: ubuntu-latest
7464
steps:
7565
- name: Checkout code
76-
uses: actions/checkout@v4
66+
uses: actions/checkout@v2
7767
with:
7868
fetch-depth: 0
79-
- uses: actions/setup-node@v3
69+
- uses: actions/setup-node@v2
8070
with:
81-
node-version: '18'
71+
node-version: '16.x'
8272
registry-url: 'https://registry.npmjs.org'
83-
cache: 'npm'
84-
- name: Install dependencies
85-
run: |
86-
npm install -g [email protected]
87-
if [ ! -f "package-lock.json" ]; then
88-
npm install
89-
else
90-
npm ci
91-
fi
73+
- uses: actions/cache@v3
74+
with:
75+
path: ~/.npm
76+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
77+
restore-keys: |
78+
${{ runner.os }}-node-
79+
- run: npm install
9280
- name: Read version from package.json
9381
uses: culshaw/read-package-node-version-actions@v1
9482
id: package-node-version

web-test-runner.config.cjs

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,40 @@
1-
const { playwrightLauncher } = require('@web/test-runner-playwright');
1+
import { visualRegressionPlugin } from '@web/test-runner-visual-regression/plugin'
22

3-
module.exports = {
3+
export default {
44
files: 'test/**/*.test.js',
55
nodeResolve: true,
6-
coverage: true,
7-
browsers: [
8-
playwrightLauncher({ product: 'chromium' }),
9-
playwrightLauncher({ product: 'firefox' }),
10-
playwrightLauncher({ product: 'webkit' })
6+
middleware: [
7+
function rewriteBase(context, next) {
8+
if (context.url.indexOf('/base') === 0) {
9+
context.url = context.url.replace('/base', '')
10+
}
11+
return next()
12+
},
1113
],
14+
coverageConfig: {
15+
include: ['src/**.js'],
16+
},
1217
testFramework: {
1318
config: {
14-
timeout: '60000',
19+
timeout: 800000,
1520
},
1621
},
17-
browserStartTimeout: 60000,
18-
testsStartTimeout: 60000,
19-
testsFinishTimeout: 60000,
20-
coverageConfig: {
21-
include: ['src/**/*.js'],
22-
exclude: ['test/**/*.js', 'demo/**/*.js'],
23-
threshold: {
24-
statements: 80,
25-
branches: 80,
26-
functions: 80,
27-
lines: 80
28-
}
29-
},
30-
middleware: [
31-
function rewriteBase(context, next) {
32-
if (context.url.startsWith('/base/')) {
33-
context.url = context.url.replace('/base/', '/');
34-
}
35-
return next();
36-
}
22+
browserStartTimeout: 20000,
23+
testsStartTimeout: 20000,
24+
testsFinishTimeout: 800000,
25+
plugins: [
26+
visualRegressionPlugin({
27+
update: process.argv.includes('--update-visual-baseline'),
28+
diffOptions: {
29+
threshold: 1,
30+
},
31+
}),
3732
],
38-
testRunnerHtml: testFramework => `
39-
<html>
40-
<head>
41-
<script>
42-
window.process = { env: { NODE_ENV: "development" } };
43-
</script>
44-
</head>
45-
<body>
46-
<script type="module" src="${testFramework}"></script>
47-
</body>
48-
</html>
49-
`
50-
};
33+
testRunnerHtml: (testFramework) =>
34+
`<html>
35+
<body>
36+
<script src="./demo/vendor.js"></script>
37+
<script type="module" src="${testFramework}"></script>
38+
</body>
39+
</html>`,
40+
}

0 commit comments

Comments
 (0)