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

Readme clarification request: does not work with ES6 #916

Closed
papb opened this issue Sep 7, 2018 · 6 comments
Closed

Readme clarification request: does not work with ES6 #916

papb opened this issue Sep 7, 2018 · 6 comments

Comments

@papb
Copy link

papb commented Sep 7, 2018

Summary

It appears that nyc does not work out of the box with ES6. The readme makes it seem like a few plugins might be necessary if one is using Babel. I'm not using Babel, I'm simply using ES6 directly in Node.

My goal opening this issue is to suggest improvements to README.md:

  • There should be a clear note at the top of README.md that nyc does not work with ES6 at all without extra plugins
  • Ideally, there could be also a short guide understandable by beginners on how to make it work with ES6.

The steps below indicate what a beginner could try to do, not even knowing what "babel" means:

Steps to reproduce

  1. npm init -y && npm install mocha nyc
  2. Create index.js with the following content:
module.exports = class Foo {
    doSomething() {
        throw new Error();
    }
};
  1. Create test.js with the following content:
const Foo = require("./index");
describe("Foo", function() {
    it("bar", function() {
        (new Foo()).doSomething();
    });
});
  1. Run nyc mocha

Expected Behavior

  Error
      at Foo.doSomething (index.js:3:15)

Observed Behavior

  Error
      at Foo.doSomething (index.js:1:999)

Forensic Information

Operating System: Windows 7
Environment Information:

  • node: v6.11.1
  • npm: v3.10.10

Notes

This is a honest opinion that README.md could be better, especially for non-experts trying to use this great library. Currently the information is scattered in complicated "transform", "babel plugins", with only superficial instructions. Please try to take a look at README.md from the point of view of a beginner (ideally, one that doesn't even know what Babel is).

I, for instance, was a bit frustrated that I had to go through all this until I figured out what was going on...

Thanks for looking 😀

@papb papb changed the title README clarification request: does not work with ES6 Readme clarification request: does not work with ES6 Sep 7, 2018
@Lukenickerson
Copy link

I also recently started using nyc with non-babelified node code, only to discover by trial-and-error that it fails in weird ways with ES6 syntax (e.g., gives 0% branch coverage when there's a default parameter). 😫

A couple of improvements I would suggest:

  • At the start of the README it says "with support for", but it would be also helpful to clearly state what's not supported: ES6.
  • Reorganize the content into major sections: Setup (the basics), CLI options, Configuration, Integrations (babel, coveralls, codecov -- maybe even as separate files)

@JaKXz
Copy link
Member

JaKXz commented Jan 3, 2019

@Lukenickerson I would love to see that! We have https://github.com/istanbuljs/istanbuljs.github.io for our complete slightly more comprehensive documentation and it has been a challenge to figure out what is "enough for the README" and what should be on the website. Please feel free to take a crack at this.

@coreyfarrell
Copy link
Member

@papb Regarding the stack trace error locations, this is documented at https://github.com/istanbuljs/nyc#accurate-stack-traces-using-source-maps. My understanding is that there are difficulties with this functionality, that would be an actual code bug (unclear where). I do not believe this would have anything to do with ES6, though I'd be willing to look at an example showing that I'm wrong.

@Lukenickerson I'm not sure what ES6 features are not working for you. I've just created the following code:

function test(value = 'default') {
	console.log(value);
}

test('test');

And run:

$ npx nyc --all=false node ./es6.js 
test
----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |      100 |        0 |      100 |      100 |                   |
 es6.js   |      100 |        0 |      100 |      100 |                 1 |
----------|----------|----------|----------|----------|-------------------|

The 0% branch coverage for this code is expected. If I replace test('test'); with test();, the default argument branch gets covered and it reports 100% branch coverage. This testing was done with nyc@13.2.0.

@stale stale bot added the stale label Apr 7, 2019
@papb
Copy link
Author

papb commented Apr 7, 2019

@coreyfarrell - Thanks for the update, sorry I didn't reply any sooner, I have been very busy, will take a look later. Thanks :)

@stale stale bot removed the stale label Apr 7, 2019
@istanbuljs istanbuljs deleted a comment from stale bot Apr 7, 2019
@JaKXz
Copy link
Member

JaKXz commented May 4, 2019

This has been fixed as of #1093.

@JaKXz JaKXz closed this as completed May 4, 2019
@LitileXueZha
Copy link

The ES6 syntax default function parameters cause 0% branch coverage sometimes. So first i deleted the syntax and nyc's coverage was expected, then i added it again and the coverage was also correct.

It is so weird. Seems no problem, i just say my exprience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants