1- import { defineConfig } from 'vitest/config' ;
2- import path from 'path' ;
1+ import { defineConfig , mergeConfig } from 'vitest/config' ;
32
4- export default defineConfig ( {
5- test : {
6- globals : true ,
7- environment : 'jsdom' ,
8- setupFiles : [ './vitest.setup.ts' ] ,
9- include : [ '**/*.test.{ts,tsx}' ] ,
10- coverage : {
11- provider : 'v8' ,
12- reporter : [ 'text' , 'json' , 'html' ] ,
13- reportsDirectory : '.coverage' ,
3+ import viteConfig from './vite.config' ;
4+
5+ export default mergeConfig (
6+ // Inherit the app's build config — `define`, `resolve.alias`, `envPrefix` —
7+ // so tests compile modules exactly like the app does and can't drift from it.
8+ // Plugins are dropped rather than merged: the router codegen, the legacy
9+ // polyfill pass and the bundle analyzer are build-time concerns that only
10+ // slow the runner down. `mergeConfig` concatenates arrays, so the reset has
11+ // to happen before the merge, not in the override below.
12+ { ...viteConfig , plugins : [ ] } ,
13+ defineConfig ( {
14+ // Pin the build stamp: vite.config.ts derives it from the git HEAD (or a
15+ // timestamp when .git is absent, as in the test container), which would
16+ // make every run compile to different output for no benefit.
17+ define : {
18+ __SOURCE_VERSION__ : JSON . stringify ( 'test' ) ,
1419 } ,
15- } ,
16- resolve : {
17- alias : {
18- '@' : path . resolve ( __dirname , './src' ) ,
20+ test : {
21+ globals : true ,
22+ environment : 'jsdom' ,
23+ setupFiles : [ './vitest.setup.ts' ] ,
24+ include : [ '**/*.test.{ts,tsx}' ] ,
25+ coverage : {
26+ provider : 'v8' ,
27+ reporter : [ 'text' , 'json' , 'html' ] ,
28+ reportsDirectory : '.coverage' ,
29+ } ,
1930 } ,
20- } ,
21- // Keep parity with vite.config.ts so tests can stub the NEXT_PUBLIC_*
22- // deprecated fallbacks via import.meta.env.
23- envPrefix : 'NEXT_PUBLIC_' ,
24- } ) ;
31+ } ) ,
32+ ) ;
0 commit comments