Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
fix: mock app manifest if required (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Oct 3, 2023
1 parent 80ee333 commit 6113a07
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/nuxt-vitest/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export async function getVitestConfigFromNuxt(
...options.viteConfig.test?.environmentOptions?.nuxt,
},
nuxtRuntimeConfig: options.nuxt.options.runtimeConfig,
nuxtRouteRules: defu({}, options.nuxt.options.routeRules, options.nuxt.options.nitro?.routeRules)
},
environmentMatchGlobs: [
['**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', 'nuxt'],
Expand Down
1 change: 1 addition & 0 deletions packages/vitest-environment-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"local-pkg": "^0.4.3",
"magic-string": "^0.30.3",
"ofetch": "^1.3.3",
"radix3": "^1.1.0",
"ufo": "^1.3.0",
"unenv": "^1.7.4"
},
Expand Down
23 changes: 22 additions & 1 deletion packages/vitest-environment-nuxt/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Environment } from 'vitest'
import { createFetch } from 'ofetch'
import { joinURL } from 'ufo'
import { createApp, toNodeListener } from 'h3'
import { createApp, defineEventHandler, toNodeListener } from 'h3'
import { createRouter as createRadixRouter, exportMatcher, toRouteMatcher } from 'radix3'
import { populateGlobal } from 'vitest/environments'
import {
createCall,
Expand Down Expand Up @@ -93,6 +94,26 @@ export default <Environment>{
bindFunctions: true,
})

// App manifest support
const timestamp = Date.now()
const routeRulesMatcher = toRouteMatcher(
createRadixRouter({ routes: environmentOptions.nuxtRouteRules || {} })
)
const matcher = exportMatcher(routeRulesMatcher)
h3App.use('/_/_nuxt/builds/latest.json', defineEventHandler(() => ({
id: 'test',
timestamp
})))
h3App.use('/_/_nuxt/builds/meta/test.json', defineEventHandler(() => ({
id: 'test',
timestamp,
matcher,
prerendered: []
})))

registry.add('/_nuxt/builds/latest.json')
registry.add('/_nuxt/builds/meta/test.json')

// @ts-ignore
await import('#app/entry').then(r => r.default())

Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6113a07

Please sign in to comment.