question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v8 coverage crashes with type-only files

See original GitHub issue

🐛 Bug Report

With coverageProvider: 'v8' and coverage enabled, Jest crashes with imported but non-elided type-only modules.

To Reproduce

Steps to reproduce the behavior:

  • jest.config.mjs:
    export default {
      collectCoverage: true,
      coverageProvider: 'v8',
      rootDir: 'src'
    };
    
  • babel.config.json
    {
      "presets": [
        "@babel/typescript"
      ]
    }
    
  • src/types.ts:
    export interface obj {}
    
  • src/mytest.test.ts:
    import * as types from './types';
    
    test('1+1=2', () => {
      console.log(types);
      expect(1 + 1).toBe(2);
    });
    
  • Run npx jest
    PASS  src2/mytest.test.ts
      √ 1+1=2 (16 ms)
    
      console.log
        { default: {} }
    
          at Object.<anonymous> (mytest.test.ts:4:11)
    
    TypeError: Cannot read property 'replace' of undefined
        at V8ToIstanbul._resolveSource (D:\repo\node_modules\v8-to-istanbul\lib\v8-to-istanbul.js:86:29)
        at V8ToIstanbul.load (D:\repo\node_modules\v8-to-istanbul\lib\v8-to-istanbul.js:57:26)
        at D:\repo\node_modules\@jest\reporters\build\CoverageReporter.js:624:27
        at Array.map (<anonymous>)
        at CoverageReporter._getCoverageResult (D:\repo\node_modules\@jest\reporters\build\CoverageReporter.js:587:32)
        at CoverageReporter.onRunComplete (D:\repo\node_modules\@jest\reporters\build\CoverageReporter.js:231:45)
        at ReporterDispatcher.onRunComplete (D:\repo\node_modules\@jest\core\build\ReporterDispatcher.js:88:9)
        at TestScheduler.scheduleTests (D:\repo\node_modules\@jest\core\build\TestScheduler.js:350:5)
        at runJest (D:\repo\node_modules\@jest\core\build\runJest.js:376:19)
        at _run10000 (D:\repo\node_modules\@jest\core\build\cli\index.js:416:7)
    

Expected behavior

Jest doesn’t crash, and coverage works.

Link to repl or repo (highly encouraged)

envinfo

  System:
    OS: Windows 10 10.0.19042
    CPU: (64) x64 AMD Ryzen Threadripper 3970X 32-Core Processor
  Binaries:
    Node: 15.2.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.0.8 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^26.6.3 => 26.6.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bcoecommented, Mar 30, 2021

Just merged @viceice’s patch 👌 sorry for the nuisance.

1reaction
SimenBcommented, Nov 14, 2020

This is what we pass

{
  originalSource: 'export interface obj {}\n\n',
  source: '"use strict";\n' +
    '//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbXX0=',
  sourceMap: {
    sourcemap: {
      version: 3,
      sources: [],
      names: [],
      mappings: '',
      sourcesContent: []
    }
  }
}

Seems like a bug in v8-to-istanbul to me. We pass a valid sourcemap - it’s just empty

Read more comments on GitHub >

github_iconTop Results From Across the Web

The hunt for chromium issue 1072171 - SensePost
The last few months I've been studying Chrome's v8 internals and exploits with the focus of finding a type confusion bug.
Read more >
Code Coverage in Chromium
The code coverage CQ builders instrument only the files changed for a given CL. ... If a crash of any type occurs (e.g....
Read more >
Visual Studio 2019 crashes when 'Show code coverage ...
Several times a day I experience that Visual Studio 2019 crashes when I want to see my code coverage. It happens when clicking...
Read more >
Average Car Insurance Costs for 21-Year Old Drivers
The average cost of auto insurance for a 21-year-old is $384 per month, ... tend to get into more accidents and file more...
Read more >
V.A.C.® Therapy Insurance Authorization Form (v8.0)
V.A.C.® Therapy Insurance Authorization Form (v8.0). Please fax this form to 3M-KCI ... I prescribe 3M-KCI V.A.C.® Therapy for the following wound type(s):....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found