Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536const postfixRE = /[?#].*$/export function cleanUrl(url: string): string { return url.replace(postfixRE, '')}
export function createManualModuleSource( moduleUrl: string, exports: string[], globalAccessor = '"__vitest_mocker__"', method: 'getFactoryModule' | 'resolveFactoryModule' = 'getFactoryModule',): string { const source = `const __factoryModule__ = await globalThis[${globalAccessor}].${method}(${JSON.stringify(moduleUrl)});` const keys = exports .map((name, index) => { return `let __${index} = __factoryModule__[${JSON.stringify(name)}]export { __${index} as ${JSON.stringify(name)} }` }) .join('\n') let code = `${source}\n${keys}` // this prevents recursion code += `if (__factoryModule__.__factoryPromise != null) { __factoryModule__.__factoryPromise.then((resolvedModule) => { ${exports .map((name, index) => { return `__${index} = resolvedModule[${JSON.stringify(name)}];` }) .join('\n')} })} ` return code}