-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathvitest.shared.ts
More file actions
45 lines (43 loc) · 1.79 KB
/
Copy pathvitest.shared.ts
File metadata and controls
45 lines (43 loc) · 1.79 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
import swc from 'unplugin-swc';
import { defineConfig, type ViteUserConfig } from 'vitest/config';
// @automapper/* resolve via the pnpm workspace symlinks + each package's
// `exports` (source index.ts) — no explicit aliases needed, mirroring the tsc
// project-references setup (the tsconfig.base.json `paths` were dropped too).
// Single source of truth for every package's Vitest config.
//
// swc transpiles TS + *legacy* decorators with emitDecoratorMetadata, so the
// @AutoMap()/reflect-metadata path keeps emitting `design:type` exactly like
// ts-jest did — and, unlike ts-jest, it is fully decoupled from the installed
// TypeScript version (this is why Vitest lands before the TS 6 bump).
//
// keepClassNames is required: the mapper uses `constructor.name` as a model
// identifier, so swc must not mangle class names.
export function vitestConfig(testOverrides: ViteUserConfig['test'] = {}) {
return defineConfig({
// unplugin-swc owns TypeScript transformation for legacy decorator
// metadata, so disable Vite's Oxc transform instead of the obsolete
// esbuild-only path configured by the plugin.
oxc: false,
plugins: [
swc.vite({
jsc: {
parser: { syntax: 'typescript', decorators: true },
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
target: 'es2022',
keepClassNames: true,
},
}),
],
test: {
globals: true,
environment: 'node',
setupFiles: ['reflect-metadata'],
include: ['src/**/*.spec.ts'],
passWithNoTests: true,
...testOverrides,
},
});
}