Skip to content

Commit 6dfba78

Browse files
authored
docs: contributing.md extending test suite section (#2946)
1 parent a56d4af commit 6dfba78

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

.github/contributing.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Each test can be run under either dev server mode or build mode.
2929

3030
- You can also use `yarn test-serve [match]` or `yarn test-build [match]` to run tests in a specific playground package, e.g. `yarn test-serve css` will run tests for both `playground/css` and `playground/css-codesplit` under serve mode.
3131

32-
Note package matching is not aviable for the `yarn test` script, which always runs all tests.
32+
Note package matching is not available for the `yarn test` script, which always runs all tests.
3333

3434
### Test Env and Helpers
3535

@@ -43,6 +43,38 @@ test('should work', async () => {
4343

4444
Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.ts`.
4545

46+
### Extending the Test Suite
47+
48+
To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/packages/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L121):
49+
50+
```html
51+
<h2>?raw import</h2>
52+
<code class="raw"></code>
53+
```
54+
55+
This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L151):
56+
57+
```js
58+
import rawSvg from './nested/fragment.svg?raw'
59+
text('.raw', rawSvg)
60+
```
61+
62+
Where the `text` util is defined as:
63+
64+
```js
65+
function text(el, text) {
66+
document.querySelector(el).textContent = text
67+
}
68+
```
69+
70+
In the [spec tests](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
71+
72+
```js
73+
test('?raw import', async () => {
74+
expect(await page.textContent('.raw')).toMatch('SVG')
75+
})
76+
```
77+
4678
## Pull Request Guidelines
4779

4880
- Checkout a topic branch from a base branch, e.g. `main`, and merge back against that branch.

0 commit comments

Comments
 (0)