mirror of
https://github.com/nestjs/nest.git
synced 2026-10-28 09:45:43 +08:00
96 lines
3.2 KiB
TypeScript
96 lines
3.2 KiB
TypeScript
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,
|
|
* making coverage track the wrong file (and then excluded by `*.js` patterns).
|
|
*/
|
|
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',
|
|
},
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'json', 'clover', 'lcov'],
|
|
reportOnFailure: true,
|
|
include: ['packages/**/*.ts'],
|
|
exclude: [
|
|
'**/node_modules/**',
|
|
'**/*.d.ts',
|
|
'**/*.spec.ts',
|
|
'packages/**/test/**',
|
|
'packages/**/adapters/*.ts',
|
|
'packages/**/nest-*.ts',
|
|
'packages/core/errors/**/*',
|
|
'packages/common/exceptions/*.ts',
|
|
'packages/common/utils/load-package.util.ts',
|
|
'packages/microservices/exceptions/',
|
|
'packages/microservices/microservices-module.ts',
|
|
'packages/core/middleware/middleware-module.ts',
|
|
'packages/core/discovery/discovery-service.ts',
|
|
'packages/core/injector/module-ref.ts',
|
|
'packages/core/injector/instance-links-host.ts',
|
|
'packages/core/helpers/context-id-factory.ts',
|
|
'packages/websockets/socket-module.ts',
|
|
'packages/common/cache/**/*',
|
|
'packages/common/serializer/**/*',
|
|
'packages/common/services/*.ts',
|
|
],
|
|
},
|
|
setupFiles: ['reflect-metadata'],
|
|
// Allow tests to fail — we only want the coverage data
|
|
passWithNoTests: true,
|
|
},
|
|
plugins: [resolveTypescriptSource()],
|
|
});
|