rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package harness
4
5import (
6 "context"
7 "fmt"
8 "strings"
9 "time"
10
11 "github.com/chromedp/chromedp"
12)
13
14// screenBudget bounds the wait for a screen to arrive. Wall-clock
15// against a real browser: generous enough for a loaded CI box, and far
16// faster than Go's default test timeout — a missing screen fails as
17// itself, not as a hung suite (ui/browser_test.go's 60s reasoning,
18// kept).
19const screenBudget = 60 * time.Second
20
21// Screen is the gate a drive passes at every screen boundary: wait for
22// selector, run the junk scan, then flush the problem list — any
23// accumulated problem fails the test naming the screen it surfaced on.
24// "body" is the whole-page case for rastrillo's server-rendered apps,
25// which have no #app convention to hard-fail on.
26func (r *Rig) Screen(selector, note string) {
27 r.t.Helper()
28 ctx, cancel := context.WithTimeout(r.ctx, screenBudget)
29 defer cancel()
30 if err := chromedp.Run(ctx, chromedp.WaitVisible(selector, chromedp.ByQuery)); err != nil {
31 r.fail(selector, note, fmt.Sprintf("screen %q never arrived: %v", selector, err))
32 }
33 if hits := r.junkHits(selector); len(hits) > 0 {
34 r.fail(selector, note, "a JS value leaked to the screen:\n "+strings.Join(hits, "\n "))
35 }
36 if probs := r.take(); len(probs) > 0 {
37 r.fail(selector, note, "the page reported problems:\n "+strings.Join(probs, "\n "))
38 }
39}
40
41// fail fails the test with what was on screen: a failure report always
42// includes what a person would have seen.
43func (r *Rig) fail(selector, note, msg string) {
44 r.t.Helper()
45 r.t.Fatalf("harness: %s: %s\non screen:\n%s", note, msg, r.onScreen(selector))
46}
47