package web import ( "os/exec" "path/filepath" "regexp" "strings" "testing" ) // TestMarkdownEditor runs testdata/editor.html, which drives the editor in // assets/app.js and reports PASS or FAIL lines, in a headless browser. func TestMarkdownEditor(t *testing.T) { var browser string for _, name := range []string{"chromium", "chromium-browser", "google-chrome"} { if p, err := exec.LookPath(name); err == nil { browser = p break } } if browser == "" { t.Skip("no Chromium to run the editor in") } page, err := filepath.Abs("testdata/editor.html") if err != nil { t.Fatal(err) } out, err := exec.Command(browser, "--headless", "--disable-gpu", "--allow-file-access-from-files", "--virtual-time-budget=3000", "--dump-dom", "file://"+page).Output() if err != nil { t.Fatalf("running %s: %v", browser, err) } m := regexp.MustCompile(`(?s)
(.*?)`).FindSubmatch(out) if m == nil || len(m[1]) == 0 { t.Fatal("the editor test page produced no results") } for _, line := range strings.Split(string(m[1]), "\n") { if !strings.HasPrefix(line, "PASS ") { t.Error(line) } } }