Skip to content

Commit 7c9d94a

Browse files
committed
Add Playwright e2e tests
1 parent 67df411 commit 7c9d94a

File tree

12 files changed

+193
-292
lines changed

12 files changed

+193
-292
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ jobs:
1919
- uses: ./.github/actions/install-dependencies
2020
- name: Run the linter
2121
run: pnpm lint
22+
test-e2e:
23+
needs:
24+
- install-dependencies
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
- uses: ./.github/actions/install-dependencies
29+
- run: pnpm build:core
30+
- run: pnpm build:shims
31+
- run: pnpm build:banner
32+
- run: pnpm playwright install --with-deps
33+
- run: pnpm -r test
2234
test-unit:
2335
needs:
2436
- install-dependencies
@@ -29,7 +41,7 @@ jobs:
2941
- run: pnpm build:core
3042
- run: pnpm build:shims
3143
- run: pnpm build:banner
32-
- run: pnpm test
44+
- run: pnpm test:build
3345
typecheck:
3446
needs:
3547
- install-dependencies

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
*.log
22
.DS_Store
3+
.cache
4+
/*.tgz
5+
blob-report
36
dist
47
node_modules
5-
package.tgz
8+
playwright-report
9+
test-results
10+
tmp

examples/vanilla/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Test</title>
6+
<title>Example (Vanilla)</title>
77
</head>
88
<body>
99
<script type="module" src="/src/main.ts"></script>

examples/vanilla/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
"scripts": {
55
"build": "vite build",
66
"dev": "vite",
7+
"test": "CI=true run-p test:build test:dev",
8+
"test:build": "VITE_COMMAND=build WEB_SERVER_COMMAND='vite build && vite preview --port 5174' WEB_SERVER_URL='http://localhost:5174' playwright test",
9+
"test:dev": "VITE_COMMAND=dev WEB_SERVER_COMMAND='vite dev' WEB_SERVER_URL='http://localhost:5173' playwright test",
710
"typecheck": "tsc"
811
},
912
"devDependencies": {
13+
"@types/lodash-es": "^4.17.12",
1014
"@types/node": "^18.18.8",
1115
"lodash-es": "^4.17.21",
1216
"memfs": "^4.6.0",
17+
"npm-run-all": "^4.1.5",
1318
"ohmyfetch": "^0.4.21",
1419
"typescript": "^5.2.2",
1520
"vite": "^4.5.0",

examples/vanilla/playwright.config.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
const webServerCommand = process.env.WEB_SERVER_COMMAND || 'pnpm dev'
4+
const webServerUrl = process.env.WEB_SERVER_URL || 'http://localhost:5173'
5+
6+
// https://playwright.dev/docs/test-configuration
7+
export default defineConfig({
8+
forbidOnly: !!process.env.CI,
9+
fullyParallel: true,
10+
projects: [
11+
{
12+
name: 'chromium',
13+
use: { ...devices['Desktop Chrome'] },
14+
},
15+
],
16+
reporter: 'html',
17+
retries: process.env.CI ? 2 : 0,
18+
testDir: './test/e2e',
19+
use: {
20+
baseURL: webServerUrl,
21+
trace: 'on-first-retry',
22+
},
23+
webServer: {
24+
command: webServerCommand,
25+
stdout: 'ignore',
26+
url: webServerUrl,
27+
},
28+
workers: process.env.CI ? 1 : undefined,
29+
})

examples/vanilla/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ console.log(resolve('.'))
2222
console.log(process)
2323
console.log(process.env)
2424
console.log(globalThis.Array)
25-
console.log(Buffer.from([0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF]).readBigUInt64BE(0))
25+
console.log(Buffer.from([0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF]).readBigUInt64BE(0).toString())
2626
console.log(Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]))
2727
console.log(Array)
2828
console.log(readFileSync('./test.txt', 'utf-8'))
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { expect, test } from '@playwright/test'
2+
import { isBuild, isDev } from '/test/utils'
3+
4+
test('sets the page title', async ({ page }) => {
5+
await page.goto('/')
6+
7+
await expect(page).toHaveTitle('Example (Vanilla)')
8+
})
9+
10+
test('logs the correct values', async ({ page }) => {
11+
const errors = []
12+
const logs = []
13+
14+
page.on('console', (message) => {
15+
logs.push(message.text())
16+
})
17+
18+
page.on('pageerror', (error) => {
19+
errors.push(error.message)
20+
})
21+
22+
await page.goto('/')
23+
24+
expect(errors).toEqual([])
25+
26+
if (isBuild) {
27+
expect(logs).toEqual([
28+
'{Volume: , vol: Volume, createFsFromVolume: , fs: Object, memfs: }',
29+
'function fetch() { [native code] }',
30+
'/',
31+
'Module',
32+
'{}',
33+
'function Array() { [native code] }',
34+
'4294967295',
35+
'Uint8Array(6)',
36+
'function Array() { [native code] }',
37+
'Hello from fs!',
38+
'{some: true, else: 1, inner: Object}',
39+
])
40+
}
41+
42+
if (isDev) {
43+
expect(logs).toEqual([
44+
'[vite] connecting...',
45+
'[vite] connected.',
46+
'{Volume: , vol: _Volume, createFsFromVolume: , fs: Object, memfs: }',
47+
'function fetch() { [native code] }',
48+
'/',
49+
'{nextTick: , title: browser, browser: true, env: Object, argv: Array(0)}',
50+
'{}',
51+
'function Array() { [native code] }',
52+
'4294967295',
53+
'Uint8Array(6)',
54+
'function Array() { [native code] }',
55+
'Hello from fs!',
56+
'{some: true, else: 1, inner: Object}',
57+
])
58+
}
59+
})

examples/vanilla/test/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isBuild = process.env.VITE_COMMAND === 'build'
2+
export const isDev = process.env.VITE_COMMAND === 'dev'

examples/vanilla/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"compilerOptions": {
3+
"baseUrl": ".",
34
"module": "ESNext",
45
"moduleResolution": "Bundler",
56
"noEmit": true,
7+
"paths": {
8+
"/*": ["./*"]
9+
},
610
"skipLibCheck": true
711
}
812
}

examples/vanilla/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills'
44

55
// https://vitejs.dev/config/
66
export default defineConfig({
7+
build: {
8+
minify: false,
9+
},
710
plugins: [
811
nodePolyfills({
912
globals: {

0 commit comments

Comments
 (0)