diff --git a/src/config.ts b/src/config.ts index f429c20c4..61d7331ff 100644 --- a/src/config.ts +++ b/src/config.ts @@ -101,6 +101,10 @@ export async function getVitestConfigFromNuxt( test: { dir: process.cwd(), environmentOptions: { + // @ts-expect-error will be available from nuxt@3.12.0 + appId: options.nuxt.options.appId, + experimental: defu({}, options.nuxt.options.experimental), + future: defu({}, options.nuxt.options.future), nuxtRuntimeConfig: applyEnv(structuredClone(options.nuxt.options.runtimeConfig), { prefix: 'NUXT_', env: await setupDotenv(defu(loadNuxtOptions.dotenv, { diff --git a/src/environments/vitest/index.ts b/src/environments/vitest/index.ts index d55da01e6..98738cc64 100644 --- a/src/environments/vitest/index.ts +++ b/src/environments/vitest/index.ts @@ -32,7 +32,7 @@ export default { win.__NUXT_VITEST_ENVIRONMENT__ = true - win.__NUXT__ = { + const __NUXT__ = { serverRendered: false, config: { public: {}, @@ -43,6 +43,17 @@ export default { state: {}, } + const multiApp = (environmentOptions?.future.multiApp as boolean) || false + if (!multiApp) { + win.__NUXT__ = __NUXT__ + } + else { + const appId = environmentOptions?.appId || 'nuxt-app' + win.__NUXT__ = { + [appId]: __NUXT__, + } + } + const app = win.document.createElement('div') // this is a workaround for a happy-dom bug with ids beginning with _ app.id = environmentOptions.nuxt.rootId