[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

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

fix(browser): failing to load vitest/utils (#3190)

authored by

Joaquín Sánchez and committed by
GitHub
(May 3, 2023, 11:23 AM +0200) 78bad4ab 036de797

+40 -14
+2 -2
packages/browser/src/client/main.ts
··· 22 22 23 23 let config: ResolvedConfig | undefined 24 24 let runner: VitestRunner | undefined 25 - const browserHashMap = new Map<string, string>() 25 + const browserHashMap = new Map<string, [test: boolean, timestamp: string]>() 26 26 27 27 const url = new URL(location.href) 28 28 const testId = url.searchParams.get('id') || 'unknown' ··· 130 130 }) 131 131 132 132 const now = `${new Date().getTime()}` 133 - files.forEach(i => browserHashMap.set(i, now)) 133 + files.forEach(i => browserHashMap.set(i, [true, now])) 134 134 135 135 for (const file of files) 136 136 await startTests([file], runner)
+10 -9
packages/browser/src/client/runner.ts
··· 4 4 5 5 interface BrowserRunnerOptions { 6 6 config: ResolvedConfig 7 - browserHashMap: Map<string, string> 7 + browserHashMap: Map<string, [test: boolean, timstamp: string]> 8 8 } 9 9 10 10 interface CoverageHandler { ··· 14 14 export function createBrowserRunner(original: any, coverageModule: CoverageHandler | null) { 15 15 return class BrowserTestRunner extends original { 16 16 public config: ResolvedConfig 17 - hashMap = new Map<string, string>() 17 + hashMap = new Map<string, [test: boolean, timstamp: string]>() 18 18 19 19 constructor(options: BrowserRunnerOptions) { 20 20 super(options.config) ··· 54 54 } 55 55 56 56 async importFile(filepath: string) { 57 - const match = filepath.match(/^(\w:\/)/) 58 - let hash = this.hashMap.get(filepath) 59 - if (!hash) { 57 + let [test, hash] = this.hashMap.get(filepath) ?? [false, ''] 58 + if (hash === '') { 60 59 hash = Date.now().toString() 61 - this.hashMap.set(filepath, hash) 60 + this.hashMap.set(filepath, [false, hash]) 62 61 } 63 - const importpath = match 64 - ? `/@fs/${filepath.slice(match[1].length)}?v=${hash}` 65 - : `${filepath}?v=${hash}` 62 + 63 + // on Windows we need the unit to resolve the test file 64 + const importpath = /^\w:/.test(filepath) 65 + ? `/@fs/${filepath}?${test ? 'browserv' : 'v'}=${hash}` 66 + : `${filepath}?${test ? 'browserv' : 'v'}=${hash}` 66 67 await import(importpath) 67 68 } 68 69 }
+28 -3
packages/browser/src/node/index.ts
··· 41 41 config() { 42 42 return { 43 43 optimizeDeps: { 44 - exclude: [...polyfills, ...builtinModules], 44 + exclude: [ 45 + ...polyfills, 46 + ...builtinModules, 47 + 'vitest', 48 + 'vitest/utils', 49 + 'vitest/browser', 50 + 'vitest/runners', 51 + '@vitest/utils', 52 + ], 53 + include: [ 54 + '@vitest/utils > concordance', 55 + '@vitest/utils > loupe', 56 + '@vitest/utils > pretty-format', 57 + 'vitest > chai', 58 + ], 45 59 }, 46 60 } 47 61 }, 48 62 async resolveId(id) { 49 - if (!builtinModules.includes(id) && !polyfills.includes(id) && !id.startsWith('node:')) 50 - return 63 + if (!builtinModules.includes(id) && !polyfills.includes(id) && !id.startsWith('node:')) { 64 + if (!/\?browserv=\w+$/.test(id)) 65 + return 66 + 67 + let useId = id.slice(0, id.lastIndexOf('?')) 68 + if (useId.startsWith('/@fs/')) 69 + useId = useId.slice(5) 70 + 71 + if (/^\w:/.test(useId)) 72 + useId = useId.replace(/\\/g, '/') 73 + 74 + return useId 75 + } 51 76 52 77 id = normalizeId(id) 53 78 return { id: await polyfillPath(id), moduleSideEffects: false }