Skip to content

Commit b6e2ab3

Browse files
committed
test: GitHub Actions reporter summary
1 parent 0f21c8f commit b6e2ab3

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { test } from 'vitest'
2+
3+
test('should add numbers correctly', { retry: 5 }, ({ expect, task }) => {
4+
expect(task.result?.retryCount).toBe(0)
5+
})
6+
7+
test('should subtract numbers correctly', { retry: 5 }, ({ expect, task }) => {
8+
expect(task.result?.retryCount).toBe(1)
9+
})
10+
11+
test('should multiply numbers correctly', { retry: 5 }, ({ expect, task }) => {
12+
expect(task.result?.retryCount).toBe(5)
13+
})
14+
15+
test('should divide numbers correctly', { retry: 5 }, ({ expect, task }) => {
16+
expect(task.result?.retryCount).toBe(2)
17+
})
18+
19+
test('should handle edge cases', { retry: 5 }, ({ expect, task }) => {
20+
expect(task.result?.retryCount).toBe(4)
21+
})
22+
23+
test('should validate input properly', { retry: 5 }, ({ expect, task }) => {
24+
expect(task.result?.retryCount).toBe(4)
25+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, test } from 'vitest'
2+
3+
describe('network', () => {
4+
test('should fetch user data from API', { retry: 3 }, ({ expect, task }) => {
5+
expect(task.result?.retryCount).toBe(2)
6+
})
7+
8+
test('should handle network timeouts gracefully', { retry: 4 }, ({ expect, task }) => {
9+
expect(task.result?.retryCount).toBe(4)
10+
})
11+
12+
test('should retry failed requests', { retry: 3 }, ({ expect, task }) => {
13+
expect(task.result?.retryCount).toBe(1)
14+
})
15+
})

test/cli/test/reporters/github-actions.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { readFile } from 'node:fs/promises'
12
import { sep } from 'node:path'
23
import { runVitest } from '#test-utils'
34
import { resolve } from 'pathe'
@@ -59,4 +60,44 @@ describe(GithubActionsReporter, () => {
5960
`)
6061
expect(stderr).toBe('')
6162
})
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+
})
62103
})

0 commit comments

Comments
 (0)