File tree Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 1
1
* text =auto eol =lf
2
+
3
+ test /reporters /fixtures /indicator-position.test.js eol =crlf
Original file line number Diff line number Diff line change @@ -251,6 +251,7 @@ export function generateCodeFrame(
251
251
const start = positionToOffset ( source , lineNumber , columnNumber )
252
252
const end = start
253
253
const lines = source . split ( lineSplitRE )
254
+ const nl = / \r \n / . test ( source ) ? 2 : 1
254
255
let count = 0
255
256
let res : string [ ] = [ ]
256
257
@@ -261,7 +262,7 @@ export function generateCodeFrame(
261
262
}
262
263
263
264
for ( let i = 0 ; i < lines . length ; i ++ ) {
264
- count += lines [ i ] . length + 1
265
+ count += lines [ i ] . length + nl
265
266
if ( count >= start ) {
266
267
for ( let j = i - range ; j <= i + range || end > count ; j ++ ) {
267
268
if ( j < 0 || j >= lines . length )
@@ -277,7 +278,7 @@ export function generateCodeFrame(
277
278
278
279
if ( j === i ) {
279
280
// push underline
280
- const pad = start - ( count - lineLength )
281
+ const pad = start - ( count - lineLength ) + ( nl - 1 )
281
282
const length = Math . max ( 1 , end > count ? lineLength - pad : end - start )
282
283
res . push ( lineNo ( ) + ' ' . repeat ( pad ) + c . red ( '^' . repeat ( length ) ) )
283
284
}
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-multiple-empty-lines */
2
+ // this file should be in CRLF format
3
+ import { expect , test } from 'vitest'
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ test ( '' , async ( ) => {
12
+ expect ( 1 + 1 ) . toBe ( 3 )
13
+ expect ( 1 + 1 ) . toBe ( 2 )
14
+ expect ( 2 + 2 ) . toBe ( 4 )
15
+ } )
Original file line number Diff line number Diff line change
1
+ import { readFileSync } from 'node:fs'
2
+ import { expect , test } from 'vitest'
3
+ import { resolve } from 'pathe'
4
+ import { runVitest } from '../../test-utils'
5
+
6
+ test ( 'should print correct indicator position' , async ( ) => {
7
+ const filename = resolve ( './fixtures/indicator-position.test.js' )
8
+ const { stderr } = await runVitest ( { root : './fixtures' } , [ filename ] )
9
+ const code = readFileSync ( filename , 'utf-8' )
10
+
11
+ expect ( code ) . toMatch ( / \r \n / )
12
+ expect ( stderr ) . toBeTruthy ( )
13
+ expect ( stderr ) . toMatchInlineSnapshot ( `
14
+ "⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
15
+
16
+ FAIL indicator-position.test.js >
17
+ AssertionError: expected 2 to be 3 // Object.is equality
18
+
19
+ - Expected
20
+ + Received
21
+
22
+ - 3
23
+ + 2
24
+
25
+ ❯ indicator-position.test.js:12:17
26
+ 10|
27
+ 11| test('', async () => {
28
+ 12| expect(1 + 1).toBe(3)
29
+ | ^
30
+ 13| expect(1 + 1).toBe(2)
31
+ 14| expect(2 + 2).toBe(4)
32
+
33
+ ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
34
+
35
+ "
36
+ ` )
37
+ } )
You can’t perform that action at this time.
0 commit comments