Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail message annotation points to the wrong line #3766

Closed
6 tasks done
davemfish opened this issue Jul 12, 2023 · 2 comments · Fixed by #3855
Closed
6 tasks done

Fail message annotation points to the wrong line #3766

davemfish opened this issue Jul 12, 2023 · 2 comments · Fixed by #3855

Comments

@davemfish
Copy link

Describe the bug

Console annotations of test failures -- specifically the red ^ -- often appears on the wrong line and at the wrong character.
Capture

In my real code I was tricked into thinking the earlier assertions were passing when they were not.

The behavior seems to be a function of the number of lines in the test file. For example, in my repro, note the ~10 lines preceding the test. If these are reduced to 1 or 2 lines, the annotation ends up in the correct place.

Reproduction

git clone https://github.com/davemfish/repro-vitest-annotation
cd repro-vitest-annotation
yarn test

System Info

λ npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers
npx: installed 1 in 2.539s

  System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
    Memory: 12.73 GB / 31.95 GB
  Binaries:
    Node: 18.14.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.11 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.14.11 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 114.0.5735.199
    Edge: Spartan (44.19041.1266.0), Chromium (114.0.1823.79)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

yarn

Validations

@mcavigelli
Copy link

mcavigelli commented Jul 16, 2023

I test the following function (powershell, windows)

export const getDouble = () : number => {
    throw new Error("Today not possible");   
}

Given the function is at the very top of the file, I get the following message on the console, indicator to "e" in "new":

 ❯ Module.getDouble test/matte.ts:2:11
      1| export const getDouble = () : number => {
      2|     throw new Error("Today not possible");
       |            ^
      3| }

Given I insert 10 blank lines, the red indicator moves 10 chars to the right, indicator to "T" in "Today":

 ❯ Module.getDouble test/matte.ts:12:11
      1| export const getDouble = () : number => {
      2|     throw new Error("Today not possible");
       |                      ^
      3| }

Given I insert 31 blank lines, the red indicator moves 31 chars to the right, indicator to SPACE behind ";":

 ❯ Module.getDouble test/matte.ts:33:11
     31|
     32| export const getDouble = () : number => {
     33|     throw new Error("Today not possible");
       |                                           ^
     34| }

@mcavigelli
Copy link

Seems to be a line ending problem.

  • In the tests above, the module had the windows line ending, ie CRLF.
  • when changing to LF as in unix, the red indicator points always to the same character ("n" in "new"):
Module.getDouble test/matte.ts:33:11
   31|
   32| export const getDouble = () : number => {
   33|     throw new Error("Today not possible");
     |           ^
   34|  }

@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants