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: exercises/02.vitest-browser-mode/05.solution.multiple-workspaces/README.mdx
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ The first workspace include the configuration for running unit tests:
74
74
-`exclude` does the opposite of `include`, listing the file patterns to _ignore_. Since my browser tests also end with `*.test.ts`, I need to exclude them not to be confused with unit tests;
75
75
-`environment` controls the test environment used for this workspace. I want my unit tests to run in Node.js, so I provide `'node'` as the enivornment here.
76
76
77
-
> :owl: Notice that each workspace lists Vitest configuration starting from the root (e.g. includes the `test` key again). This is handy because this means each workspace can have a different set of Vite options to handle the test files (e.g. list different `plugins`).
77
+
> :owl: Notice that each workspace lists Vitest configuration starting from the root by including the `test` key again. This is handy because each workspace can have a different set of Vite options and `plugins` for different test files.
78
78
79
79
Similarly, here's the workspace for the browser (component) tests:
80
80
@@ -98,17 +98,17 @@ Similarly, here's the workspace for the browser (component) tests:
98
98
},
99
99
```
100
100
101
-
Here, I'm naming this workspace `'browser'` and configuring it to include only `*.browser.test.ts(x)` test files. Those will be my component tests. For the rest of it, I simply moved the existing `test.browser` configuration under this workspace and left it as-is.
101
+
Here, I'm naming this workspace `'browser'` and configuring it to include only `*.browser.test.ts(x)` test files. These will be my component tests. For the rest of the configuration, I simply moved the existing `test.browser` configuration under this workspace and left it as-is.
102
102
103
103
## TypeScript
104
104
105
-
The next step is to deal with TypeScript. One of the most overlooked aspects of using TypeScript is that you often need _multiple configurations_ within the same project. Your source code, unit tests, integration tests, or test utilities are all written in TypeScript but have different concerns that may require different types.
105
+
The next step is to deal with TypeScript. One of the most overlooked aspects of using TypeScript is that you often need _multiple configurations_ within the same project. Your source code, unit tests, integration tests, and test utilities are all written in TypeScript but have different concerns that may require different types.
106
106
107
107
> :scroll: If you want to dive deeper into the reason behing using multiple TypeScript configurations and how to do that properly, read my post called [One Thing Nobody Explained To You About TypeScript](https://kettanaito.com/blog/one-thing-nobody-explained-to-you-about-typescript).
108
108
109
-
In our project, unit and component tests have a different set of type requirements because they run in different environments. This means I need to introduce two separate configurations: `tsconfig.test.unit.json` and `tsconfig.test.browser.json` to address those differences.
109
+
In our project, unit and component tests have a different set of type requirements because they run in different environments. This means I need to introduce two separate configurations to address these differences: `tsconfig.test.unit.json` and `tsconfig.test.browser.json`.
110
110
111
-
Let's start with the unit tests.
111
+
Let's start with the unit tests:
112
112
113
113
```json filename=tsconfig.test.unit.json
114
114
{
@@ -129,7 +129,7 @@ Similar to how I've configured Vitest workspaces to apply only to specific file
129
129
"types": ["node", "vitest/globals"]
130
130
```
131
131
132
-
This include Node.js type definitions (`@types/node`) and Vitest global types (e.g. `test` and `expect`) for my unit tests. Since I don't have the Node.js types installed, I need to add them as a dependency to the project:
132
+
This includes Node.js type definitions (`@types/node`) and Vitest global types (e.g. `test` and `expect`) for my unit tests. Since I don't have the Node.js types installed, I need to add them as a dependency to the project:
133
133
134
134
```sh nonumber
135
135
npm i -D @types/node
@@ -151,7 +151,7 @@ Next, I rename the existing `tsconfig.test.json` to `tsconfig.test.browser.json`
151
151
152
152
## Test commands
153
153
154
-
To make it easier to run specific types of tests, I will modify `package.json` to include the new`test:unit` and `test:integration` commands:
154
+
To make it easier to run specific types of tests, I will modify `package.json` to add`test:unit` and `test:integration` commands:
155
155
156
156
```json
157
157
{
@@ -170,4 +170,4 @@ There are multiple ways to group different types of tests in the same project:
170
170
-**By file name**. This is the one I'm using this exercise, adopting `*.test.ts` for unit tests and `*.browser.test.tsx` for integration tests;
171
171
-**By directory name**. For example, you can keep unit tests in `./src` while integration tests in `./tests`
172
172
173
-
The only wrong choice here is the one not followed consistently. You can choose whichever approach makes more sense in your circumstance, but I don't recommend mixing them in the same app.
173
+
The choice is up to you — I only recommend you stick to one approach and don't mix them in your app.
0 commit comments