Skip to content

Commit 222d1cc

Browse files
committed
test: use playwright instead of testcafe
1 parent b73cdd6 commit 222d1cc

File tree

7 files changed

+128
-62
lines changed

7 files changed

+128
-62
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,11 @@ jobs:
201201
browsers:
202202
needs:
203203
- build
204-
runs-on: ${{ matrix.runs-on || 'ubuntu-latest' }}
204+
runs-on: macos-latest
205205
strategy:
206206
fail-fast: false
207207
matrix:
208-
browser:
209-
- name: chrome
210-
id: chrome:headless
211-
- name: firefox
212-
id: firefox:headless
213-
- name: edge
214-
id: edge:headless
215-
include:
216-
- runs-on: macos-15
217-
browser:
218-
name: safari
219-
id: safari
208+
browser: [chromium, firefox, safari]
220209
steps:
221210
- name: Checkout
222211
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -226,21 +215,26 @@ jobs:
226215
node-version: lts/*
227216
cache: 'npm'
228217
- run: npm clean-install
229-
- run: npm install --global testcafe@3
230-
- name: Add rows to the TCC.db
231-
if: ${{ matrix.runs-on == 'macos-15' }}
232-
run: |
233-
sudo sqlite3 "$HOME/Library/Application Support/com.apple.TCC/TCC.db" "INSERT OR REPLACE INTO access VALUES('kTCCServiceAppleEvents','com.devexpress.testcafe-browser-tools',0,2,3,1,X'fade0c0000000068000000010000000700000007000000080000001443fa4ca5141baeda21aeca1f50894673b440d4690000000800000014f8afcf6e69791b283e55bd0b03e39e422745770e0000000800000014bf4fc1aed64c871a49fc6bc9dd3878ce5d4d17c6',NULL,0,'com.apple.Safari',X'fade0c000000002c00000001000000060000000200000010636f6d2e6170706c652e53616661726900000003',NULL,1687952810,NULL,NULL,'UNUSED',1687952810);"
234-
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "INSERT OR REPLACE INTO access VALUES('kTCCServiceScreenCapture','com.devexpress.testcafe-browser-tools',0,2,3,1,X'fade0c0000000068000000010000000700000007000000080000001443fa4ca5141baeda21aeca1f50894673b440d4690000000800000014f8afcf6e69791b283e55bd0b03e39e422745770e0000000800000014bf4fc1aed64c871a49fc6bc9dd3878ce5d4d17c6',NULL,0,'UNUSED',NULL,0,1687952810,NULL,NULL,'UNUSED',1687952810);"
218+
- run: npm upgrade playwright
219+
- name: get playwright version
220+
id: playwright-version
221+
run:
222+
echo "version=$(npm list playwright --json | jq -r '.dependencies["@playwright/test"].dependencies.playwright.version')" >>
223+
$GITHUB_OUTPUT
224+
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
225+
with:
226+
path: ~/Library/Caches/ms-playwright
227+
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
228+
- run: npx playwright install --only-shell chromium firefox webkit
235229
- name: Run Test Suite
236230
run: npm run tap:browsers
237231
env:
238-
BROWSER: ${{ matrix.browser.id }}
232+
BROWSER: ${{ matrix.browser }}
239233
- name: Upload server logs
240234
if: ${{ failure() }}
241235
id: artifact-upload-step
242236
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
243237
with:
244238
path: server.log
245-
name: ${{ matrix.browser.name }} server log
239+
name: ${{ matrix.browser }} server log
246240
if-no-files-found: warn

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,4 @@ tap/run-*.cjs
135135
tap/.workerd.capnp
136136
tap/.workers.capnp
137137
submissions
138+
test-results/.last-run.json

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
},
7777
"devDependencies": {
7878
"@koa/cors": "^5.0.0",
79+
"@playwright/test": "^1.58.2",
7980
"@types/koa__cors": "^5.0.1",
8081
"@types/node": "^24.12.0",
8182
"@types/qunit": "^2.19.13",

playwright.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
export default defineConfig({
4+
testDir: './tap',
5+
testMatch: '.browser.ts',
6+
timeout: 120_000,
7+
projects: [
8+
{ name: 'chromium', use: devices['Desktop Chrome'] },
9+
{ name: 'firefox', use: devices['Desktop Firefox'] },
10+
{ name: 'safari', use: devices['Desktop Safari'] },
11+
],
12+
})

tap/.browser.ts

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
1-
import { t, ClientFunction } from 'testcafe'
2-
import * as fs from 'node:fs'
3-
4-
const script = fs.readFileSync('./tap/run-browser.js', { encoding: 'utf-8' })
5-
6-
fixture('test suite').page('https://important-clam-66.deno.dev')
7-
8-
test('passes tests', async (user) => {
9-
await ClientFunction(
10-
() => {
11-
function escapeHTML(str: string) {
12-
return str
13-
.replace(/&/g, '&')
14-
.replace(/</g, '&lt;')
15-
.replace(/>/g, '&gt;')
16-
.replace(/"/g, '&quot;')
17-
.replace(/'/g, '&#39;')
18-
}
19-
// @ts-expect-error
20-
document.getElementById('js').innerHTML = escapeHTML(innerHTML)
21-
document.querySelector('form')?.submit()
22-
},
23-
{ dependencies: { innerHTML: script } },
24-
)()
25-
26-
let i = 0
27-
const interval = setInterval(() => {
28-
t.getBrowserConsoleMessages().then(({ log: messages }) => {
29-
messages.forEach((message, index) => {
30-
if (i && index <= i) return
31-
i++
32-
console.log(message)
33-
})
34-
})
35-
}, 100)
1+
import { test, expect } from '@playwright/test'
2+
import { createServer } from 'node:http'
3+
import { readFileSync } from 'node:fs'
4+
5+
const script = readFileSync('./tap/run-browser.js', 'utf-8')
6+
7+
test('passes tests', async ({ page }) => {
8+
const server = createServer((req, res) => {
9+
if (req.url === '/run-browser.js') {
10+
res.writeHead(200, { 'Content-Type': 'application/javascript' })
11+
res.end(script)
12+
} else {
13+
res.writeHead(200, { 'Content-Type': 'text/html' })
14+
res.end(
15+
'<!DOCTYPE html><html><head></head><body><script type="module" src="/run-browser.js"></script></body></html>',
16+
)
17+
}
18+
})
19+
20+
await new Promise<void>((resolve) => server.listen(0, resolve))
21+
const port = (server.address() as import('node:net').AddressInfo).port
22+
23+
page.on('console', (msg) => {
24+
if (msg.type() === 'log') {
25+
console.log(msg.text())
26+
}
27+
})
28+
29+
await page.goto(`http://localhost:${port}`)
3630

3731
let stats
3832
do {
39-
await new Promise((resolve) => setTimeout(resolve, 1000))
40-
stats = await t.eval(() => globalThis.stats)
33+
await page.waitForTimeout(1000)
34+
stats = await page.evaluate(() => (globalThis as any).stats)
4135
} while (!stats)
4236

43-
clearInterval(interval)
37+
server.close()
4438

45-
await t.expect(stats?.failed).eql(0)
39+
expect(stats.failed).toBe(0)
4640
})

tap/.browsers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
--outfile=tap/run-browser.js \
1212
tap/run-browser.ts
1313

14-
: "${BROWSER:=chrome:headless}"
14+
: "${BROWSER:=chromium}"
1515

16-
testcafe "$BROWSER" --hostname localhost tap/.browser.ts
16+
npx playwright test --project="$BROWSER"

0 commit comments

Comments
 (0)