Skip to content

Commit c13d072

Browse files
committed
Document considerations when using Vitest
1 parent d00834e commit c13d072

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

README.md

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
This package contains common utilities for testing UI components across
44
Hypothesis frontend projects. It includes tools for:
55

6-
- Rendering UI components and unmounting them once the test ends
7-
- Waiting for conditions to be met
8-
- Mocking UI components
9-
- Testing accessibility using [axe-core](https://github.com/dequelabs/axe-core)
6+
- Rendering UI components and unmounting them once the test ends
7+
- Waiting for conditions to be met
8+
- Mocking UI components
9+
- Testing accessibility using [axe-core](https://github.com/dequelabs/axe-core)
1010

1111
This package is designed to work with downstream projects that use Hypothesis's
1212
standard UI and UI testing stack, built on:
1313

14-
- [Preact](https://preactjs.com)
15-
- [Enzyme](https://github.com/enzymejs/enzyme)
16-
- [Vitest](http://vitest.dev/)
17-
- [babel-plugin-mockable-imports](https://github.com/robertknight/babel-plugin-mockable-imports)
14+
- [Preact](https://preactjs.com)
15+
- [Enzyme](https://github.com/enzymejs/enzyme)
16+
- [Vitest](http://vitest.dev/)
17+
- [babel-plugin-mockable-imports](https://github.com/robertknight/babel-plugin-mockable-imports)
1818

1919
## API guide
2020

@@ -36,13 +36,13 @@ describe('MyWidget', () => {
3636
});
3737

3838
it('should render', () => {
39-
const wrapper = mount(<MyWidget/>);
39+
const wrapper = mount(<MyWidget />);
4040

4141
// Query component content etc.
4242
});
4343

4444
it('should do something that requires component to be connected', () => {
45-
const wrapper = mount(<MyWidget/>, { connected: true });
45+
const wrapper = mount(<MyWidget />, { connected: true });
4646

4747
// Test behavior that relies on rendered component being part of the
4848
// DOM tree under `document.body`.
@@ -58,30 +58,30 @@ However, we don't follow all practices recommended by Vitest. You should take
5858
these points into consideration when reading Vitest's documentation:
5959

6060
1. By default, Vitest uses [Vite](https://vite.dev/) to bundle the tests and
61-
source code as test files are run.
62-
Instead, we manually pre-bundle our tests and source code in a single file
63-
with Rollup, and that's the only test file we run.
64-
That file is still processed by Vite, but since it has nothing to transform,
65-
the time it takes is negligible.
61+
source code as test files are run.
62+
Instead, we manually pre-bundle our tests and source code in a single file
63+
with Rollup, and that's the only test file we run.
64+
That file is still processed by Vite, but since it has nothing to transform,
65+
the time it takes is negligible.
6666
2. Due to the point above, Vitest tries to capture and calculate code coverage while
67-
tests and sources are bundled with Vite.
68-
In our case, we use `babel-plugin-istanbul` to instrument the code coverage
69-
while we do our own pre-bundling.
70-
This requires two configuration options to be set in `babel-plugin-istanbul`,
71-
so that `istanbul-lib-instrument` checks the file is already instrumented.
72-
See the details below.
73-
74-
```js
75-
[
76-
'babel-plugin-istanbul',
77-
{
78-
coverageGlobalScope: 'globalThis',
79-
coverageVariable: '__VITEST_COVERAGE__',
80-
81-
// Other options...
82-
},
83-
]
84-
```
67+
tests and sources are bundled with Vite.
68+
In our case, we use `babel-plugin-istanbul` to instrument the code coverage
69+
while we do our own pre-bundling.
70+
This requires two configuration options to be set in `babel-plugin-istanbul`,
71+
so that `istanbul-lib-instrument` checks the file is already instrumented.
72+
[See the discussion](https://github.com/vitest-dev/vitest/discussions/7841#discussioncomment-12855608).
73+
74+
```js
75+
[
76+
'babel-plugin-istanbul',
77+
{
78+
coverageGlobalScope: 'globalThis',
79+
coverageVariable: '__VITEST_COVERAGE__',
80+
81+
// Other options...
82+
},
83+
];
84+
```
8585

8686
### Istanbul coverage options
8787

@@ -132,7 +132,6 @@ still prints the real-time summary and details for any failed test.
132132

133133
```js
134134
// vitest.config.js
135-
136135
import { SummaryReporter } from '@hypothesis/frontend-testing';
137136
import { defineConfig } from 'vitest/config';
138137

0 commit comments

Comments
 (0)