[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): fix source map of inlined node_modules (#7557)

authored by

Hiroshi Ogawa and committed by
GitHub
(Mar 7, 2025, 9:50 AM +0100) 34aa322b 0fb21faa

+317 -1
+1
eslint.config.js
··· 23 23 'test/network-imports/public/slash@3.0.0.js', 24 24 'test/coverage-test/src/transpiled.js', 25 25 'test/coverage-test/src/original.ts', 26 + 'test/cli/deps/error/*', 26 27 'examples/**/mockServiceWorker.js', 27 28 'examples/sveltekit/.svelte-kit', 28 29 'packages/browser/**/esm-client-injector.js',
+8
pnpm-lock.yaml
··· 1099 1099 '@vitest/runner': 1100 1100 specifier: workspace:^ 1101 1101 version: link:../../packages/runner 1102 + '@vitest/test-dep-error': 1103 + specifier: file:./deps/error 1104 + version: file:test/cli/deps/error 1102 1105 '@vitest/utils': 1103 1106 specifier: workspace:* 1104 1107 version: link:../../packages/utils ··· 3940 3943 3941 3944 '@vitest/test-dep-conditions@file:test/config/deps/test-dep-conditions': 3942 3945 resolution: {directory: test/config/deps/test-dep-conditions, type: directory} 3946 + 3947 + '@vitest/test-dep-error@file:test/cli/deps/error': 3948 + resolution: {directory: test/cli/deps/error, type: directory} 3943 3949 3944 3950 '@vitest/test-dep1@file:test/core/deps/dep1': 3945 3951 resolution: {directory: test/core/deps/dep1, type: directory} ··· 12130 12136 '@vitest/test-dep-conditions@file:test/config/deps/test-dep-conditions': 12131 12137 dependencies: 12132 12138 '@vitest/test-dep-conditions-indirect': file:test/config/deps/test-dep-conditions-indirect 12139 + 12140 + '@vitest/test-dep-error@file:test/cli/deps/error': {} 12133 12141 12134 12142 '@vitest/test-dep1@file:test/core/deps/dep1': {} 12135 12143
+1
test/cli/package.json
··· 10 10 "@types/ws": "^8.5.9", 11 11 "@vitejs/plugin-basic-ssl": "^1.0.2", 12 12 "@vitest/runner": "workspace:^", 13 + "@vitest/test-dep-error": "file:./deps/error", 13 14 "@vitest/utils": "workspace:*", 14 15 "debug": "^4.3.4", 15 16 "unplugin-swc": "^1.4.4",
+1 -1
packages/vite-node/src/server.ts
··· 428 428 } 429 429 430 430 const sourcemap = this.options.sourcemap ?? 'inline' 431 - if (sourcemap === 'inline' && result && !id.includes('node_modules')) { 431 + if (sourcemap === 'inline' && result) { 432 432 result = await this.processTransformResult(filepath, result) 433 433 } 434 434
+28
test/cli/test/stacktraces.test.ts
··· 68 68 }) 69 69 }) 70 70 71 + describe('stacktrace in dependency package', () => { 72 + const root = resolve(__dirname, '../fixtures/stacktraces') 73 + const testFile = resolve(root, './error-in-package.test.js') 74 + 75 + it('external', async () => { 76 + const { stderr } = await runVitest({ 77 + root, 78 + }, [testFile]) 79 + expect(removeNodeModules(removeLines(stderr))).toMatchSnapshot() 80 + }) 81 + 82 + it('inline', async () => { 83 + const { stderr } = await runVitest({ 84 + root, 85 + server: { 86 + deps: { 87 + inline: [/@vitest\/test-dep-error/], 88 + }, 89 + }, 90 + }, [testFile]) 91 + expect(removeNodeModules(removeLines(stderr))).toMatchSnapshot() 92 + }) 93 + }) 94 + 71 95 it.runIf(major < 22)('stacktrace in vmThreads', async () => { 72 96 const root = resolve(__dirname, '../fixtures/stacktraces') 73 97 const testFile = resolve(root, './error-with-stack.test.js') ··· 81 105 82 106 function removeLines(log: string) { 83 107 return log.replace(/⎯{2,}/g, '⎯⎯') 108 + } 109 + 110 + function removeNodeModules(log: string) { 111 + return log.replace(/[^ ]*\/node_modules\//g, '(NODE_MODULES)/') 84 112 }
+11
test/cli/deps/error/index.js
··· 1 + import 'node:path' 2 + 3 + export default function testStack() { 4 + innerTestStack() 5 + } 6 + 7 + import 'node:util' 8 + 9 + function innerTestStack() { 10 + throw new Error('__TEST_STACK__') 11 + }
+9
test/cli/deps/error/package.json
··· 1 + { 2 + "name": "@vitest/test-dep-error", 3 + "type": "module", 4 + "private": true, 5 + "exports": { 6 + ".": "./index.js", 7 + "./*": "./*" 8 + } 9 + }
+9
test/cli/deps/error/transpiled-inline.js
··· 1 + import "node:path"; 2 + export default function testStack() { 3 + innerTestStack(); 4 + } 5 + import "node:util"; 6 + function innerTestStack() { 7 + throw new Error("__TEST_STACK_TRANSPILED_INLINE__"); 8 + } 9 + //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidHJhbnNwaWxlZC1pbmxpbmUudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImltcG9ydCAnbm9kZTpwYXRoJ1xuXG5leHBvcnQgdHlwZSBEdW1teSA9IHtcbiAgZm9vOiBcImZvb1wiLFxufVxuXG4vKipcbiAqIGR1bW15XG4gKiBkdW1teVxuICovXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiB0ZXN0U3RhY2soKSB7XG4gIGlubmVyVGVzdFN0YWNrKClcbn1cblxuaW1wb3J0ICdub2RlOnV0aWwnXG5cbi8qKlxuICogYmFyXG4gKiBiYXJcbiAqL1xuZnVuY3Rpb24gaW5uZXJUZXN0U3RhY2soKSB7XG4gIHRocm93IG5ldyBFcnJvcignX19URVNUX1NUQUNLX1RSQU5TUElMRURfSU5MSU5FX18nKVxufSJdLAogICJtYXBwaW5ncyI6ICJBQUFBLE9BQU87QUFVUCx3QkFBd0IsWUFBWTtBQUNsQyxpQkFBZTtBQUNqQjtBQUVBLE9BQU87QUFNUCxTQUFTLGlCQUFpQjtBQUN4QixRQUFNLElBQUksTUFBTSxrQ0FBa0M7QUFDcEQ7IiwKICAibmFtZXMiOiBbXQp9Cg==
+26
test/cli/deps/error/transpiled-inline.ts
··· 1 + import 'node:path' 2 + 3 + export type Dummy = { 4 + foo: "foo", 5 + } 6 + 7 + /** 8 + * dummy 9 + * dummy 10 + */ 11 + export default function testStack() { 12 + innerTestStack() 13 + } 14 + 15 + import 'node:util' 16 + 17 + /** 18 + * bar 19 + * bar 20 + */ 21 + function innerTestStack() { 22 + throw new Error('__TEST_STACK_TRANSPILED_INLINE__') 23 + } 24 + 25 + // transpiled-inline.js is copied from 26 + // https://esbuild.github.io/try/#dAAwLjI1LjAALS1sb2FkZXI9dHMgLS1zb3VyY2VtYXA9aW5saW5lIC0tc291cmNlZmlsZT10cmFuc3BpbGVkLWlubGluZS50cwBpbXBvcnQgJ25vZGU6cGF0aCcKCmV4cG9ydCB0eXBlIER1bW15ID0gewogIGZvbzogImZvbyIsCn0KCi8qKgogKiBkdW1teQogKiBkdW1teQogKi8KZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24gdGVzdFN0YWNrKCkgewogIGlubmVyVGVzdFN0YWNrKCkKfQoKaW1wb3J0ICdub2RlOnV0aWwnCgovKioKICogYmFyCiAqIGJhcgogKi8KZnVuY3Rpb24gaW5uZXJUZXN0U3RhY2soKSB7CiAgdGhyb3cgbmV3IEVycm9yKCdfX1RFU1RfU1RBQ0tfVFJBTlNQSUxFRF9JTkxJTkVfXycpCn0
+9
test/cli/deps/error/transpiled.js
··· 1 + import "node:path"; 2 + export default function testStack() { 3 + innerTestStack(); 4 + } 5 + import "node:util"; 6 + function innerTestStack() { 7 + throw new Error("__TEST_STACK_TRANSPILED__"); 8 + } 9 + //# sourceMappingURL=transpiled.js.map
+7
test/cli/deps/error/transpiled.js.map
··· 1 + { 2 + "version": 3, 3 + "sources": ["transpiled.ts"], 4 + "sourcesContent": ["import 'node:path'\n\nexport type Dummy = {\n foo: \"foo\",\n}\n\n/**\n * dummy\n * dummy\n */\nexport default function testStack() {\n innerTestStack()\n}\n\nimport 'node:util'\n\n/**\n * bar\n * bar\n */\nfunction innerTestStack() {\n throw new Error('__TEST_STACK_TRANSPILED__')\n}"], 5 + "mappings": "AAAA,OAAO;AAUP,wBAAwB,YAAY;AAClC,iBAAe;AACjB;AAEA,OAAO;AAMP,SAAS,iBAAiB;AACxB,QAAM,IAAI,MAAM,2BAA2B;AAC7C;", 6 + "names": [] 7 + }
+26
test/cli/deps/error/transpiled.ts
··· 1 + import 'node:path' 2 + 3 + export type Dummy = { 4 + foo: "foo", 5 + } 6 + 7 + /** 8 + * dummy 9 + * dummy 10 + */ 11 + export default function testStack() { 12 + innerTestStack() 13 + } 14 + 15 + import 'node:util' 16 + 17 + /** 18 + * bar 19 + * bar 20 + */ 21 + function innerTestStack() { 22 + throw new Error('__TEST_STACK_TRANSPILED__') 23 + } 24 + 25 + // transpiled.js and transpiled.js.map are copied from 26 + // https://esbuild.github.io/try/#dAAwLjI1LjAALS1sb2FkZXI9dHMgLS1zb3VyY2VtYXAgLS1zb3VyY2VmaWxlPXRyYW5zcGlsZWQudHMAaW1wb3J0ICdub2RlOnBhdGgnCgpleHBvcnQgdHlwZSBEdW1teSA9IHsKICBmb286ICJmb28iLAp9CgovKioKICogZHVtbXkKICogZHVtbXkKICovCmV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uIHRlc3RTdGFjaygpIHsKICBpbm5lclRlc3RTdGFjaygpCn0KCmltcG9ydCAnbm9kZTp1dGlsJwoKLyoqCiAqIGJhcgogKiBiYXIKICovCmZ1bmN0aW9uIGlubmVyVGVzdFN0YWNrKCkgewogIHRocm93IG5ldyBFcnJvcignX19URVNUX1NUQUNLX1RSQU5TUElMRURfXycpCn0
+23
test/cli/deps/error/ts.ts
··· 1 + import 'node:path' 2 + 3 + export type Dummy = { 4 + foo: "foo", 5 + } 6 + 7 + /** 8 + * dummy 9 + * dummy 10 + */ 11 + export default function testStack() { 12 + innerTestStack() 13 + } 14 + 15 + import 'node:util' 16 + 17 + /** 18 + * bar 19 + * bar 20 + */ 21 + function innerTestStack() { 22 + throw new Error('__TEST_STACK_TS__') 23 + }
+21
test/cli/fixtures/stacktraces/error-in-package.test.js
··· 1 + import { test } from 'vitest' 2 + import testStack from "@vitest/test-dep-error" 3 + import testStackTs from "@vitest/test-dep-error/ts.ts" 4 + import testStackTranspiled from "@vitest/test-dep-error/transpiled.js" 5 + import testStackTranspiledInline from "@vitest/test-dep-error/transpiled-inline.js" 6 + 7 + test('js', () => { 8 + testStack() 9 + }) 10 + 11 + test('ts', () => { 12 + testStackTs() 13 + }) 14 + 15 + test('transpiled', () => { 16 + testStackTranspiled() 17 + }) 18 + 19 + test('transpiled inline', () => { 20 + testStackTranspiledInline() 21 + })
+137
test/cli/test/__snapshots__/stacktraces.test.ts.snap
··· 22 22 " 23 23 `; 24 24 25 + exports[`stacktrace in dependency package > external 1`] = ` 26 + " 27 + ⎯⎯ Failed Tests 4 ⎯⎯ 28 + 29 + FAIL error-in-package.test.js > js 30 + Error: __TEST_STACK__ 31 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/index.js:10:9 32 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/index.js:4:3 33 + ❯ error-in-package.test.js:8:12 34 + 6| 35 + 7| test('js', () => { 36 + 8| testStack() 37 + | ^ 38 + 9| }) 39 + 10| 40 + 41 + ⎯⎯[1/4]⎯ 42 + 43 + FAIL error-in-package.test.js > ts 44 + Error: __TEST_STACK_TS__ 45 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/ts.ts:22:9 46 + 20| */ 47 + 21| function innerTestStack() { 48 + 22| throw new Error('__TEST_STACK_TS__') 49 + | ^ 50 + 23| } 51 + 24| 52 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/ts.ts:12:3 53 + ❯ error-in-package.test.js:12:14 54 + 55 + ⎯⎯[2/4]⎯ 56 + 57 + FAIL error-in-package.test.js > transpiled 58 + Error: __TEST_STACK_TRANSPILED__ 59 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/transpiled.ts:22:9 60 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/transpiled.ts:12:3 61 + ❯ error-in-package.test.js:16:22 62 + 14| 63 + 15| test('transpiled', () => { 64 + 16| testStackTranspiled() 65 + | ^ 66 + 17| }) 67 + 18| 68 + 69 + ⎯⎯[3/4]⎯ 70 + 71 + FAIL error-in-package.test.js > transpiled inline 72 + Error: __TEST_STACK_TRANSPILED_INLINE__ 73 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/transpiled-inline.ts:22:9 74 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/transpiled-inline.ts:12:3 75 + ❯ error-in-package.test.js:20:28 76 + 18| 77 + 19| test('transpiled inline', () => { 78 + 20| testStackTranspiledInline() 79 + | ^ 80 + 21| }) 81 + 22| 82 + 83 + ⎯⎯[4/4]⎯ 84 + 85 + " 86 + `; 87 + 88 + exports[`stacktrace in dependency package > inline 1`] = ` 89 + " 90 + ⎯⎯ Failed Tests 4 ⎯⎯ 91 + 92 + FAIL error-in-package.test.js > js 93 + Error: __TEST_STACK__ 94 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/index.js:10:9 95 + 8| 96 + 9| function innerTestStack() { 97 + 10| throw new Error('__TEST_STACK__') 98 + | ^ 99 + 11| } 100 + 12| 101 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/index.js:4:3 102 + ❯ error-in-package.test.js:8:12 103 + 104 + ⎯⎯[1/4]⎯ 105 + 106 + FAIL error-in-package.test.js > ts 107 + Error: __TEST_STACK_TS__ 108 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/ts.ts:22:9 109 + 20| */ 110 + 21| function innerTestStack() { 111 + 22| throw new Error('__TEST_STACK_TS__') 112 + | ^ 113 + 23| } 114 + 24| 115 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/ts.ts:12:3 116 + ❯ error-in-package.test.js:12:14 117 + 118 + ⎯⎯[2/4]⎯ 119 + 120 + FAIL error-in-package.test.js > transpiled 121 + Error: __TEST_STACK_TRANSPILED__ 122 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/transpiled.ts:22:9 123 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/transpiled.ts:12:3 124 + ❯ error-in-package.test.js:16:22 125 + 14| 126 + 15| test('transpiled', () => { 127 + 16| testStackTranspiled() 128 + | ^ 129 + 17| }) 130 + 18| 131 + 132 + ⎯⎯[3/4]⎯ 133 + 134 + FAIL error-in-package.test.js > transpiled inline 135 + Error: __TEST_STACK_TRANSPILED_INLINE__ 136 + ❯ innerTestStack (NODE_MODULES)/@vitest/test-dep-error/transpiled-inline.ts:22:9 137 + ❯ testStack (NODE_MODULES)/@vitest/test-dep-error/transpiled-inline.ts:12:3 138 + ❯ error-in-package.test.js:20:28 139 + 18| 140 + 19| test('transpiled inline', () => { 141 + 20| testStackTranspiledInline() 142 + | ^ 143 + 21| }) 144 + 22| 145 + 146 + ⎯⎯[4/4]⎯ 147 + 148 + " 149 + `; 150 + 25 151 exports[`stacktrace in vmThreads 1`] = ` 26 152 " 27 153 ⎯⎯ Failed Tests 1 ⎯⎯ ··· 114 240 115 241 ⎯⎯[1/1]⎯ 116 242 243 + " 244 + `; 245 + 246 + exports[`stacktraces should respect sourcemaps > error-in-package.test.js 1`] = ` 247 + " ❯ error-in-package.test.js:8:12 248 + 6| 249 + 7| test('js', () => { 250 + 8| testStack() 251 + | ^ 252 + 9| }) 253 + 10| 117 254 " 118 255 `; 119 256