Skip to content

Fail message annotation points to the wrong line #3766

@davemfish

Description

@davemfish

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions