Skip to content

Add SummaryReporter for vitest #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,40 @@ describe('MyWidget', () => {
});
});
```

## Vitest

This package has an optional peer dependency on `vitest`. Any vitest-specific
utility is exposed in a separate `@hypothesis/frontend-testing/vitest` entry
point.

### Summary reporter

Vitest's default reporter prints a real-time summary indicating the test
execution progress, but also a per-file list of tests at the end of every test
file.

This package provides a `SummaryReporter` that skips the per-file output, but
still prints the real-time summary and details for any failed test.

```js
// vitest.config.js

import { SummaryReporter } from '@hypothesis/frontend-testing/vitest';
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
browser: {
provider: 'playwright',
// ...
},

// Set the summary reporter here. You can define more reporters if desired
reporters: [new SummaryReporter()],

// Other config...
},
});
```
21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,35 @@
"author": "Hypothesis Developers <[email protected]>",
"license": "BSD-2-Clause",
"packageManager": "[email protected]",
"exports": {
".": {
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./vitest": {
"import": "./lib/vitest.js",
"types": "./lib/vitest.d.ts"
}
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^3.1.2"
},
"dependencies": {
"axe-core": "^4.8.2",
"enzyme": "^3.11.0",
"preact": "^10.18.1"
},
"peerDependencies": {
"vitest": "^3.1.2"
},
"peerDependenciesMeta": {
"vitest": {
"optional": true
}
},
"files": [
"lib/**/*.js",
"lib/**/*.d.ts"
Expand Down
12 changes: 12 additions & 0 deletions src/vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DefaultReporter } from 'vitest/reporters';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that Vitest also has a BasicReporter. How does the output from that differ from what we're doing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basic reporter is the same as the default reporter, but with the summary disabled. Basically the opposite of what we want.

Copy link
Contributor Author

@acelaya acelaya Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad. The basic reporter seems to be the same we want, except that it does not print the progress in real time, only at the end.

basic-reporter-2025-04-24_10.54.48.mp4

That makes me think that the summary is not what I have been calling "summary", but the output from every file. Perhaps we should find a better name for our reporter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the discussion here, it seems what we want is in fact the summary, so SummaryReporter sounds like a good name vitest-dev/vitest#7881


/**
* This reporter provides a real-time progress summary during test execution and
* reports failures in detail but avoids printing a list of successful tests.
* For context see https://github.com/vitest-dev/vitest/issues/7881
*/
export class SummaryReporter extends DefaultReporter {
onTestModuleEnd() {
// Override this method to suppress individual file results
}
}
Loading