mirror of
https://github.com/vitest-dev/vitest.git
synced 2026-02-01 17:36:51 +00:00
fix(vite-node): stub /@vite/client by default
This commit is contained in:
parent
53633b710b
commit
9ef599774c
@ -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) {
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user