Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating coverage produces errors when testing code that uses ES 6 default/override pattern #264

Closed
patrickarlt opened this issue May 29, 2016 · 3 comments

Comments

@patrickarlt
Copy link

I'm testing code that uses the ES 6 default override pattern in some code I am testing. When testing regularly with node-tap (which bundles nyc) or ava (which recommends nyc) the tests pass. But when I use nyc to generate coverage reports there are errors that are not present when not generating coverage.

I've created a minimal reproduction of this issue in this gist. which shows Node 6.2.0 being able to run the tests without coverage (tap node-tap-test.js and ava ava-test.js) and passing but when running with coverage (tap test-node-tap.js --coverage-report=text and nyc ava ava-test.js) the tests fail and the parameters padded to the say(options) function end up being undefined.

@JaKXz
Copy link
Member

JaKXz commented May 30, 2016

@patrickarlt I got the ava tests passing with some configuration options and fixing some typos in the package.json: https://gist.github.com/JaKXz/f64d82899e00495aba83ddd16d702ee9/revisions

I recommend taking a look at ava's instructions for .babelrc configuration and taking note that you should use nyc --require babel-register npm run <your test task> to get the same transpilation for coverage reports.

Let me know if that helps or not :)

@novemberborn
Copy link
Contributor

There are various issues with ES6 code and Istanbul, the library nyc uses to collect coverage data and prepare the reports: #215, #198, #239.

The tl;dr is that Istanbul doesn't support the new syntax, so you need to transpile to ES5, which is @JaKXz's suggestion.

Unfortunately that doesn't always work, since nyc now needs source maps in order to get the correct data. Source maps aren't always accurate, and then the resulting coverage data may be internally inconsistent, leading to crashes when generating reports.

There's a few things we can do to reduce the incidence of crashes (namely to throw away inconsistent data), but then there'll be less coverage.

The better approach would be to switch to an instrumenter that understands ES6. I've been planning to work on that but haven't had the time.

In the meantime try transpiling to ES5 and hope for the best.

@bcoe
Copy link
Member

bcoe commented Jun 15, 2016

@patrickarlt give this a spin:

https://github.com/bcoe/nyc#use-babel-plugin__coverage__-for-better-es6es7-support

we've released better support for ES6/ES6 coverage using the __coverage__ instrumentation library.

@bcoe bcoe closed this as completed Jun 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants