Skip to content

Commit 342b567

Browse files
committed
docs(swc): apply pr suggestions
1 parent e62eec1 commit 342b567

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

content/recipes/swc.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ If your ORM does not provide a similar workaround, you can define the wrapper ty
9595
*/
9696
export type WrapperType<T> = T; // WrapperType === Relation
9797
```
98+
9899
### Vitest
99100

100101
[Vitest](https://vitest.dev/) is a fast and lightweight test runner designed to work with Vite. It provides a modern, fast, and easy-to-use testing solution that can be integrated with NestJS projects.
@@ -113,23 +114,14 @@ Create a vitest.config.ts file in the root directory of your application with th
113114

114115
```ts
115116
import swc from 'unplugin-swc';
116-
import { defineConfig } from 'vite';
117+
import { defineConfig } from 'vitest/config';
117118

118119
export default defineConfig({
119120
test: {
120121
globals: true,
121-
alias: {
122-
'@src': './src',
123-
'@test': './test',
124-
},
125122
root: './',
126123
},
127-
resolve: {
128-
alias: {
129-
'@src': './src',
130-
'@test': './test',
131-
},
132-
},
124+
133125
plugins: [swc.vite()], // This is required to build the test files with SWC
134126
});
135127
```
@@ -139,7 +131,23 @@ file for e2e tests, with an additional field `include` that specifies the test p
139131

140132
```ts
141133
import swc from 'unplugin-swc';
142-
import { defineConfig } from 'vite';
134+
import { defineConfig } from 'vitest/config';
135+
136+
export default defineConfig({
137+
test: {
138+
include: ['**/*.e2e-spec.ts'],
139+
globals: true,
140+
root: './',
141+
},
142+
plugins: [swc.vite()],
143+
});
144+
```
145+
146+
Additionaly, you can set `include` and `alias` options to support typescript paths in your tests:
147+
148+
```ts
149+
import swc from 'unplugin-swc';
150+
import { defineConfig } from 'vitest/config';
143151

144152
export default defineConfig({
145153
test: {
@@ -174,11 +182,13 @@ Lastly, update the test scripts in your package.json file to the following:
174182
"test:watch": "vitest",
175183
"test:cov": "vitest run --coverage",
176184
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --threads=false",
177-
"test:e2e": "vitest run -c ./vitest.config.e2e.ts"
185+
"test:e2e": "vitest run --config ./vitest.config.e2e.ts"
178186
}
179187
}
180188
```
189+
181190
These scripts configure Vitest for running tests, watching for changes, generating code coverage reports, and debugging. The test:e2e script is specifically for running E2E tests with a custom configuration file.
182191

183192
With this setup, you can now enjoy the benefits of using Vitest in your NestJS project, including faster test execution and a more modern testing experience.
193+
184194
> info **Hint** You can check out a working example in this [repository](https://github.com/TrilonIO/nest-vitest)

0 commit comments

Comments
 (0)