Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use correct source maps in stacktrace (#2027)
* [vitest] use correct source maps in stacktrace use vitenode server to get a fetch result instead of a transform result. And then get the sourcemap from it. * [vitest] refactor * add tests for stack traces and sourcemaps * commit lockfile * fix linter * fix types linter * remove dynamic content from snapshot * push the correct snapshot * fix tests :) * increase timeout for runner tests * decrease timeout .. not the culprit in CI * move continue below map assignment * guard against accessing vitenode server * reduce the size of snapshots * rename timeout to prevent running more than one
- Loading branch information
Showing
13 changed files
with
172 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {it, expect} from 'vitest' | ||
|
||
export def add(...args) | ||
return args.reduce((do(a, b) a + b), 0) | ||
|
||
it "add", do | ||
expect(add()).toBe 0 | ||
expect(add(1)).toBe 3 | ||
expect(add(1, 2, 3)).toBe 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* body */ | ||
import { expect, it } from 'vitest' | ||
import { add } from './utils' | ||
|
||
it('add', () => { | ||
expect(add()).toBe(100) | ||
expect(add(1)).toBe(1) | ||
return expect(add(1, 2, 3)).toBe(6) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* body */ | ||
import { expect, it } from 'vitest' | ||
import { add } from './utils' | ||
|
||
interface Num { | ||
count: number | ||
} | ||
|
||
const a: Num = { count: 10 } | ||
|
||
it('add', () => { | ||
expect(add(a.count)).toBe(100) | ||
expect(add(1)).toBe(1) | ||
return expect(add(1, 2, 3)).toBe(6) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function add(...args: number[]) { | ||
return args.reduce((a, b) => { return a + b }, 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
plugins: [{ | ||
name: 'vite-plugin-imba', | ||
transform(code, id) { | ||
if (id.endsWith('.imba')) { | ||
return { | ||
code: | ||
'\n/*body*/\nimport {it,expect} from \'vitest\';\n\nexport function add(...args){\n\t\n\treturn args.reduce(function(a,b) { return a + b; },0);\n};\n\nit("add",function() {\n\t\n\texpect(add()).toBe(0);\n\texpect(add(1)).toBe(3);\n\treturn expect(add(1,2,3)).toBe(6);\n});\n\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMudGVzdC5pbWJhIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidXRpbHMudGVzdC5pbWJhIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7aXQsIGV4cGVjdH0gZnJvbSAndml0ZXN0J1xuXG5leHBvcnQgZGVmIGFkZCguLi5hcmdzKVxuXHRyZXR1cm4gYXJncy5yZWR1Y2UoKGRvKGEsIGIpIGEgKyBiKSwgMClcblxuaXQgXCJhZGRcIiwgZG9cblx0ZXhwZWN0KGFkZCgpKS50b0JlIDBcblx0ZXhwZWN0KGFkZCgxKSkudG9CZSAzXG5cdGV4cGVjdChhZGQoMSwgMiwgMykpLnRvQmUgNlxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsTUFBTSxFQUFFLEVBQUUsQ0FBRSxNQUFNLE9BQU8sUUFBUTs7QUFFakMsTUFBTSxDQUFDLFFBQUcsQ0FBQyxHQUFHLElBQUksSUFBSSxDQUFDOztDQUN0QixNQUFNLENBQUMsSUFBSSxDQUFDLE1BQU0sQ0FBRSxRQUFFLENBQUMsQ0FBQyxDQUFFLENBQUMsSUFBRSxPQUFBLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFHLENBQUMsQ0FBQztDQUFBOztBQUV4QyxFQUFFLENBQUMsS0FBSyxDQUFFLFFBQUUsR0FBQTs7Q0FDWCxNQUFNLENBQUMsR0FBRyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFBO0NBQ3BCLE1BQU0sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFBO0NBQ3JCLE9BQUEsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUUsQ0FBQyxDQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQTtDQUFBLENBSDFCO0FBSUY7In0=', | ||
map: { | ||
version: 3, | ||
file: 'add-in-imba.test.imba', | ||
names: [], | ||
sourceRoot: '', | ||
sources: ['add-in-imba.test.imba'], | ||
sourcesContent: [ | ||
'import {it, expect} from \'vitest\'\n\nexport def add(...args)\n\treturn args.reduce((do(a, b) a + b), 0)\n\nit "add", do\n\texpect(add()).toBe 0\n\texpect(add(1)).toBe 3\n\texpect(add(1, 2, 3)).toBe 6\n', | ||
], | ||
mappings: | ||
';;AAAA,MAAM,EAAE,EAAE,CAAE,MAAM,OAAO,QAAQ;;AAEjC,MAAM,CAAC,QAAG,CAAC,GAAG,IAAI,IAAI,CAAC;;CACtB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAE,QAAE,CAAC,CAAC,CAAE,CAAC,IAAE,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,IAAG,CAAC,CAAC;CAAA;;AAExC,EAAE,CAAC,KAAK,CAAE,QAAE,GAAA;;CACX,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;CACpB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;CACrB,OAAA,MAAM,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;CAAA,CAH1B;AAIF;', | ||
}, | ||
} | ||
} | ||
}, | ||
}], | ||
test: { | ||
threads: false, | ||
isolate: false, | ||
include: ['**/*.{test,spec}.{imba,js,mjs,cjs,ts,mts,cts,jsx,tsx}'], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@vitest/test-fails", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
"devDependencies": { | ||
"execa": "^6.1.0", | ||
"vitest": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`stacktraces should respect sourcemaps > add.test.ts > add.test.ts 1`] = ` | ||
" ❯ add.test.ts:12:23 | ||
10| | ||
11| it('add', () => { | ||
12| expect(add(a.count)).toBe(100) | ||
| ^ | ||
13| expect(add(1)).toBe(1) | ||
14| return expect(add(1, 2, 3)).toBe(6) | ||
" | ||
`; | ||
exports[`stacktraces should respect sourcemaps > add-in-imba.test.imba > add-in-imba.test.imba 1`] = ` | ||
" ❯ add-in-imba.test.imba:8:16 | ||
6| it \\"add\\", do | ||
7| expect(add()).toBe 0 | ||
8| expect(add(1)).toBe 3 | ||
| ^ | ||
9| expect(add(1, 2, 3)).toBe 6 | ||
10| | ||
" | ||
`; | ||
exports[`stacktraces should respect sourcemaps > add-in-js.test.js > add-in-js.test.js 1`] = ` | ||
" ❯ add-in-js.test.js:6:17 | ||
4| | ||
5| it('add', () => { | ||
6| expect(add()).toBe(100) | ||
| ^ | ||
7| expect(add(1)).toBe(1) | ||
8| return expect(add(1, 2, 3)).toBe(6) | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { resolve } from 'pathe' | ||
import fg from 'fast-glob' | ||
import { execa } from 'execa' | ||
import { describe, expect, it } from 'vitest' | ||
|
||
describe('stacktraces should respect sourcemaps', async () => { | ||
const root = resolve(__dirname, '../fixtures') | ||
const files = await fg('*.test.*', { cwd: root }) | ||
|
||
for (const file of files) { | ||
it(file, async () => { | ||
// in Windows child_process is very unstable, we skip testing it | ||
if (process.platform === 'win32' && process.env.CI) | ||
return | ||
|
||
let error: any | ||
await execa('npx', ['vitest', 'run', file], { | ||
cwd: root, | ||
env: { | ||
...process.env, | ||
CI: 'true', | ||
NO_COLOR: 'true', | ||
}, | ||
}) | ||
.catch((e) => { | ||
error = e | ||
}) | ||
|
||
expect(error).toBeTruthy() | ||
const lines = String(error).split(/\n/g) | ||
const index = lines.findIndex(val => val.includes(`${file}:`)) | ||
const msg = lines.slice(index, index + 8).join('\n') | ||
expect(msg).toMatchSnapshot(file) | ||
}, 10000) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['test/*.test.ts'], | ||
}, | ||
}) |