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.
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)
To point to the right line of code.
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
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
Most helpful comment
Repo with minimal code to reproduce: https://github.com/Marik-D/jest-source-map-issue
Looks like just using jest with
source-map-supportis enough to reproduce.Also, console logs and node's assert are unaffected by this issue.