| 1 | //go:build browser |
| 2 | |
| 3 | package harness |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "os/exec" |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | // ChromePath finds the Chromium a browser-tagged test drives: |
| 13 | // FIESTA_CHROME first, then the usual PATH names, then the Playwright |
| 14 | // cache. One discovery story for every browser test. |
| 15 | // |
| 16 | // A skip is not a pass: with no browser this fails, unless |
| 17 | // FIESTA_BROWSER_OPTIONAL is set, which makes the skip a deliberate |
| 18 | // visible choice rather than an accident. |
| 19 | func ChromePath(t *testing.T) string { |
| 20 | t.Helper() |
| 21 | if p := os.Getenv("FIESTA_CHROME"); p != "" { |
| 22 | return p |
| 23 | } |
| 24 | for _, name := range []string{"chromium", "chromium-browser", "google-chrome", "google-chrome-stable"} { |
| 25 | if p, err := exec.LookPath(name); err == nil { |
| 26 | return p |
| 27 | } |
| 28 | } |
| 29 | if home, err := os.UserHomeDir(); err == nil { |
| 30 | hits, _ := filepath.Glob(filepath.Join(home, ".cache", "ms-playwright", "chromium-*", "chrome-linux64", "chrome")) |
| 31 | if len(hits) > 0 { |
| 32 | return hits[len(hits)-1] |
| 33 | } |
| 34 | } |
| 35 | if os.Getenv("FIESTA_BROWSER_OPTIONAL") != "" { |
| 36 | t.Skip("no chromium found, FIESTA_BROWSER_OPTIONAL set — SKIPPED, not passed") |
| 37 | } |
| 38 | t.Fatal("no chromium found: set FIESTA_CHROME, or FIESTA_BROWSER_OPTIONAL to skip deliberately") |
| 39 | return "" |
| 40 | } |
| 41 | |