Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
···11import { loadNuxt, buildNuxt } from '@nuxt/kit'
22-import { InlineConfig as VitestConfig } from 'vitest'
33-import { InlineConfig } from 'vite'
22+import type { InlineConfig as VitestConfig } from 'vitest'
33+import type { InlineConfig } from 'vite'
4455// https://github.com/nuxt/framework/issues/6496
66async function getViteConfig (rootDir = process.cwd()) {
+6-4
src/index.ts
···11import type { Environment } from 'vitest'
22import { Window, GlobalWindow } from 'happy-dom'
33-import { createFetch } from 'ohmyfetch'
44-import { App, createApp, toNodeListener } from 'h3'
33+import { createFetch } from 'ofetch'
44+import { createApp, toNodeListener } from 'h3'
55+import type { App } from 'h3'
56import {
67 createCall,
78 createFetch as createLocalFetch,
···50515152 const registry = new Set<string>()
52535353- win.fetch = (init, options) => {
5454+ win.fetch = (init: string, options?: any) => {
5455 if (typeof init === 'string' && registry.has(init)) {
5556 init = '/_' + init
5657 }
···65666667 const { keys, originals } = populateGlobal(global, win, { bindFunctions: true })
67686868- // @ts-expect-error nuxt alias
6969 await import('#app/entry')
70707171 return {
7272 // called after all tests with this env have been run
7373 teardown () {
7474 win.happyDOM.cancelAsync()
7575+ // @ts-expect-error
7576 keys.forEach(key => delete global[key])
7777+ // @ts-expect-error
7678 originals.forEach((v, k) => global[k] = v)
7779 }
7880 }
+5-1
src/runtime/mock.ts
···11-import { defineEventHandler, EventHandler } from 'h3'
11+import { defineEventHandler } from 'h3'
22+import type { EventHandler } from 'h3'
2334export function registerEndpoint (url: string, handler: EventHandler) {
55+ // @ts-expect-error private property
46 if (!window.__app) return
77+ // @ts-expect-error private property
58 window.__app.use('/_' + url, defineEventHandler(handler))
99+ // @ts-expect-error private property
610 window.__registry.add(url)
711}