package bakeoff import ( "encoding/json" "io" ) // ParsePlaywright counts the shared suite's results per project from // Playwright's JSON reporter. A flaky test (passed only on retry) counts // as failed: the suite runs without retries, so it shouldn't happen. func ParsePlaywright(r io.Reader) (map[string]Behaviour, error) { type test struct { Project string `json:"projectName"` Status string `json:"status"` } type suite struct { Specs []struct { Tests []test `json:"tests"` } `json:"specs"` Suites []suite `json:"suites"` } var report struct { Suites []suite `json:"suites"` } if err := json.NewDecoder(r).Decode(&report); err != nil { return nil, err } out := map[string]Behaviour{} var walk func([]suite) walk = func(ss []suite) { for _, s := range ss { for _, sp := range s.Specs { for _, t := range sp.Tests { b := out[t.Project] switch t.Status { case "expected": b.Passed++ case "skipped": b.Skipped++ default: b.Failed++ } out[t.Project] = b } } walk(s.Suites) } } walk(report.Suites) return out, nil }