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.

When run from `jest --coverage`, produces invalid code

See original GitHub issue

The test repo with the error Jest 19.0.2, babel-plugin-istanbul-4.0.0

The error happens to be related to a particular code. Test is passed ok, but when jest is run with --coverage, a Syntax Error happens. I made a minimal code example in the buggy function:

function buggy(stages, cs) {
    for (let i = 0; i < stages.length; i++) {
        if (cs > i) {
            continue;
        }
        let stage = stages[i];
        if (!stage.complete) {
            when(() => stage.complete, callback);
            break;
        }
    }
    return true;
}

Seems to be a code generation issue.

$ jest --coverage
 FAIL  ./buggy.test.js
  ● Test suite failed to run

    /Users/max/Documents/projects/bugs_demo/buggy.js:16
            } else /* istanbul ignore next */{++cov_2f4l4kc7dh.b[1][1];}};_loop2: for (var i = 0; i < stages.length; i++) {/* istanbul ignore next */var _ret = _loop(i); /* istanbul ignore next */switch (_ret) {case "continue":continue;case "break":break (/* istanbul ignore next */_loop2);}
                                                                                                                                                                                                                                                               ^
    SyntaxError: Unexpected token (

      at transformAndBuildScript (node_modules/jest-runtime/build/transform.js:320:12)
      at Object.<anonymous> (buggy.test.js:1:115)

Ref: https://github.com/facebook/jest/issues/3089

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
erquhartcommented, Sep 19, 2017

@bcoe this still seems to be an issue. Why was it closed?

2reactions
samuelcastrocommented, Jul 19, 2018

I’m having the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my Jest code coverage report invalid? - Stack Overflow
I generate the code coverage report with yarn jest --coverage and the application source code is written in JavaScript (rather than TypeScript).
Read more >
Configuring code coverage in Jest, the right way
In this brief tutorial we see how to configure code coverage for Jest, the right way.
Read more >
Find out how much code you're testing - Angular
When the tests are complete, the command creates a new /coverage folder in the project. Open the index.html file to see a report...
Read more >
Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >
Code Coverage - Cypress Documentation
If you do want to merge the reports yourself: on every machine running Cypress tests, copy the produced code coverage report into a...
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