Skip to content

Commit 843900e

Browse files
ci(github): add workflow e2e.yml and run multiple browser tests
1 parent d30c67f commit 843900e

File tree

8 files changed

+58
-20
lines changed

8 files changed

+58
-20
lines changed

.github/workflows/e2e.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: e2e
2+
on: [push, pull_request]
3+
4+
permissions:
5+
contents: read
6+
7+
jobs:
8+
e2e:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
browser: [chromium, firefox, webkit]
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v6
17+
18+
- name: Use Node.js
19+
uses: actions/setup-node@v6
20+
with:
21+
cache: npm
22+
node-version-file: .nvmrc
23+
24+
- name: Install dependencies
25+
run: npm ci --prefer-offline
26+
27+
- name: Install Playwright browsers
28+
run: npx playwright install ${{ matrix.browser }}
29+
30+
- name: Run browser tests on Chrome
31+
run: vitest run --config vitest.browser.config.mts --browser=${{ matrix.browser }}

.github/workflows/test.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,3 @@ jobs:
3030

3131
- name: Run module tests
3232
run: npm run test:esm
33-
34-
- name: Install Playwright browsers
35-
run: npx playwright install chromium
36-
37-
- name: Run browser tests
38-
run: npm run test:browser

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"prepublishOnly": "run-s build lint lint:tsc lint:package",
4747
"size-limit": "size-limit",
4848
"test": "vitest",
49-
"test:browser": "vitest run --config vitest.browser.config.mts",
49+
"test:browser": "vitest run --config vitest.browser.config.mts --browser=chromium",
5050
"test:coverage": "vitest run --color --coverage",
5151
"test:esm": "npm run build:esm && node --test test/esm"
5252
},

test/cases/html.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { isNode } from '../helpers';
2+
13
export default [
24
// html tags
35
{
@@ -225,7 +227,7 @@ export default [
225227
data: '<noscript><p>JS is disabled</p></noscript>',
226228
get skip() {
227229
// jsdom template renders noscript children as text instead of nodes
228-
return typeof process !== 'undefined';
230+
return isNode();
229231
},
230232
},
231233

test/client/index.test.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import htmlToDOM from '../../src/client/html-to-dom';
33
import htmlCases from '../cases/html';
44
import {
5+
isBrowser,
56
parseDOM,
67
runTests,
78
testCaseSensitiveTags,
@@ -15,16 +16,18 @@ describe('client parser', () => {
1516
runTests(htmlToDOM, parseDOM, htmlCases);
1617
testCaseSensitiveTags(htmlToDOM);
1718

18-
describe('performance', () => {
19-
it('executes 1000 times in less than 50ms', () => {
20-
let times = 1000;
21-
const start = performance.now();
22-
while (--times) {
23-
htmlToDOM('<div>test</div>');
24-
}
25-
const end = performance.now();
26-
const elapsed = end - start;
27-
expect(elapsed).below(50);
19+
if (isBrowser()) {
20+
describe('performance', () => {
21+
it('executes 1000 times in less than 50ms', () => {
22+
let times = 1000;
23+
const start = performance.now();
24+
while (--times) {
25+
htmlToDOM('<div>test</div>');
26+
}
27+
const end = performance.now();
28+
const elapsed = end - start;
29+
expect(elapsed).below(50);
30+
});
2831
});
29-
});
32+
}
3033
});

test/helpers/environment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const isBrowser = () => typeof window === 'object' && !isNode();
2+
3+
export const isNode = () => typeof process === 'object';

test/helpers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { isBrowser, isNode } from './environment';
12
export { parseDOM } from './parse-dom';
23
export { runTests } from './run-tests';
34
export { testCaseSensitiveTags } from './test-case-sensitive-tags';

vitest.browser.config.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export default mergeConfig(
1212
enabled: true,
1313
provider: playwright(),
1414
headless: true,
15-
instances: [{ browser: 'chromium' }],
15+
instances: [
16+
{ browser: 'chromium' },
17+
{ browser: 'firefox' },
18+
{ browser: 'webkit' },
19+
],
1620
},
1721
include: ['test/client/**'],
1822
},

0 commit comments

Comments
 (0)