Skip to content

Stack trace points to incorrect file on error #3004

Closed
@DanHulton

Description

Describe the bug

When running tests that encounter an error in a required file, the generated trace does not point to the correct file.

Expected:

ReferenceError: boop is not defined
 ❯ test/main.test.js:5:12
 > src/main.js:2:9
      1| export function testFunc(x) {
      2|   return boop(x);
       |          ^
      3| }

Actual:

ReferenceError: boop is not defined
 ❯ Module.testFunc ../../../../../src/main.js:2:3
 ❯ test/main.test.js:5:12
      3| describe('Main test', () => {
      4|   it('should blow up here', () => {
      5|     expect(testFunc(5)).toBe(10);
       |            ^
      6|   });
      7| });

Reproduction

  1. Check out https://github.com/DanHulton/vitest-stack-sourcemap-repro
  2. yarn install
  3. yarn test

System Info

System:
    OS: macOS 13.2.1
    CPU: (8) x64 Apple M1 Pro
    Memory: 19.44 MB / 32.00 GB
    Shell: 3.5.1 - /usr/local/bin/fish
  Binaries:
    Node: 17.3.0 - /usr/local/bin/node
    Yarn: 3.3.1 - /usr/local/bin/yarn
    npm: 8.16.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 110.0.5481.177
    Firefox: 109.0
    Safari: 16.3
  npmPackages:
    vite: latest => 4.1.4
    vitest: latest => 0.29.2

Used Package Manager

yarn

Validations

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