Skip to content

Commit 7ac283a

Browse files
committed
Add Playwright e2e smoke tests and CI workflow
Introduce a GitHub Actions test matrix (fast and full gates) to run CI test groups. Add a Playwright-based browser smoke test (test/e2e/ui-smoke.test.js) that launches the app and verifies basic UI flows. Update README with local instructions for running e2e (install browsers) and the ci:fast/ci:full command groups.
1 parent 4df89d3 commit 7ac283a

4 files changed

Lines changed: 170 additions & 0 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: TinyNode Test Matrix
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
fast:
14+
name: Fast Test Gate
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "24"
24+
cache: "npm"
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Run fast suites
30+
run: npm run ci:fast
31+
32+
full:
33+
name: Full Test Gate
34+
needs: fast
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: "24"
44+
cache: "npm"
45+
46+
- name: Install dependencies
47+
run: npm ci
48+
49+
- name: Install Playwright browser
50+
run: npm run e2e:install
51+
52+
- name: Run full suite and coverage
53+
run: npm run ci:full

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ npm run existsTests
4848
npm run functionalTests
4949
```
5050

51+
Run browser smoke tests (optional for local development):
52+
```shell
53+
npm run e2e:install
54+
npm run E2Etests
55+
```
56+
57+
Run the CI-equivalent command groups locally:
58+
```shell
59+
npm run ci:fast
60+
npm run ci:full
61+
```
62+
5163
And start the app
5264
```shell
5365
npm start

package-lock.json

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

test/e2e/ui-smoke.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import "../helpers/env.js"
2+
import assert from "node:assert/strict"
3+
import { after, before, describe, it } from "node:test"
4+
import http from "node:http"
5+
import { chromium } from "playwright"
6+
import app from "../../app.js"
7+
8+
let server
9+
let baseUrl
10+
11+
before(async () => {
12+
server = http.createServer(app)
13+
await new Promise(resolve => {
14+
server.listen(0, "127.0.0.1", resolve)
15+
})
16+
const address = server.address()
17+
baseUrl = `http://127.0.0.1:${address.port}`
18+
})
19+
20+
after(async () => {
21+
if (!server) return
22+
await new Promise(resolve => {
23+
server.close(() => resolve())
24+
})
25+
})
26+
27+
describe("TinyNode browser smoke checks. __e2e", () => {
28+
it("Loads index page and toggles forms from the button panel. __e2e", async t => {
29+
let browser
30+
try {
31+
browser = await chromium.launch({ headless: true })
32+
}
33+
catch (error) {
34+
t.skip(`Chromium is not installed. Run 'npm run e2e:install'. ${error.message}`)
35+
return
36+
}
37+
38+
try {
39+
const page = await browser.newPage()
40+
await page.goto(`${baseUrl}/index.html`, { waitUntil: "domcontentloaded" })
41+
await page.waitForSelector(".button-panel")
42+
43+
const title = await page.title()
44+
assert.match(title, /Tiny Things by Rerum/i)
45+
46+
const createIsVisibleByDefault = await page.locator("form#create:not([data-hidden])").count()
47+
assert.equal(createIsVisibleByDefault, 1)
48+
49+
await page.click('.button-panel > button[data-lang-key="updateBtn"]')
50+
const updateVisible = await page.locator("form#rerumUpdate:not([data-hidden])").count()
51+
const createHidden = await page.locator('form#create[data-hidden="true"]').count()
52+
53+
assert.equal(updateVisible, 1)
54+
assert.equal(createHidden, 1)
55+
}
56+
finally {
57+
await browser.close()
58+
}
59+
})
60+
})

0 commit comments

Comments
 (0)