From be31a95c53f5360dd54ea37a673f46301d6c4d1d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 8 Oct 2024 20:33:19 +0200 Subject: [PATCH] fix(nuxt): prevent 404 when hitting component test endpoint --- packages/nuxt/src/pages/module.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 3cb562dc88..0e1cd131c0 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -414,8 +414,18 @@ export default defineNuxtModule({ }) } + const componentStubPath = await resolvePath(resolve(runtimeDir, 'component-stub')) + if (nuxt.options.test && nuxt.options.dev) { + // add component testing route so 404 won't be triggered + nuxt.hook('pages:extend', (routes) => { + routes.push({ + _sync: true, + path: '/__nuxt_component_test__/:pathMatch(.*)', + file: componentStubPath, + }) + }) + } if (nuxt.options.experimental.appManifest) { - const componentStubPath = await resolvePath(resolve(runtimeDir, 'component-stub')) // Add all redirect paths as valid routes to router; we will handle these in a client-side middleware // when the app manifest is enabled. nuxt.hook('pages:extend', (routes) => {