diff --git a/.github/hub-checks/.gitignore b/.github/hub-checks/.gitignore new file mode 100644 index 0000000..ae2f532 --- /dev/null +++ b/.github/hub-checks/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +test-results/ diff --git a/.github/hub-checks/hub.spec.mjs b/.github/hub-checks/hub.spec.mjs new file mode 100644 index 0000000..aa7b162 --- /dev/null +++ b/.github/hub-checks/hub.spec.mjs @@ -0,0 +1,86 @@ +import { fileURLToPath } from 'node:url'; +import { expect, test } from '@playwright/test'; + +const appNames = ['AllAboard', 'AllHail', 'OverBoard', 'OverHeard']; +const custom404 = fileURLToPath(new URL('../../404.html', import.meta.url)); + +test.beforeEach(async ({ context, baseURL }) => { + await context.route('**/*', route => + new URL(route.request().url()).origin === baseURL ? route.continue() : route.abort() + ); +}); + +test('the homepage displays the app cards and remembers the theme', async ({ page }) => { + const errors = []; + page.on('pageerror', error => errors.push(error.message)); + await page.goto('/'); + await expect(page.getByRole('heading', { level: 1 })).toBeVisible(); + await expect(page.locator('link[rel="stylesheet"][href$="style.css"]')).toHaveCount(1); + for (const name of appNames) { + await expect(page.getByRole('heading', { name, exact: true })).toBeVisible(); + } + + await page.getByRole('button', { name: 'Switch to dark mode' }).click(); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark'); + await page.reload(); + await expect(page.getByRole('button', { name: 'Switch to light mode' })).toBeVisible(); + expect(errors).toEqual([]); +}); + +test('the homepage fits a phone viewport', async ({ page }) => { + await page.setViewportSize({ width: 375, height: 812 }); + await page.goto('/'); + await expect(page.getByRole('heading', { level: 1 })).toBeVisible(); + const overflows = await page.locator('body').evaluate(body => + body.scrollWidth > document.documentElement.clientWidth + ); + expect(overflows).toBe(false); +}); + +test('hub pages and their local links and assets resolve', async ({ page }) => { + const links = new Set(); + for (const path of ['/', '/privacy.html', '/terms.html', '/404.html']) { + const response = await page.goto(path); + expect(response.status(), path).toBe(200); + await expect(page.getByRole('heading', { level: 1 })).toBeVisible(); + const pageLinks = await page.locator('a[href], link[href], script[src], img[src]').evaluateAll(elements => + elements.map(element => { + const url = new URL(element.getAttribute('href') ?? element.getAttribute('src'), document.baseURI); + url.hash = ''; + return url.origin === window.location.origin ? url.href : null; + }).filter(Boolean) + ); + for (const url of pageLinks) links.add(url); + } + + for (const url of links) { + const response = await page.request.head(url); + await expect(response, url).toBeOK(); + } +}); + +const roomOrigin = 'https://over-heard-606573080592.us-east1.run.app'; +const shortcuts = [ + ['/chefbot/', '/ChefBot/'], + ['/cHeFbOt', '/ChefBot/'], + ['/AlLaBoArD/', 'https://allaboard-606573080592.us-east1.run.app/'], + ['/OvErBoArD/', 'https://bpmdata.github.io/OverBoard/app/'], + ['/OvErHeArD/', roomOrigin + '/'], + ['/Physics-42/', roomOrigin + '/physics-42'], +]; + +for (const [shortcut, target] of shortcuts) { + test(`the 404 page routes ${shortcut}`, async ({ page, baseURL }) => { + const destination = new URL(target, baseURL); + // GitHub Pages serves this file at the missing URL. Stub the destination so + // a linked app's availability cannot affect the test. + await page.route(url => url.pathname === shortcut, route => + route.fulfill({ status: 404, path: custom404 }) + ); + await page.route(url => url.origin === destination.origin && url.pathname === destination.pathname, route => + route.fulfill({ contentType: 'text/html', body: 'Destination' }) + ); + await page.goto(shortcut + '?source=test#section'); + await expect(page).toHaveURL(destination.href + '?source=test#section'); + }); +} diff --git a/.github/hub-checks/package-lock.json b/.github/hub-checks/package-lock.json new file mode 100644 index 0000000..abe020d --- /dev/null +++ b/.github/hub-checks/package-lock.json @@ -0,0 +1,58 @@ +{ + "name": "bpmdata-hub-checks", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "bpmdata-hub-checks", + "devDependencies": { + "@playwright/test": "1.63.0" + } + }, + "node_modules/@playwright/test": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.63.0.tgz", + "integrity": "sha512-oxMK4vllB9RK5NQ2l1pq1IfOf2AvnEuj/vYGDj0H2nMtmtZpKtCwt/l00GEO6xjGfpBNAvjovvYdCm50dRQkpQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.63.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.63.0.tgz", + "integrity": "sha512-+7ziBLidS4NaNCdt57SUDT+wYmmd5fmiQejUic/kb+YsYSCPyOOE9sebzMjNmQrsnNpDJqd4WHvV/8lfKfUDUg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.63.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.63.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz", + "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/.github/hub-checks/package.json b/.github/hub-checks/package.json new file mode 100644 index 0000000..db66980 --- /dev/null +++ b/.github/hub-checks/package.json @@ -0,0 +1,10 @@ +{ + "name": "bpmdata-hub-checks", + "private": true, + "scripts": { + "test": "playwright test" + }, + "devDependencies": { + "@playwright/test": "1.63.0" + } +} diff --git a/.github/hub-checks/playwright.config.mjs b/.github/hub-checks/playwright.config.mjs new file mode 100644 index 0000000..329a33c --- /dev/null +++ b/.github/hub-checks/playwright.config.mjs @@ -0,0 +1,12 @@ +import { defineConfig } from '@playwright/test'; + +const baseURL = 'http://127.0.0.1:4173'; + +export default defineConfig({ + testDir: '.', + use: { baseURL, colorScheme: 'light' }, + webServer: { + command: 'python3 -m http.server 4173 --bind 127.0.0.1 --directory ../..', + url: baseURL, + }, +}); diff --git a/.github/workflows/hub-checks.yml b/.github/workflows/hub-checks.yml new file mode 100644 index 0000000..d5c6110 --- /dev/null +++ b/.github/workflows/hub-checks.yml @@ -0,0 +1,30 @@ +name: Hub checks + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + check: + name: Check hub + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: .github/hub-checks + steps: + - uses: actions/checkout@v6 + with: + persist-credentials: false + - uses: actions/setup-node@v6 + with: + node-version: "22" + cache: npm + cache-dependency-path: .github/hub-checks/package-lock.json + - run: npm ci + - run: npx playwright install --with-deps --only-shell chromium + - run: npm test diff --git a/README.md b/README.md index c4a0e27..a3d0d7a 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,18 @@ Also here: the icon generator script there, rebuild, and copy the new files here. Plain HTML and CSS; no build step. `.nojekyll` turns off GitHub's Jekyll processing. + +## Hub checks + +GitHub Actions checks pull requests and pushes to `main`. It opens a local copy in Chromium, checks +the homepage, theme toggle, policy pages, and local links and assets, and exercises app shortcuts +and an OverHeard room redirect. The checks use stub pages for the linked services. + +To run the checks locally with Node.js 22 and Python 3: + +```sh +cd .github/hub-checks +npm ci +npx playwright install --only-shell chromium +npm test +```