diff --git a/src/nuxt-vitest/config.ts b/src/nuxt-vitest/config.ts index 3099edbed..f7e4b1557 100644 --- a/src/nuxt-vitest/config.ts +++ b/src/nuxt-vitest/config.ts @@ -121,7 +121,11 @@ export async function getVitestConfigFromNuxt( }, }, nuxtRuntimeConfig: options.nuxt.options.runtimeConfig, - nuxtRouteRules: defu({}, options.nuxt.options.routeRules, options.nuxt.options.nitro?.routeRules) + nuxtRouteRules: defu( + {}, + options.nuxt.options.routeRules, + options.nuxt.options.nitro?.routeRules + ), }, environmentMatchGlobs: [ ['**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', 'nuxt'], diff --git a/src/vitest-environment-nuxt/index.ts b/src/vitest-environment-nuxt/index.ts index 103bcb44e..023d3e18a 100644 --- a/src/vitest-environment-nuxt/index.ts +++ b/src/vitest-environment-nuxt/index.ts @@ -3,7 +3,11 @@ import { createFetch } from 'ofetch' import { indexedDB } from 'fake-indexeddb' import { joinURL } from 'ufo' import { createApp, defineEventHandler, toNodeListener } from 'h3' -import { createRouter as createRadixRouter, exportMatcher, toRouteMatcher } from 'radix3' +import { + createRouter as createRadixRouter, + exportMatcher, + toRouteMatcher, +} from 'radix3' import { populateGlobal } from 'vitest/environments' import { createCall, @@ -108,25 +112,38 @@ export default { createRadixRouter({ routes: environmentOptions.nuxtRouteRules || {} }) ) const matcher = exportMatcher(routeRulesMatcher) - const manifestOutputPath = joinURL('/', environmentOptions?.nuxtRuntimeConfig.app?.buildAssetsDir || '_nuxt', 'builds') + const manifestOutputPath = joinURL( + '/', + environmentOptions?.nuxtRuntimeConfig.app?.buildAssetsDir || '_nuxt', + 'builds' + ) const manifestBaseRoutePath = joinURL('/_', manifestOutputPath) - h3App.use(`${manifestBaseRoutePath}/latest.json`, defineEventHandler(() => ({ - id: 'test', - timestamp - }))) - h3App.use(`${manifestBaseRoutePath}/meta/test.json`, defineEventHandler(() => ({ - id: 'test', - timestamp, - matcher, - prerendered: [] - }))) - h3App.use(`${manifestBaseRoutePath}/meta/dev.json`, defineEventHandler(() => ({ - id: 'test', - timestamp, - matcher, - prerendered: [] - }))) + h3App.use( + `${manifestBaseRoutePath}/latest.json`, + defineEventHandler(() => ({ + id: 'test', + timestamp, + })) + ) + h3App.use( + `${manifestBaseRoutePath}/meta/test.json`, + defineEventHandler(() => ({ + id: 'test', + timestamp, + matcher, + prerendered: [], + })) + ) + h3App.use( + `${manifestBaseRoutePath}/meta/dev.json`, + defineEventHandler(() => ({ + id: 'test', + timestamp, + matcher, + prerendered: [], + })) + ) registry.add(`${manifestOutputPath}/latest.json`) registry.add(`${manifestOutputPath}/meta/test.json`) diff --git a/src/vitest-environment-nuxt/runtime/mount.ts b/src/vitest-environment-nuxt/runtime/mount.ts index 235276bdd..76c9c2694 100644 --- a/src/vitest-environment-nuxt/runtime/mount.ts +++ b/src/vitest-environment-nuxt/runtime/mount.ts @@ -85,13 +85,13 @@ export async function mountSuspended( ...component, render: render ? (_ctx: any, ...args: any[]) => { - // add all _ctx properties to renderContext - // the renderContext must remain intact, otherwise the emits don't work - for (const key in _ctx) { - renderContext[key] = _ctx[key] + // add all _ctx properties to renderContext + // the renderContext must remain intact, otherwise the emits don't work + for (const key in _ctx) { + renderContext[key] = _ctx[key] + } + return render.apply(_ctx, [renderContext, ...args]) } - return render.apply(_ctx, [renderContext, ...args]) - } : undefined, setup: setup ? (props: Record) => diff --git a/test/fixtures/nuxt-vitest/tests/nuxt/export-define-component.spec.ts b/test/fixtures/nuxt-vitest/tests/nuxt/export-define-component.spec.ts index a0892a60b..75d17bc69 100644 --- a/test/fixtures/nuxt-vitest/tests/nuxt/export-define-component.spec.ts +++ b/test/fixtures/nuxt-vitest/tests/nuxt/export-define-component.spec.ts @@ -55,4 +55,4 @@ it('should support export default that returns render function', async () => {

ExportDefaultReturnsRenderComponent

Hello nuxt-vitest
XHello nuxt-vitest
" `) -}) \ No newline at end of file +})