-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Expand file tree
/
Copy pathvitest.config.mts
More file actions
65 lines (63 loc) · 2.08 KB
/
Copy pathvitest.config.mts
File metadata and controls
65 lines (63 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { existsSync } from 'fs';
import type { Plugin } from 'vite';
import { defineConfig } from 'vitest/config';
/**
* Resolves `.js` imports to `.ts` source files when both exist side-by-side.
*
* The NestJS monorepo keeps compiled `.js` output next to the `.ts` sources.
* Without this plugin, Vite resolves `import '…/foo.js'` to the compiled JS
* instead of the original TypeScript source.
*/
function resolveTypescriptSource(): Plugin {
return {
name: 'resolve-ts-source',
enforce: 'pre',
async resolveId(source, importer, options) {
if (!importer) return null;
const resolved = await this.resolve(source, importer, {
...options,
skipSelf: true,
});
if (resolved && !resolved.external && resolved.id.endsWith('.js')) {
const tsPath = resolved.id.replace(/\.js$/, '.ts');
if (existsSync(tsPath)) return tsPath;
}
return null;
},
};
}
export default defineConfig({
// Spec files are excluded from every tsconfig in the repo, so Oxc cannot pick
// up `experimentalDecorators`/`emitDecoratorMetadata` from them and would emit
// TC39 decorators (which reject parameter decorators). Configure them here.
oxc: {
decorator: {
legacy: true,
emitDecoratorMetadata: true,
},
assumptions: {
setPublicClassFields: true,
},
typescript: {
removeClassFieldsWithoutInitializer: true,
},
},
test: {
globals: true,
root: './',
include: ['packages/**/*.spec.ts'],
alias: {
'@nestjs/common': './packages/common',
'@nestjs/core': './packages/core',
'@nestjs/microservices': './packages/microservices',
'@nestjs/websockets': './packages/websockets',
'@nestjs/testing': './packages/testing',
'@nestjs/platform-express': './packages/platform-express',
'@nestjs/platform-ws': './packages/platform-ws',
'@nestjs/platform-fastify': './packages/platform-fastify',
'@nestjs/platform-socket.io': './packages/platform-socket.io',
},
setupFiles: ['reflect-metadata'],
},
plugins: [resolveTypescriptSource()],
});