[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(vite-node): top-level throw in module is not reported properly (#6840)

Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>

authored by

vanaigr
Hiroshi Ogawa
and committed by
GitHub
(Nov 5, 2024, 12:25 PM +0100) cf0cbf6a 487c80ae

+26 -2
+11
test/vite-node/src/hmr-throw.js
··· 1 + if (import.meta.hot) { 2 + import.meta.hot.accept(() => {}) 3 + if (import.meta.hot.data.value == null) { 4 + import.meta.hot.data.value = 0 5 + } 6 + else { 7 + // eslint-disable-next-line no-throw-literal 8 + throw 'some error' 9 + } 10 + } 11 + console.error('ready')
+13
test/vite-node/test/hmr.test.ts
··· 15 15 await viteNode.waitForStderr('Accept') 16 16 await viteNode.waitForStdout(`[vite-node] hot updated: ${scriptFile}`) 17 17 }) 18 + 19 + test('can handle top-level throw in self-accepting module', async () => { 20 + const scriptFile = resolve(__dirname, '../src/hmr-throw.js') 21 + 22 + const { viteNode } = await runViteNodeCli('--watch', scriptFile) 23 + 24 + await viteNode.waitForStderr('ready') 25 + 26 + editFile(scriptFile, content => `${content}\nconsole.error("done")`) 27 + 28 + await viteNode.waitForStderr('some error') 29 + await viteNode.waitForStderr(`[hmr] Failed to reload ${scriptFile}. This could be due to syntax errors or importing non-existent modules. (see errors above)`) 30 + })
+2 -2
packages/vite-node/src/hmr/hmr.ts
··· 160 160 } 161 161 } 162 162 163 - function warnFailedFetch(err: Error, path: string | string[]) { 164 - if (!err.message.match('fetch')) { 163 + function warnFailedFetch(err: unknown, path: string | string[]) { 164 + if (!(err instanceof Error) || !err.message.match('fetch')) { 165 165 console.error(err) 166 166 } 167 167