fix(vite-node): stub /@vite/client by default

This commit is contained in:
Anthony Fu 2022-01-19 04:26:23 +08:00
parent 53633b710b
commit 9ef599774c
2 changed files with 16 additions and 16 deletions

View File

@ -5,6 +5,19 @@ import { dirname, resolve } from 'pathe'
import { isPrimitive, normalizeId, slash, toFilePath } from './utils'
import type { ModuleCache, ViteNodeRunnerOptions } from './types'
export const DEFAULT_REQUEST_STUBS = {
'/@vite/client': {
injectQuery: (id: string) => id,
createHotContext() {
return {
accept: () => {},
prune: () => {},
}
},
updateStyle() {},
},
}
export class ViteNodeRunner {
root: string
@ -51,8 +64,9 @@ export class ViteNodeRunner {
return this.cachedRequest(dep, callstack)
}
if (this.options.requestStubs && id in this.options.requestStubs)
return this.options.requestStubs[id]
const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS
if (id in requestStubs)
return requestStubs[id]
const { code: transformed, externalize } = await this.options.fetchModule(id)
if (externalize) {

View File

@ -24,20 +24,6 @@ export class VitestRunner extends ViteNodeRunner {
constructor(public options: ExecuteOptions) {
super(options)
options.requestStubs = options.requestStubs || {
'/@vite/client': {
injectQuery: (id: string) => id,
createHotContext() {
return {
accept: () => {},
prune: () => {},
}
},
updateStyle() {},
},
}
this.mocker = createMocker(this.root, options.mockMap)
}