From 37ac042677d9abef561f8cb365b742ea8d27d40e Mon Sep 17 00:00:00 2001 From: Nicolas Payot Date: Tue, 21 May 2024 18:35:07 +0200 Subject: [PATCH 1/2] feat: add multi-app support for global var __NUXT__ --- src/config.ts | 4 ++++ src/environments/vitest/index.ts | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) 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..3ab7046c8 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,16 @@ 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 From f005fddfedeb020acc0817c76ba262a7c4aeb661 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 22 May 2024 08:51:11 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- src/environments/vitest/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/environments/vitest/index.ts b/src/environments/vitest/index.ts index 3ab7046c8..98738cc64 100644 --- a/src/environments/vitest/index.ts +++ b/src/environments/vitest/index.ts @@ -46,10 +46,11 @@ export default { const multiApp = (environmentOptions?.future.multiApp as boolean) || false if (!multiApp) { win.__NUXT__ = __NUXT__ - } else { + } + else { const appId = environmentOptions?.appId || 'nuxt-app' win.__NUXT__ = { - [appId]: __NUXT__ + [appId]: __NUXT__, } }