Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions packages/vitest/src/node/printError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,8 @@ export function generateCodeFrame(
return ''
}

res.push(
lineNo(j + 1)
+ truncateString(lines[j].replace(/\t/g, ' '), columns - 5 - indent),
)
const truncatedLine = truncateString(lines[j].replace(/\t/g, ' '), columns - 5 - indent).trimEnd()
res.push(lineNo(j + 1) + (truncatedLine ? ' ' + truncatedLine : truncatedLine))

if (j === i) {
// push underline
Expand All @@ -481,12 +479,12 @@ export function generateCodeFrame(
1,
end > count ? lineLength - pad : end - start,
)
res.push(lineNo() + ' '.repeat(pad) + c.red('^'.repeat(length)))
res.push(lineNo() + ' '.repeat(pad + 1) + c.red('^'.repeat(length)))
}
else if (j > i) {
if (end > count) {
const length = Math.max(1, Math.min(end - count, lineLength))
res.push(lineNo() + c.red('^'.repeat(length)))
res.push(lineNo() + ' ' + c.red('^'.repeat(length)))
}
count += lineLength + 1
}
Expand All @@ -503,5 +501,5 @@ export function generateCodeFrame(
}

function lineNo(no: number | string = '') {
return c.gray(`${String(no).padStart(3, ' ')}| `)
return c.gray(`${String(no).padStart(3, ' ')}|`)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ await expect.element(locator).toBeInTheDocument()
❯ expect-element.test.js:18:33
16| const element = page.getByText("Hello Vitest!");
17|
17|
18| expect.element(element).toBeInTheDocument();
| ^
19| })
20|
20|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Expand Down
18 changes: 9 additions & 9 deletions test/cli/test/__snapshots__/list.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
exports[`basic output shows error 1`] = `
"Error: describe error
❯ describe-error.test.ts:4:9
2|
2|
3| describe('describe error', () => {
4| throw new Error('describe error')
| ^
5|
5|
6| it('wont run', () => {

Error: top level error
❯ top-level-error.test.ts:1:7
1| throw new Error('top level error')
| ^
2|
2|

"
`;
Expand Down Expand Up @@ -78,37 +78,37 @@ exports[`correctly outputs all tests with args: "--typecheck.only" 1`] = `
exports[`json output shows error 1`] = `
"Error: describe error
❯ describe-error.test.ts:4:9
2|
2|
3| describe('describe error', () => {
4| throw new Error('describe error')
| ^
5|
5|
6| it('wont run', () => {

Error: top level error
❯ top-level-error.test.ts:1:7
1| throw new Error('top level error')
| ^
2|
2|

"
`;

exports[`json with a file output shows error 1`] = `
"Error: describe error
❯ describe-error.test.ts:4:9
2|
2|
3| describe('describe error', () => {
4| throw new Error('describe error')
| ^
5|
5|
6| it('wont run', () => {

Error: top level error
❯ top-level-error.test.ts:1:7
1| throw new Error('top level error')
| ^
2|
2|

"
`;
66 changes: 33 additions & 33 deletions test/cli/test/__snapshots__/stacktraces.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ exports[`stacktrace filtering > filters stacktraces 1`] = `
FAIL error-with-stack.test.js > error in deps
Error: Something truly horrible has happened!
❯ d error-with-stack.test.js:20:9
18|
18|
19| function d() {
20| throw new Error('Something truly horrible has happened!')
| ^
21| }
22|
22|
❯ c error-with-stack.test.js:16:3
❯ a error-with-stack.test.js:8:3
❯ error-with-stack.test.js:4:3
Expand All @@ -31,12 +31,12 @@ Error: __TEST_STACK__
❯ innerTestStack (NODE_MODULES)/@test/test-dep-error/index.js:10:9
❯ testStack (NODE_MODULES)/@test/test-dep-error/index.js:4:3
❯ error-in-package.test.js:8:12
6|
6|
7| test('js', () => {
8| testStack()
| ^
9| })
10|
10|

⎯⎯[1/4]⎯

Expand All @@ -48,7 +48,7 @@ Error: __TEST_STACK_TS__
22| throw new Error('__TEST_STACK_TS__')
| ^
23| }
24|
24|
❯ testStack (NODE_MODULES)/@test/test-dep-error/ts.ts:12:3
❯ error-in-package.test.js:12:14

Expand All @@ -59,12 +59,12 @@ Error: __TEST_STACK_TRANSPILED__
❯ innerTestStack (NODE_MODULES)/@test/test-dep-error/transpiled.js:7:9
❯ testStack (NODE_MODULES)/@test/test-dep-error/transpiled.js:3:3
❯ error-in-package.test.js:16:22
14|
14|
15| test('transpiled', () => {
16| testStackTranspiled()
| ^
17| })
18|
18|

⎯⎯[3/4]⎯

Expand All @@ -73,12 +73,12 @@ Error: __TEST_STACK_TRANSPILED_INLINE__
❯ innerTestStack (NODE_MODULES)/@test/test-dep-error/transpiled-inline.js:7:9
❯ testStack (NODE_MODULES)/@test/test-dep-error/transpiled-inline.js:3:3
❯ error-in-package.test.js:20:28
18|
18|
19| test('transpiled inline', () => {
20| testStackTranspiledInline()
| ^
21| })
22|
22|

⎯⎯[4/4]⎯

Expand All @@ -92,12 +92,12 @@ exports[`stacktrace in dependency package > inline 1`] = `
FAIL error-in-package.test.js > js
Error: __TEST_STACK__
❯ innerTestStack (NODE_MODULES)/@test/test-dep-error/index.js:10:9
8|
8|
9| function innerTestStack() {
10| throw new Error('__TEST_STACK__')
| ^
11| }
12|
12|
❯ testStack (NODE_MODULES)/@test/test-dep-error/index.js:4:3
❯ error-in-package.test.js:8:12

Expand All @@ -111,7 +111,7 @@ Error: __TEST_STACK_TS__
22| throw new Error('__TEST_STACK_TS__')
| ^
23| }
24|
24|
❯ testStack (NODE_MODULES)/@test/test-dep-error/ts.ts:12:3
❯ error-in-package.test.js:12:14

Expand All @@ -122,12 +122,12 @@ Error: __TEST_STACK_TRANSPILED__
❯ innerTestStack (NODE_MODULES)/@test/test-dep-error/transpiled.ts:22:9
❯ testStack (NODE_MODULES)/@test/test-dep-error/transpiled.ts:12:3
❯ error-in-package.test.js:16:22
14|
14|
15| test('transpiled', () => {
16| testStackTranspiled()
| ^
17| })
18|
18|

⎯⎯[3/4]⎯

Expand All @@ -136,12 +136,12 @@ Error: __TEST_STACK_TRANSPILED_INLINE__
❯ innerTestStack (NODE_MODULES)/@test/test-dep-error/transpiled-inline.ts:22:9
❯ testStack (NODE_MODULES)/@test/test-dep-error/transpiled-inline.ts:12:3
❯ error-in-package.test.js:20:28
18|
18|
19| test('transpiled inline', () => {
20| testStackTranspiledInline()
| ^
21| })
22|
22|

⎯⎯[4/4]⎯

Expand All @@ -155,12 +155,12 @@ exports[`stacktrace in vmThreads 1`] = `
FAIL error-with-stack.test.js > error in deps
Error: Something truly horrible has happened!
❯ d error-with-stack.test.js:20:9
18|
18|
19| function d() {
20| throw new Error('Something truly horrible has happened!')
| ^
21| }
22|
22|
❯ c error-with-stack.test.js:16:3
❯ b error-with-stack.test.js:12:3
❯ a error-with-stack.test.js:8:3
Expand All @@ -183,7 +183,7 @@ ReferenceError: bar is not defined
3| return bar()
| ^
4| }
5|
5|
❯ error-in-deps.test.js:5:6

⎯⎯[1/1]⎯
Expand All @@ -204,7 +204,7 @@ imba-parser error: Unexpected 'CALL_END'

exports[`stacktraces should respect sourcemaps > add.test.ts 1`] = `
" ❯ add.test.ts:12:24
10|
10|
11| it('add', () => {
12| expect(add(a.count)).toBe(100)
| ^
Expand All @@ -220,13 +220,13 @@ exports[`stacktraces should respect sourcemaps > add-in-imba.test.imba 1`] = `
8| expect(add(1)).toBe 3
| ^
9| expect(add(1, 2, 3)).toBe 6
10|
10|
"
`;

exports[`stacktraces should respect sourcemaps > add-in-js.test.js 1`] = `
" ❯ add-in-js.test.js:6:17
4|
4|
5| it('add', () => {
6| expect(add()).toBe(100)
| ^
Expand All @@ -245,63 +245,63 @@ exports[`stacktraces should respect sourcemaps > error-in-deps.test.js 1`] = `

exports[`stacktraces should respect sourcemaps > error-in-package.test.js 1`] = `
" ❯ error-in-package.test.js:8:12
6|
6|
7| test('js', () => {
8| testStack()
| ^
9| })
10|
10|
"
`;

exports[`stacktraces should respect sourcemaps > error-with-stack.test.js 1`] = `
" ❯ d error-with-stack.test.js:20:9
18|
18|
19| function d() {
20| throw new Error('Something truly horrible has happened!')
| ^
21| }
22|
22|
❯ c error-with-stack.test.js:16:3"
`;

exports[`stacktraces should respect sourcemaps > mocked-global.test.js 1`] = `
" ❯ mocked-global.test.js:6:13
4|
4|
5| test('failed', () => {
6| expect(1).toBe(2)
| ^
7| })
8|
8|
"
`;

exports[`stacktraces should respect sourcemaps > mocked-imported.test.js 1`] = `
" ❯ mocked-imported.test.js:6:13
4|
4|
5| test('failed', () => {
6| expect(1).toBe(2)
| ^
7| })
8|
8|
"
`;

exports[`stacktraces should respect sourcemaps > mocked-imported.test.ts 1`] = `
" ❯ mocked-imported.test.ts:6:13
4|
4|
5| test('failed', () => {
6| expect(1).toBe(2)
| ^
7| })
8|
8|
"
`;

exports[`stacktraces should respect sourcemaps > require-assertions.test.js 1`] = `
" ❯ require-assertions.test.js:3:5
1| import { test } from 'vitest'
2|
2|
3| test('assertion is not called', () => {
| ^
4| // no expect
Expand Down
8 changes: 4 additions & 4 deletions test/cli/test/annotations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ describe('reporters', () => {
11| throw new Error('thrown error')
| ^
12| })
13|
13|

❯ basic.test.ts:9:15 notice
↳ printed
Expand Down Expand Up @@ -549,7 +549,7 @@ describe('reporters', () => {
6| throw new Error('thrown error')
| ^
7| })
8|
8|

❯ basic.test.ts:5:15 notice
↳ printed
Expand Down Expand Up @@ -587,7 +587,7 @@ describe('reporters', () => {
6| throw new Error('thrown error')
| ^
7| })
8|
8|

❯ basic.test.ts:5:15 notice
↳ printed 1
Expand All @@ -602,7 +602,7 @@ describe('reporters', () => {
6| throw new Error('thrown error')
| ^
7| })
8|
8|

❯ basic.test.ts:5:15 notice
↳ printed 2
Expand Down
Loading
Loading