Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: actions/setup-node@v7.1.0
with:
node-version-file: .node-version
cache: npm
cache-dependency-path: e2e/package-lock.json
- run: scripts/e2e
env:
BUILD_SHA: ${{ github.event.pull_request.head.sha }}
E2E_BASE_REF: origin/${{ github.base_ref }}
- if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-${{ github.event.pull_request.head.sha }}
path: |
e2e/test-results/
e2e/playwright-report/
if-no-files-found: ignore
retention-days: 14
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ web/node_modules/
web/dist/
web/tsconfig.tsbuildinfo

# Browser tests
e2e/node_modules/
e2e/test-results/
e2e/playwright-report/

# Internal docs
plan.md
internal_docs/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ docker buildx build --platform linux/amd64 -t vimmary:local .
| `scripts/setup` | installs the toolchain (Go, golangci-lint, govulncheck, Node, npm dependencies); runs at session start |
| `scripts/test` | Go tests with the race detector, the storage and service tests against Postgres + pgvector (`TEST_DATABASE_URL`, or `compose.test.yaml`), the frontend tests |
| `scripts/lint` | gofmt, go vet, golangci-lint, govulncheck, the migration rules (`scripts/check-migrations.sh`), the script tests, the frontend type check and build |
| `scripts/e2e` | the built image with pgvector and the fixture data: `/version` and the loopback `/healthz` report the SHA, the API and the frontend answer; upgrade from the image of `main` and back |
| `scripts/e2e` | the built image with pgvector and the fixture data: `/version` and the loopback `/healthz` report the SHA, the API and the frontend answer, the Playwright tests in `e2e/` pass; upgrade from the image of `main` and back |

CI runs `test`, `lint` and `e2e` on the head commit of every pull request,
and `review` (Claude, rules in `REVIEW.md`); all four are required checks.
Expand Down
58 changes: 58 additions & 0 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "vimmary-e2e",
"private": true,
"type": "module",
"scripts": {
"test": "playwright test"
},
"devDependencies": {
"@playwright/test": "1.64.1"
}
}
23 changes: 23 additions & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Browser tests against a running vimmary with the preview fixtures and
// without an auth block. scripts/e2e starts the instance and sets
// E2E_BASE_URL; see that script.
import { defineConfig, devices } from "@playwright/test";

const baseURL = process.env.E2E_BASE_URL;
if (!baseURL) {
throw new Error("E2E_BASE_URL is not set; run the tests through scripts/e2e");
}

export default defineConfig({
testDir: "tests",
outputDir: "test-results",
forbidOnly: !!process.env.CI,
retries: 0,
reporter: process.env.CI ? [["list"], ["html", { open: "never" }]] : "list",
use: {
baseURL,
trace: "retain-on-failure",
screenshot: "only-on-failure",
},
projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }],
});
18 changes: 18 additions & 0 deletions e2e/tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test as base, expect } from "@playwright/test";

// Every test fails on an uncaught exception in the page. Console messages
// about failed resource loads do not count: the fixture thumbnails point at
// YouTube IDs that do not exist.
export const test = base.extend<{ pageErrors: Error[] }>({
pageErrors: [
async ({ page }, use) => {
const errors: Error[] = [];
page.on("pageerror", (err) => errors.push(err));
await use(errors);
expect(errors.map((e) => e.message)).toEqual([]);
},
{ auto: true },
],
});

export { expect };
56 changes: 56 additions & 0 deletions e2e/tests/library.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { test, expect } from "./fixtures.ts";

// The preview fixtures: internal/storage/fixtures/preview.json.
const videoTitles = [
"Fixture: Postgres indexes in fifteen minutes",
"Fixture: Context cancellation in Go",
"Fixture: Sourdough starter from scratch",
"Fixture: Vortrag über Wärmepumpen",
];

test("the library lists the fixture videos and no podcast episodes", async ({ page }) => {
await page.goto("/");
for (const title of videoTitles) {
await expect(page.getByRole("heading", { name: title, level: 3 })).toBeVisible();
}
await expect(page.getByRole("heading", { name: /Fixture Weekly/ })).toHaveCount(0);
});

test("opening a video shows its summary", async ({ page }) => {
await page.goto("/");
await page.getByRole("link", { name: /Context cancellation in Go/ }).click();
await expect(page).toHaveURL(/\/video\/[0-9a-f-]{36}$/);
await expect(
page.getByRole("heading", { name: "Fixture: Context cancellation in Go", level: 1 }),
).toBeVisible();
await expect(page.getByRole("heading", { name: "Overview", level: 2 })).toBeVisible();
});

test("search narrows the library to the matching video", async ({ page }) => {
await page.goto("/");
await page.getByRole("textbox", { name: "Search summaries" }).fill("sourdough");
await page.keyboard.press("Enter");
await expect(page).toHaveURL(/\?q=sourdough$/);
await expect(
page.getByRole("heading", { name: "Fixture: Sourdough starter from scratch" }),
).toBeVisible();
await expect(page.getByRole("heading", { name: videoTitles[0] })).toHaveCount(0);
});

for (const [path, heading] of [
["/inbox", "Inbox"],
["/channels", "Channels & shows"],
["/stats", "Stats"],
["/settings", "Settings"],
] as const) {
test(`${path} renders`, async ({ page }) => {
await page.goto(path);
await expect(page.getByRole("heading", { name: heading, level: 1 })).toBeVisible();
});
}

test("without application login the nav offers no sign-out", async ({ page }) => {
await page.goto("/");
await expect(page.getByRole("navigation").getByRole("link", { name: "Settings" })).toBeVisible();
await expect(page.getByRole("button", { name: "Sign out" })).toHaveCount(0);
});
18 changes: 15 additions & 3 deletions scripts/e2e
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/usr/bin/env bash
# End-to-end checks against a running vimmary.
#
# With E2E_BASE_URL set, the HTTP checks run against that instance (a session
# starts the app natively with seed_fixtures: true and sets it).
# With E2E_BASE_URL set, the HTTP checks and the Playwright tests in e2e/ run
# against that instance (a session starts the app natively with
# seed_fixtures: true and sets it).
#
# Otherwise the script builds the production image of the working tree as
# vimmary-local:<BUILD_SHA> and runs the upgrade test with compose.e2e.yaml:
#
# 1. the image of the base (E2E_BASE_REF, default origin/main) on an empty
# database, which seeds the fixtures once the base knows seed_fixtures;
# 2. the new image on that database: /version reports BUILD_SHA inside the
# container and on the published port, the HTTP checks pass;
# container and on the published port, the HTTP checks and the
# Playwright tests pass;
# 3. the base image again on the migrated schema, because a rollback resets
# only the image.
#
Expand Down Expand Up @@ -50,8 +52,17 @@ http_checks() {
echo "ok / serves the frontend"
}

# browser_tests <base url>: the Playwright tests in e2e/. On failure the
# traces and screenshots are in e2e/test-results.
browser_tests() {
step "browser tests (e2e/)"
ensure_playwright
E2E_BASE_URL="${1%/}" playwright test
}

if [[ -n "${E2E_BASE_URL:-}" ]]; then
http_checks "$E2E_BASE_URL"
browser_tests "$E2E_BASE_URL"
echo
echo "e2e ok: ${E2E_BASE_URL}"
exit 0
Expand Down Expand Up @@ -115,6 +126,7 @@ fi
step "2. new image"
start "vimmary-local:${BUILD_SHA}" "$BUILD_SHA"
http_checks "$base_url"
browser_tests "$base_url"

if [[ "$upgrade" == 1 ]]; then
step "3. base image on the migrated schema"
Expand Down
22 changes: 22 additions & 0 deletions scripts/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ ensure_npm_deps() {
is_ci() { [[ "${CI:-}" == "true" ]]; }

step() { printf '\n==> %s\n' "$*"; }

# playwright <args>: the Playwright CLI of e2e/, with browsers in Playwright's
# default cache. A cloud session presets PLAYWRIGHT_BROWSERS_PATH to a browser
# build that need not match e2e/'s Playwright version, and
# PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD, which would keep the matching one out.
playwright() {
(cd e2e && env -u PLAYWRIGHT_BROWSERS_PATH -u PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD \
./node_modules/.bin/playwright "$@")
}

# ensure_playwright: e2e/'s npm dependencies and the Chromium build of its
# Playwright version, with the system libraries it needs on Linux.
ensure_playwright() {
if [[ ! -f e2e/node_modules/.package-lock.json || e2e/package-lock.json -nt e2e/node_modules/.package-lock.json ]]; then
(cd e2e && npm ci --no-audit --no-fund --loglevel=error)
fi
if [[ "$(uname -s)" == Linux ]]; then
playwright install --with-deps chromium
else
playwright install chromium
fi
}
9 changes: 8 additions & 1 deletion scripts/setup
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Toolchain and dependencies for a session or a CI job: Go (the version in
# go.mod), golangci-lint, govulncheck, Node (.node-version), the npm
# dependencies of web/, and jq. Runs from the SessionStart hook in
# dependencies of web/ and e2e/, Playwright's Chromium, and jq. Runs from the SessionStart hook in
# .claude/settings.json; quiet when everything is in place.
#
# On Linux as root it installs a missing Go and a missing or mismatched Node;
Expand Down Expand Up @@ -95,6 +95,13 @@ if [[ ! -f web/node_modules/.package-lock.json || web/package-lock.json -nt web/
(cd web && npm ci --no-audit --no-fund --loglevel=error) >&2
fi

# Playwright for the browser tests in e2e/
# shellcheck source=scripts/lib/common.sh
source scripts/lib/common.sh
if ! ensure_playwright >/tmp/vimmary-playwright.log 2>&1; then
say "Playwright browser install failed (log: /tmp/vimmary-playwright.log)"
fi

# jq (hooks read their input with it)
if ! command -v jq >/dev/null 2>&1 && $linux && $root && command -v apt-get >/dev/null 2>&1; then
say "installing jq"
Expand Down
Loading