Skip to content

Commit ac54bbf

Browse files
committed
Update docs to reflect that bundles can also use browser mode for testing
1 parent 9fca7f1 commit ac54bbf

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

docs/src/modules/4-testing/4-unit/2-unit.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,10 @@ export function bar2() {
233233

234234
:::
235235

236-
Though `vi.mock` accepts a string path, you should always use the import expression syntax, since it will
237-
allow Typescript to provide typing and ensure that the path refers to a module that exists.
236+
Though `vi.mock` accepts a string path, you should always use the import expression syntax where possible,
237+
since it will allow Typescript to provide typing and ensure that the path refers to a module that exists. Also, if you
238+
relocate the file you're importing from or the test file itself, the path will automatically get rewritten
239+
(if you're using an editor like VSCode).
238240

239241
```ts
240242
// do this

docs/src/modules/4-testing/4-unit/3-browser.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Browser Mode
22

3-
Tabs have the ability to leverage `playwright` and `vitest`'s browser mode to ensure that the interactive features of the tab actually
4-
behave like they should.
3+
Vitest provides a special "browser" mode that runs tests directly in a simulated browser environment and provides utilities
4+
to test interactive features.
55

6-
The default testing configuration for tabs has browser mode disabled. This is so that if your tab doesn't need the features that Playwright provides,
6+
This is particularly useful for tabs, but bundles can also leverage browser mode to test browser-only functionalities. Refer to the `pix_n_flix`
7+
bundle for such an example.
8+
9+
The default testing configuration has browser mode disabled. This is so that if your dom't need the features that Playwright provides,
710
`vitest` won't need to spin up the Playwright instance.
811

912
## Setting up Browser Mode
1013

11-
Should you wish to enable browser mode, create a custom `vitest` configuration file for your tab with the `browser.enabled` option set to `true`:
14+
Should you wish to enable browser mode, [create](./1-general#custom-test-configuration) a custom `vitest` configuration file for your tab with the `browser.enabled` option set to `true`:
1215

13-
```js {9}
14-
// @ts-check
16+
```js {8}
1517
import { defineProject } from 'vitest/config';
1618

1719
export default defineProject({
@@ -49,8 +51,8 @@ Now, the tests for your tab can be run in browser mode.
4951
Writing interactive tests is not very different from writing regular tests. Most of the time, the usual test and assertion functions will suffice.
5052

5153
> [!INFO]
52-
> While writing your tests, you should use watch mode. This will allow `vitest` to open a browser and actually display what your tab looks like whilst
53-
> being rendered during the test.
54+
> While writing your tests, you should use watch mode. This will allow `vitest` to open a browser and actually display what your rendered
55+
> component looks like during the test.
5456
5557
Use the `render` function provided `vitest-browser-react` to render your tab/component to a screen. Note that it should be awaited.
5658
The returned value can then be interacted with:
@@ -85,7 +87,7 @@ test('Testing my component', async () => {
8587
8688
### `expect.poll` and `expect.element`
8789
88-
Sometimes, visual elements take a while to finish or an element might take a while to load. If you just directly used an assertion, the assertion
90+
Sometimes, visual elements take a while to finish or an element might take a while to load. If you just used an assertion normally, the assertion
8991
might fail because the element hasn't displayed yet:
9092
9193
```tsx
@@ -169,7 +171,7 @@ assertions or clicking).
169171

170172
`vitest` provides several ways to "locate" an element helpfully called [locators](https://vitest.dev/guide/browser/locators.html).
171173

172-
While writing tabs, if we believe that a component will need to be interacted with during unit testing, we can use attributes like `title` to make it
174+
While writing components, if we believe they will need to be interacted with during unit testing, we can use attributes like `title` to make it
173175
easier to refer to these elements:
174176

175177
```tsx

lib/repotools/src/testing/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ async function loadRootConfig() {
5656
*/
5757
export const baseVitestConfig: ViteUserConfig = await loadRootConfig();
5858

59+
/**
60+
* Default browser mode options
61+
*/
5962
export const browserModeConfig: BrowserConfigOptions = {
63+
/*
64+
* Instances should not be set here because if the config to merge
65+
* also contains an instances configuration the instance configured here
66+
* gets added instead of being replaced, resulting in an erroneous extra
67+
* instance configuration.
68+
*/
6069
provider: playwright(),
6170
};
6271

0 commit comments

Comments
 (0)