Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Nov 20, 2023
1 parent 326aaef commit caf4d82
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/nuxt-vitest/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
53 changes: 35 additions & 18 deletions src/vitest-environment-nuxt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -108,25 +112,38 @@ export default <Environment>{
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`)
Expand Down
12 changes: 6 additions & 6 deletions src/vitest-environment-nuxt/runtime/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ export async function mountSuspended<T>(
...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<string, any>) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ it('should support export default that returns render function', async () => {
<h1>ExportDefaultReturnsRenderComponent</h1><pre>Hello nuxt-vitest</pre><pre>XHello nuxt-vitest</pre>
</div>"
`)
})
})

0 comments on commit caf4d82

Please sign in to comment.