Jest: Source maps are mis-aligned

Created on 28 Jul 2020  路  2Comments  路  Source: facebook/jest

馃悰 Bug Report

Jest errors that show line numbers and code snippets aren't showing the right thing.

This seems to happen by merely including another package that already loads source-map-support module prior, for example pino-caller. You can see the code for pino-caller is very simple, and in fact no code paths get triggered, other than just the loading of the module itself.

When I comment out the require line in pino-caller, the source maps align fine.

I've looked at other source maps issues here, and none of them seem to be relevant to this.

To Reproduce

Steps to reproduce the behavior:

require('pino-caller')

describe('Name of the group', () => {
  it('should work', () => {
    // comment

    throw new Error('foo')
  })
})

Results in:


      4 |   it('should work', () => {
      5 |     // comment
    > 6 |
        | ^
      7 |     throw new Error('foo')
      8 |   })
      9 | })

      at Object.<anonymous> (test/foo.test.ts:6:15)

Expected behavior

To point to the right line of code.

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: macOS 10.15.4
    CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
  Binaries:
    Node: 12.18.2 - ~/.nvm/versions/node/v12.18.2/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.2/bin/npm
  npmPackages:
    jest: 26.1.0 => 26.1.0
Bug Report Needs Repro Needs Triage

Most helpful comment

Repo with minimal code to reproduce: https://github.com/Marik-D/jest-source-map-issue

require('source-map-support').install() //commenting out this line makes the issue dissapear






test('test', () => {
  expect(false).toEqual(true)
})

Looks like just using jest with source-map-support is enough to reproduce.

Also, console logs and node's assert are unaffected by this issue.

All 2 comments

Repo with minimal code to reproduce: https://github.com/Marik-D/jest-source-map-issue

require('source-map-support').install() //commenting out this line makes the issue dissapear






test('test', () => {
  expect(false).toEqual(true)
})

Looks like just using jest with source-map-support is enough to reproduce.

Also, console logs and node's assert are unaffected by this issue.

So I dug into the code and where Istanbul is working it should not be.

Also I doubt It will be fixed any time soon coverage is built into V8 directly for example implementation see
https://www.npmjs.com/package/c8

Was this page helpful?
0 / 5 - 0 ratings