Skip to content

Commit 85b51f1

Browse files
committed
Add SummaryReporter for vitest
1 parent b13ee79 commit 85b51f1

File tree

4 files changed

+1791
-7
lines changed

4 files changed

+1791
-7
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,40 @@ describe('MyWidget', () => {
4848
});
4949
});
5050
```
51+
52+
## Vitest
53+
54+
This package has an optional peer dependency on `vitest`. Any vitest-specific
55+
utility is exposed in a separate `@hypothesis/frontend-testing/vitest` entry
56+
point.
57+
58+
### Summary reporter
59+
60+
Vitest's default reporter prints a real-time summary indicating the test
61+
execution progress, but also a per-file list of tests at the end of every test
62+
file.
63+
64+
This package provides a `SummaryReporter` that skips the per-file output, but
65+
still prints the real-time summary and details for any failed test.
66+
67+
```js
68+
// vitest.config.js
69+
70+
import { SummaryReporter } from '@hypothesis/frontend-testing/vitest';
71+
import { defineConfig } from 'vitest/config';
72+
73+
export default defineConfig({
74+
test: {
75+
globals: true,
76+
browser: {
77+
provider: 'playwright',
78+
// ...
79+
},
80+
81+
// Set the summary reporter here. You can define more reporters if desired
82+
reporters: [new SummaryReporter()],
83+
84+
// Other config...
85+
},
86+
});
87+
```

package.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,35 @@
99
"author": "Hypothesis Developers <[email protected]>",
1010
"license": "BSD-2-Clause",
1111
"packageManager": "[email protected]",
12+
"exports": {
13+
".": {
14+
"import": "./lib/index.js",
15+
"types": "./lib/index.d.ts"
16+
},
17+
"./vitest": {
18+
"import": "./lib/vitest.js",
19+
"types": "./lib/vitest.d.ts"
20+
}
21+
},
1222
"devDependencies": {
1323
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
1424
"prettier": "^3.0.3",
15-
"typescript": "^5.2.2"
25+
"typescript": "^5.2.2",
26+
"vitest": "^3.1.2"
1627
},
1728
"dependencies": {
1829
"axe-core": "^4.8.2",
1930
"enzyme": "^3.11.0",
2031
"preact": "^10.18.1"
2132
},
33+
"peerDependencies": {
34+
"vitest": "^3.1.2"
35+
},
36+
"peerDependenciesMeta": {
37+
"vitest": {
38+
"optional": true
39+
}
40+
},
2241
"files": [
2342
"lib/**/*.js",
2443
"lib/**/*.d.ts"

src/vitest.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DefaultReporter } from 'vitest/reporters';
2+
3+
/**
4+
* This reporter provides a real-time summary and reports errors in detail, but
5+
* skips the individual file output.
6+
*/
7+
export class SummaryReporter extends DefaultReporter {
8+
onTestModuleEnd() {
9+
// Override this method to suppress individual file results
10+
}
11+
}

0 commit comments

Comments
 (0)