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
Unlike Jest, Vitest does not automatically resolve TypeScript path aliases like `src/`. This may lead to dependency resolution errors during testing. To resolve this issue, add the following `resolve.alias` configuration in your `vitest.config.ts` file:
338
+
339
+
```ts
340
+
import { resolve } from'path';
341
+
342
+
exportdefaultdefineConfig({
343
+
resolve: {
344
+
alias: {
345
+
'src': resolve(__dirname, './src'),
346
+
},
347
+
},
348
+
});
349
+
```
350
+
This ensures that Vitest correctly resolves module imports, preventing errors related to missing dependencies.
351
+
329
352
#### Update imports in E2E tests
330
353
331
354
Change any E2E test imports using `import * as request from 'supertest'` to `import request from 'supertest'`. This is necessary because Vitest, when bundled with Vite, expects a default import for supertest. Using a namespace import may cause issues in this specific setup.
@@ -344,6 +367,7 @@ Lastly, update the test scripts in your package.json file to the following:
344
367
}
345
368
```
346
369
370
+
347
371
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.
348
372
349
373
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.
0 commit comments