From 59bc78a28f97c0e477f7379e020e1632229237d3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 2 Nov 2026 08:55:35 +0000 Subject: [PATCH] fix(config): override `NODE_ENV` in the client environment --- .../app5/test/nuxt/emitted.spec.ts | 14 ++++++++++++++ src/config.ts | 11 ++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 examples/app-vitest-workspace/app5/test/nuxt/emitted.spec.ts diff --git a/examples/app-vitest-workspace/app5/test/nuxt/emitted.spec.ts b/examples/app-vitest-workspace/app5/test/nuxt/emitted.spec.ts new file mode 100644 index 000000000..7adb26282 --- /dev/null +++ b/examples/app-vitest-workspace/app5/test/nuxt/emitted.spec.ts @@ -0,0 +1,14 @@ +import { defineComponent, h } from 'vue' +import { describe, expect, it } from 'vitest' +import { mountSuspended } from '@nuxt/test-utils/runtime' + +describe('emitted', () => { + it('records events emitted by the mounted component', async () => { + const component = await mountSuspended(defineComponent({ + emits: ['ping'], + setup: (_, { emit }) => () => h('button', { onClick: () => emit('ping', 1) }), + })) + await component.find('button').trigger('click') + expect(component.emitted('ping')).toEqual([[1]]) + }) +}) diff --git a/src/config.ts b/src/config.ts index de0ed9df2..cb828281b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -158,13 +158,18 @@ export async function getVitestConfigFromNuxt( const h3Version = h3Info?.version ?? 1 const h3Entry = h3Info && resolveModulePath(h3Version === 2 ? 'h3/generic' : 'h3', { from: `${h3Info.rootPath}/`, try: true }) + const define = { + 'process.env.NODE_ENV': '"test"', + '__NUXT_VITEST_RESOLVED__': 'true', + } + const resolver = createResolver(import.meta.url) const resolvedConfig = defu( // overrides { - define: { - 'process.env.NODE_ENV': '"test"', - '__NUXT_VITEST_RESOLVED__': 'true', + define, + ...options.viteConfig.environments?.client && { + environments: { client: { define } }, }, resolve: { alias: {