Download this file
| 1 | package bakeoff |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "io" |
| 6 | ) |
| 7 | |
| 8 | // ParsePlaywright counts the shared suite's results per project from |
| 9 | // Playwright's JSON reporter. A flaky test (passed only on retry) counts |
| 10 | // as failed: the suite runs without retries, so it shouldn't happen. |
| 11 | func ParsePlaywright(r io.Reader) (map[string]Behaviour, error) { |
| 12 | type test struct { |
| 13 | Project string `json:"projectName"` |
| 14 | Status string `json:"status"` |
| 15 | } |
| 16 | type suite struct { |
| 17 | Specs []struct { |
| 18 | Tests []test `json:"tests"` |
| 19 | } `json:"specs"` |
| 20 | Suites []suite `json:"suites"` |
| 21 | } |
| 22 | var report struct { |
| 23 | Suites []suite `json:"suites"` |
| 24 | } |
| 25 | if err := json.NewDecoder(r).Decode(&report); err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | out := map[string]Behaviour{} |
| 29 | var walk func([]suite) |
| 30 | walk = func(ss []suite) { |
| 31 | for _, s := range ss { |
| 32 | for _, sp := range s.Specs { |
| 33 | for _, t := range sp.Tests { |
| 34 | b := out[t.Project] |
| 35 | switch t.Status { |
| 36 | case "expected": |
| 37 | b.Passed++ |
| 38 | case "skipped": |
| 39 | b.Skipped++ |
| 40 | default: |
| 41 | b.Failed++ |
| 42 | } |
| 43 | out[t.Project] = b |
| 44 | } |
| 45 | } |
| 46 | walk(s.Suites) |
| 47 | } |
| 48 | } |
| 49 | walk(report.Suites) |
| 50 | return out, nil |
| 51 | } |
| 52 | |