|
| 1 | +import { readFile } from 'node:fs/promises' |
1 | 2 | import { sep } from 'node:path' |
2 | 3 | import { runVitest } from '#test-utils' |
3 | 4 | import { resolve } from 'pathe' |
@@ -59,4 +60,44 @@ describe(GithubActionsReporter, () => { |
59 | 60 | `) |
60 | 61 | expect(stderr).toBe('') |
61 | 62 | }) |
| 63 | + |
| 64 | + // summary gets written in $GITHUB_STEP_SUMMARY |
| 65 | + it.runIf(process.env.GITHUB_STEP_SUMMARY !== undefined)('creates summary', async () => { |
| 66 | + const { stdout, stderr } = await runVitest( |
| 67 | + { |
| 68 | + reporters: new GithubActionsReporter(), |
| 69 | + root: './fixtures/reporters/github-actions', |
| 70 | + }, |
| 71 | + ) |
| 72 | + |
| 73 | + expect(stderr).toBe('') |
| 74 | + expect(stdout).toBe('') |
| 75 | + |
| 76 | + const summary = await readFile(process.env.GITHUB_STEP_SUMMARY!, 'utf8') |
| 77 | + |
| 78 | + expect( |
| 79 | + summary.replace(/https:\/\/github.com\/\w+\/\w+\/blob\/\w+/g, '<repository>'), |
| 80 | + ).toMatchInlineSnapshot(` |
| 81 | + "## Vitest Test Report |
| 82 | +
|
| 83 | + ### Flaky Tests |
| 84 | +
|
| 85 | + These tests passed only after one or more retries, indicating potential instability. |
| 86 | +
|
| 87 | + ##### \`flaky/math.spec.ts\` (5 flaky tests) |
| 88 | +
|
| 89 | + - [\`should multiply numbers correctly\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 5 out of 5**) |
| 90 | + - [\`should handle edge cases\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 4 out of 5**) |
| 91 | + - [\`should validate input properly\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (**passed on retry 4 out of 5**) |
| 92 | + - [\`should divide numbers correctly\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (passed on retry 2 out of 5) |
| 93 | + - [\`should subtract numbers correctly\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/math.spec.ts) (passed on retry 1 out of 5) |
| 94 | +
|
| 95 | + ##### \`flaky/network.spec.ts\` (3 flaky tests) |
| 96 | +
|
| 97 | + - [\`network > should handle network timeouts gracefully\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/network.spec.ts) (**passed on retry 4 out of 4**) |
| 98 | + - [\`network > should fetch user data from API\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/network.spec.ts) (passed on retry 2 out of 3) |
| 99 | + - [\`network > should retry failed requests\`](<repository>/test/cli/fixtures/reporters/github-actions/flaky/network.spec.ts) (passed on retry 1 out of 3) |
| 100 | + " |
| 101 | + `) |
| 102 | + }) |
62 | 103 | }) |
0 commit comments