From 6879f025890f2330438a73f9b0c22c8558c90d6e Mon Sep 17 00:00:00 2001 From: dimiro1 Date: Thu, 4 Jun 2026 09:29:46 +0200 Subject: [PATCH 1/3] test: add headless e2e test that runs the Jasmine frontend suite Drive frontend/test/SpecRunner.html in headless Chrome (chromedp) and fail if any spec fails, automating the verdict that was previously only eyeballed via cmd/testserver. A small custom reporter publishes the result on window.__jasmineResults since Jasmine's jsApiReporter is deprecated and unwired. Lives in e2e/jasmine so it is gated behind the e2e task and excluded from unit tests; add a test-frontend-headless mise task. Also fix a stale utils spec that still expected 5 function tabs after a sixth (data) tab was added. --- e2e/jasmine/jasmine_test.go | 132 +++++++++++++++++++++++++++++++ frontend/test/SpecRunner.html | 36 +++++++++ frontend/test/spec/utils.spec.js | 5 +- mise.toml | 7 ++ 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 e2e/jasmine/jasmine_test.go diff --git a/e2e/jasmine/jasmine_test.go b/e2e/jasmine/jasmine_test.go new file mode 100644 index 0000000..8371677 --- /dev/null +++ b/e2e/jasmine/jasmine_test.go @@ -0,0 +1,132 @@ +// Package jasmine runs the frontend's Jasmine unit-test suite end-to-end in a +// real headless Chrome browser and asserts that every spec passes. +// +// The Jasmine specs (frontend/test/spec/**) exercise the dashboard's +// client-side code — components, routing, i18n, utilities — directly in the +// browser, the way they actually run. `mise run test-frontend` (cmd/testserver) +// serves the very same SpecRunner.html for a human to eyeball; this test +// automates the verdict so a frontend regression fails CI instead of waiting for +// someone to look. +// +// It lives under e2e/ so it is gated behind the e2e task (which already requires +// a Chrome/Chromium on the machine) and excluded from the unit-test task, which +// runs `go list ./... | grep -v /e2e`. +// +// Run it on its own with: +// +// go test ./e2e/jasmine/... +// +// It is also covered by `mise run test-e2e`, which runs `go test ./e2e/...`. +package jasmine + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "path/filepath" + "runtime" + "strings" + "testing" + "time" + + "github.com/chromedp/chromedp" +) + +// frontendDir resolves the absolute path to the repository's frontend/ directory +// from this test file's location, so the test works regardless of the working +// directory `go test` happens to be invoked from. +func frontendDir() string { + _, thisFile, _, _ := runtime.Caller(0) + // e2e/jasmine/jasmine_test.go -> e2e -> repo root -> frontend + return filepath.Join(filepath.Dir(thisFile), "..", "..", "frontend") +} + +// jasmineResults mirrors the window.__jasmineResults object that SpecRunner.html +// publishes once the whole suite has finished. +type jasmineResults struct { + OverallStatus string `json:"overallStatus"` + Total int `json:"total"` + Failures []struct { + FullName string `json:"fullName"` + Messages []string `json:"messages"` + } `json:"failures"` +} + +func TestJasmineSuitePasses(t *testing.T) { + // Serve the on-disk frontend directory exactly as cmd/testserver does. The + // SpecRunner and its specs are not embedded in the production binary, so they + // must be served straight from the source tree. + ts := httptest.NewServer(http.FileServer(http.Dir(frontendDir()))) + defer ts.Close() + + opts := append(chromedp.DefaultExecAllocatorOptions[:], + chromedp.Flag("disable-gpu", true), + chromedp.Flag("no-sandbox", true), + chromedp.Flag("headless", true), + ) + allocCtx, cancelAlloc := chromedp.NewExecAllocator(context.Background(), opts...) + defer cancelAlloc() + + browserCtx, cancelBrowser := chromedp.NewContext(allocCtx) + defer cancelBrowser() + + // Generous bound: Chrome cold-start plus loading and running the full spec + // suite (it imports the real app modules) can be slow on CI runners. + ctx, cancel := context.WithTimeout(browserCtx, 90*time.Second) + defer cancel() + + if err := chromedp.Run(ctx, chromedp.Navigate(ts.URL+"/test/SpecRunner.html")); err != nil { + t.Fatalf("navigate to SpecRunner.html: %v", err) + } + + // The specs are ES modules executed asynchronously, and Jasmine itself only + // starts on window.onload, so the verdict lags the page load — poll for it. + if err := waitJasmineDone(ctx); err != nil { + t.Fatalf("waiting for the Jasmine suite to finish: %v", err) + } + + var res jasmineResults + if err := chromedp.Run(ctx, chromedp.Evaluate(`window.__jasmineResults`, &res)); err != nil { + t.Fatalf("reading Jasmine results: %v", err) + } + + // Zero specs means the spec modules failed to load (a bad import path or a + // syntax error) rather than a genuinely empty suite — treat it as a failure. + if res.Total == 0 { + t.Fatal("Jasmine reported 0 specs — the spec files likely failed to load") + } + + if res.OverallStatus != "passed" { + var b strings.Builder + fmt.Fprintf(&b, "Jasmine suite did not pass: overall status = %q, %d/%d specs failed\n", + res.OverallStatus, len(res.Failures), res.Total) + for _, f := range res.Failures { + fmt.Fprintf(&b, " ✗ %s\n", f.FullName) + for _, m := range f.Messages { + fmt.Fprintf(&b, " %s\n", strings.ReplaceAll(m, "\n", "\n ")) + } + } + t.Fatal(b.String()) + } + + t.Logf("Jasmine suite passed: %d specs, 0 failures", res.Total) +} + +// waitJasmineDone polls until SpecRunner.html has published its final results +// (up to ~30s once the page is loaded). +func waitJasmineDone(ctx context.Context) error { + for range 120 { + var done bool + if err := chromedp.Run(ctx, chromedp.Evaluate(`window.__jasmineResults !== null`, &done)); err != nil { + return err + } + if done { + return nil + } + if err := chromedp.Run(ctx, chromedp.Sleep(250*time.Millisecond)); err != nil { + return err + } + } + return context.DeadlineExceeded +} diff --git a/frontend/test/SpecRunner.html b/frontend/test/SpecRunner.html index ade9024..f9460c4 100644 --- a/frontend/test/SpecRunner.html +++ b/frontend/test/SpecRunner.html @@ -14,6 +14,42 @@ + + + diff --git a/frontend/test/spec/utils.spec.js b/frontend/test/spec/utils.spec.js index f6c0e99..e7ad20c 100644 --- a/frontend/test/spec/utils.spec.js +++ b/frontend/test/spec/utils.spec.js @@ -5,9 +5,9 @@ import { formatUnixTimestamp, getFunctionTabs } from "../../js/utils.js"; describe("getFunctionTabs", () => { - it("returns all 5 tabs", () => { + it("returns all 6 tabs", () => { const tabs = getFunctionTabs("test-id"); - expect(tabs.length).toBe(5); + expect(tabs.length).toBe(6); }); it("includes correct tab ids", () => { @@ -16,6 +16,7 @@ describe("getFunctionTabs", () => { expect(ids).toContain("code"); expect(ids).toContain("versions"); expect(ids).toContain("executions"); + expect(ids).toContain("data"); expect(ids).toContain("settings"); expect(ids).toContain("test"); }); diff --git a/mise.toml b/mise.toml index af0e3ac..4c7f1b1 100644 --- a/mise.toml +++ b/mise.toml @@ -64,6 +64,13 @@ run = "go test -tags integration -v -timeout 60s ./..." description = "Open Jasmine frontend tests in browser" run = "go run ./cmd/testserver" +[tasks.test-frontend-headless] +description = "Run the Jasmine frontend tests headlessly and assert they pass" +# Drives SpecRunner.html in headless Chrome and fails if any spec fails. Also +# covered by `mise run test-e2e` (it runs all of ./e2e/...); this task narrows +# the run to just the frontend suite. Needs a Chrome/Chromium on the machine. +run = "go test -v -count=1 -timeout 5m ./e2e/jasmine/..." + [tasks.test-e2e] description = "Run E2E tests with headless Chrome (Cucumber/godog)" # The whole browser suite runs well under the 20m budget locally; the generous From e78bb3b167d8f02a3fffcc2823464bf424f0be1d Mon Sep 17 00:00:00 2001 From: dimiro1 Date: Thu, 4 Jun 2026 09:41:26 +0200 Subject: [PATCH 2/3] test(e2e): launch headless Chrome with --disable-dev-shm-usage on CI The E2E job failed because headless Chrome crashed on startup: the new Jasmine test reported "websocket url timeout reached" (Chrome never printed its DevTools endpoint) and the first godog scenario hit a cold context deadline. CI containers expose a ~64MB /dev/shm, which headless Chrome exhausts; routing shared memory to /tmp via --disable-dev-shm-usage keeps the browser stable. Add the flag to both the godog allocator and the Jasmine test's allocator. --- e2e/jasmine/jasmine_test.go | 5 +++++ e2e/world_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/e2e/jasmine/jasmine_test.go b/e2e/jasmine/jasmine_test.go index 8371677..3ddcdee 100644 --- a/e2e/jasmine/jasmine_test.go +++ b/e2e/jasmine/jasmine_test.go @@ -63,6 +63,11 @@ func TestJasmineSuitePasses(t *testing.T) { opts := append(chromedp.DefaultExecAllocatorOptions[:], chromedp.Flag("disable-gpu", true), chromedp.Flag("no-sandbox", true), + // CI runners give the container a tiny /dev/shm (~64MB); without this + // headless Chrome exhausts it and crashes on startup, which surfaces here + // as "websocket url timeout reached" because it never prints its DevTools + // endpoint. Writing shared memory to /tmp instead avoids that. + chromedp.Flag("disable-dev-shm-usage", true), chromedp.Flag("headless", true), ) allocCtx, cancelAlloc := chromedp.NewExecAllocator(context.Background(), opts...) diff --git a/e2e/world_test.go b/e2e/world_test.go index 5d73fd3..9eb762b 100644 --- a/e2e/world_test.go +++ b/e2e/world_test.go @@ -110,6 +110,10 @@ func sharedAllocator() context.Context { chromedp.DefaultExecAllocatorOptions[:], chromedp.Flag("disable-gpu", true), chromedp.Flag("no-sandbox", true), + // CI runners give the container a tiny /dev/shm (~64MB); headless + // Chrome can exhaust it and crash on startup. Writing shared memory to + // /tmp instead keeps the browser stable on the first (cold) launch. + chromedp.Flag("disable-dev-shm-usage", true), ) // Headless by default. Set E2E_HEADED=1 (or true/yes/on) to watch the // suite drive a real, visible browser window — handy when debugging a From 14df3b7e904c612fd378206de0f1589b00f21b26 Mon Sep 17 00:00:00 2001 From: dimiro1 Date: Thu, 4 Jun 2026 09:48:00 +0200 Subject: [PATCH 3/3] test(e2e): run e2e package test binaries serially with -p 1 The real cause of the E2E job failure: `go test ./e2e/...` builds two Chrome-driving binaries (./e2e godog and ./e2e/jasmine) and Go runs different packages' binaries in parallel by default. Their two headless Chromes contend for the runner, so the Jasmine Chrome can't start within chromedp's 20s window ("websocket url timeout reached") and the godog cold-start scenario blows its deadline. -p 1 serializes the binaries, the way the godog suite already runs its own scenarios with Concurrency: 1. (The earlier --disable-dev-shm-usage flag is kept as CI hardening.) --- mise.toml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mise.toml b/mise.toml index 4c7f1b1..94e2596 100644 --- a/mise.toml +++ b/mise.toml @@ -77,12 +77,17 @@ description = "Run E2E tests with headless Chrome (Cucumber/godog)" # timeout is headroom for slower CI runners (Chrome cold-start + Monaco load). # Set E2E_HEADED=1 to watch a real browser; GODOG_FEATURE=e2e/features/.feature # narrows the run to one file. `mise run test-e2e-headed` does both conveniently. -run = "go test -v -timeout 20m ./e2e/..." +# +# -p 1 runs the e2e packages' test binaries one at a time. Both ./e2e (godog) and +# ./e2e/jasmine drive their own headless Chrome; left to run in parallel (Go's +# default) the two browsers contend for the runner and Chrome fails to start +# within chromedp's startup window ("websocket url timeout reached"). +run = "go test -v -p 1 -timeout 20m ./e2e/..." [tasks.test-e2e-headed] description = "Run E2E tests in a visible (non-headless) browser" env = { E2E_HEADED = "1" } -run = "go test -v -count=1 -timeout 20m ./e2e/..." +run = "go test -v -p 1 -count=1 -timeout 20m ./e2e/..." [tasks.test-all] description = "Run all Go tests (unit + e2e)"