You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/contributing.md
+33-1Lines changed: 33 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Each test can be run under either dev server mode or build mode.
29
29
30
30
- 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.
31
31
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.
Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.ts`.
45
45
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
+
<codeclass="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
+
importrawSvgfrom'./nested/fragment.svg?raw'
59
+
text('.raw', rawSvg)
60
+
```
61
+
62
+
Where the `text` util is defined as:
63
+
64
+
```js
65
+
functiontext(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:
0 commit comments