File tree Expand file tree Collapse file tree 2 files changed +24
-16
lines changed
Expand file tree Collapse file tree 2 files changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { defu } from 'defu'
1212import { createResolver , findPath } from '@nuxt/kit'
1313
1414import { applyEnv , loadKit } from './utils'
15+ import { NuxtVitestEnvironmentOptionsPlugin } from './module/plugins/options'
1516
1617interface GetVitestConfigOptions {
1718 nuxt : Nuxt
@@ -307,22 +308,7 @@ async function resolveConfig<T extends ViteUserConfig & { test?: VitestConfig }
307308 } ) satisfies ViteUserConfig & { test : NonNullable < T [ 'test' ] > } ,
308309 ) as T & { test : NonNullable < T [ 'test' ] > }
309310
310- const PLUGIN_NAME = 'nuxt:vitest:nuxt-environment-options'
311- const STUB_ID = 'nuxt-vitest-environment-options'
312- resolvedConfig . plugins ! . push ( {
313- name : PLUGIN_NAME ,
314- enforce : 'pre' ,
315- resolveId ( id ) {
316- if ( id . endsWith ( STUB_ID ) ) {
317- return STUB_ID
318- }
319- } ,
320- load ( id ) {
321- if ( id . endsWith ( STUB_ID ) ) {
322- return `export default ${ JSON . stringify ( resolvedConfig . test . environmentOptions || { } ) } `
323- }
324- } ,
325- } )
311+ resolvedConfig . plugins ! . push ( NuxtVitestEnvironmentOptionsPlugin ( resolvedConfig . test . environmentOptions ) )
326312
327313 if ( resolvedConfig . test . browser ?. enabled ) {
328314 if ( resolvedConfig . test . environment === 'nuxt' ) {
Original file line number Diff line number Diff line change 1+ import type { Plugin } from 'vite'
2+ import type { EnvironmentOptions } from 'vitest/node'
3+
4+ const PLUGIN_NAME = 'nuxt:vitest:nuxt-environment-options'
5+ const STUB_ID = 'nuxt-vitest-environment-options'
6+
7+ export function NuxtVitestEnvironmentOptionsPlugin ( environmentOptions : EnvironmentOptions = { } ) : Plugin {
8+ return {
9+ name : PLUGIN_NAME ,
10+ enforce : 'pre' ,
11+ resolveId ( id ) {
12+ if ( id . endsWith ( STUB_ID ) ) {
13+ return STUB_ID
14+ }
15+ } ,
16+ load ( id ) {
17+ if ( id . endsWith ( STUB_ID ) ) {
18+ return `export default ${ JSON . stringify ( environmentOptions || { } ) } `
19+ }
20+ } ,
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments