Skip to content

Commit c0f06eb

Browse files
committed
02/06: add suffix-based test files pattern
1 parent 529810a commit c0f06eb

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

exercises/02.vitest-browser-mode/06.solution.multiple-workspaces/README.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
Problem: you may have unit tests and browser (integration) tests in the same project using Vitest.
44

55
1. Update `vite.config.ts` to include multiple [`workspaces`](https://main.vitest.dev/guide/workspace.html#configuration): one for unit tests, another for browser tests.
6+
1. Update TypeScript configs so different test patterns have different types (unit tests have no business accessing browser types).
67
1. Update `package.json` with `test:unit` and `test:integration` scripts. Show how to run different workspaces from the CLI.
8+
1. Install `@types/node` for unit tests.
79
1. List different strategies for separating tests: base on filename, base on directory.

exercises/02.vitest-browser-mode/06.solution.multiple-workspaces/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"references": [
44
{ "path": "./tsconfig.app.json" },
55
{ "path": "./tsconfig.node.json" },
6-
{ "path": "./tsconfig.test.json" }
6+
{ "path": "./tsconfig.test.unit.json" },
7+
{ "path": "./tsconfig.test.browser.json" }
78
]
89
}

exercises/02.vitest-browser-mode/06.solution.multiple-workspaces/tsconfig.test.json renamed to exercises/02.vitest-browser-mode/06.solution.multiple-workspaces/tsconfig.test.browser.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.base.json",
3-
"include": ["vite.config.ts", "**/*.test.ts*"],
3+
"include": ["vite.config.ts", "**/*.browser.test.ts*"],
44
"compilerOptions": {
55
"target": "esnext",
66
"module": "preserve",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": ["**/*.test.ts*"],
4+
"exclude": ["**/*.browser.test.ts*"],
5+
"compilerOptions": {
6+
"target": "esnext",
7+
"module": "preserve",
8+
"types": ["node"]
9+
}
10+
}

exercises/02.vitest-browser-mode/06.solution.multiple-workspaces/vite.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export default defineConfig({
1010
extends: true,
1111
test: {
1212
name: 'unit',
13-
include: ['**/*.test.ts'],
13+
include: ['**/*.test.tsx?'],
14+
environment: 'node',
1415
},
1516
},
1617
{
1718
extends: true,
1819
test: {
1920
name: 'browser',
21+
include: ['**/*.browser.test.tsx?'],
2022
browser: {
2123
enabled: true,
2224
provider: 'playwright',

0 commit comments

Comments
 (0)