[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
nuxt nuxt-module testing unit-testing vitest
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: remove stray file

Daniel Roe (Nov 30, 2022, 5:12 PM UTC) b8240fb0 05992fa9

-59
-59
src/runtime/window.ts
··· 1 - import { createFetch } from 'ohmyfetch' 2 - import { App, createApp, defineEventHandler, toNodeListener } from 'h3' 3 - import { 4 - createCall, 5 - createFetch as createLocalFetch, 6 - } from 'unenv/runtime/fetch/index' 7 - 8 - // @ts-expect-error undeclared property on window 9 - window.__NUXT__ = { 10 - serverRendered: false, 11 - config: { 12 - public: {}, 13 - app: { baseURL: '/' }, 14 - }, 15 - data: {}, 16 - state: {}, 17 - } 18 - 19 - const app = document.createElement('div') 20 - document.body.appendChild(app) 21 - 22 - // Workaround for happy-dom bug 23 - const { querySelector } = document 24 - app.id = 'nuxt' 25 - function qsWrapper (selectors) { 26 - if (selectors === '#__nuxt') selectors = '#nuxt' 27 - return querySelector(selectors) 28 - } 29 - document.querySelector = qsWrapper 30 - 31 - const h3App = createApp() 32 - 33 - const localCall = createCall(toNodeListener(h3App)) 34 - const localFetch = createLocalFetch(localCall, globalThis.fetch) 35 - 36 - const registry = new Set<string>() 37 - 38 - window.fetch = (init, options) => { 39 - if (typeof init === 'string' && registry.has(init)) { 40 - init = '/_' + init 41 - } 42 - return localFetch(init, options) 43 - } 44 - window.$fetch = createFetch({ fetch: window.fetch }) 45 - 46 - window.__registry = registry 47 - window.__app = h3App 48 - 49 - declare global { 50 - interface Window { 51 - __app: App 52 - __registry: Set<string> 53 - } 54 - } 55 - 56 - export {} 57 - 58 - // @ts-expect-error nuxt alias 59 - await import('#app/entry')