| 14 | |
| 15 | // this is only exported as a public function and not used inside vitest |
| 16 | export async function resolveConfig( |
| 17 | options: UserConfig = {}, |
| 18 | viteOverrides: ViteUserConfig = {}, |
| 19 | ): Promise<{ vitestConfig: ResolvedConfig; viteConfig: ResolvedViteConfig }> { |
| 20 | const root = slash(resolve(options.root || process.cwd())) |
| 21 | |
| 22 | const configPath |
| 23 | = options.config === false |
| 24 | ? false |
| 25 | : options.config |
| 26 | ? resolve(root, options.config) |
| 27 | : find.any(configFiles, { cwd: root }) |
| 28 | options.config = configPath |
| 29 | |
| 30 | const vitest = new Vitest('test', deepClone(options)) |
| 31 | const config = await resolveViteConfig( |
| 32 | mergeConfig( |
| 33 | { |
| 34 | configFile: configPath, |
| 35 | // this will make "mode": "test" | "benchmark" inside defineConfig |
| 36 | mode: options.mode || 'test', |
| 37 | plugins: [ |
| 38 | await VitestPlugin(options, vitest), |
| 39 | ], |
| 40 | }, |
| 41 | mergeConfig(viteOverrides, { root: options.root }), |
| 42 | ), |
| 43 | 'serve', |
| 44 | ) |
| 45 | // Reflect just to avoid type error |
| 46 | const updatedOptions = Reflect.get(config, '_vitest') as UserConfig |
| 47 | const vitestConfig = resolveVitestConfig( |
| 48 | vitest, |
| 49 | updatedOptions, |
| 50 | config, |
| 51 | ) |
| 52 | await vitest.close() |
| 53 | return { |
| 54 | viteConfig: config, |
| 55 | vitestConfig, |
| 56 | } |
| 57 | } |