Skip to content

Commit 87bb8f4

Browse files
authored
fix(module-runner): support getBuiltins (#8746)
1 parent 87108db commit 87bb8f4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/vitest/src/runtime/moduleRunner/moduleTransport.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { FetchFunction, ModuleRunnerTransport } from 'vite/module-runner'
22
import type { ResolveFunctionResult } from '../../types/general'
3+
import { builtinModules } from 'node:module'
34

45
export interface VitestTransportOptions {
56
fetchModule: FetchFunction
67
resolveId: (id: string, importer?: string) => Promise<ResolveFunctionResult | null>
78
}
89

10+
const nodeBuiltins = builtinModules.filter(id => !id.includes(':'))
11+
912
export class VitestTransport implements ModuleRunnerTransport {
1013
constructor(private options: VitestTransportOptions) {}
1114

@@ -20,6 +23,9 @@ export class VitestTransport implements ModuleRunnerTransport {
2023
if (name !== 'fetchModule') {
2124
return { error: new Error(`Unknown method: ${name}. Expected "fetchModule".`) }
2225
}
26+
if (name === 'getBuiltins') {
27+
return { result: [...nodeBuiltins, /^node:/] }
28+
}
2329
try {
2430
const result = await this.options.fetchModule(...data as Parameters<FetchFunction>)
2531
return { result }

0 commit comments

Comments
 (0)