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

Use c8 for coverage instead of nyc #493

Closed
isaacs opened this issue Jan 22, 2019 · 13 comments
Closed

Use c8 for coverage instead of nyc #493

isaacs opened this issue Jan 22, 2019 · 13 comments
Labels
plan a feature that is accepted and planned

Comments

@isaacs
Copy link
Member

isaacs commented Jan 22, 2019

This should produce the same coverage output, but run much faster.

Need bcoe/c8#59 to land so we can do --100.

@isaacs isaacs added plan a feature that is accepted and planned node version 11 labels Jan 22, 2019
@isaacs
Copy link
Member Author

isaacs commented Jan 23, 2019

Either wait for Node v10 to fall off LTS, or fork based on Node version and use nyc/c8 as appropriate.

@brodybits
Copy link

wait for Node v10 to fall off LTS

According to c8 Supported Node.js Versions it should be possible to use c8 on Node.js back to 10.12.0, which came before LTS (10.13.0) and security updates (10.14.0). And according to Node.js Release Schedule, Node.js pre-10 will reach EOL this year.

use nyc/c8 as appropriate

Any reason to run coverage on Node.js pre-10?

@isaacs
Copy link
Member Author

isaacs commented Jan 23, 2019

Oh, I guess we can do it as of node version 10, then!

@isaacs
Copy link
Member Author

isaacs commented Jan 23, 2019

Any reason to run coverage on Node.js pre-10?

Yeah? I personally think you should always run tests with coverage. It's going to become the default in tap v13.

@brodybits
Copy link

I personally think you should always run tests with coverage.

Got it (missed the built-in test coverage).

"Use nyc/c8 as appropriate" would solve this problem, which would go away with Node.js 8 EOL in less than 1 year. Hope this would not add too much complexity:)

Need bcoe/c8#59 to land so we can do --100.

Ugly alternative would be to make a temporary fork

@isaacs
Copy link
Member Author

isaacs commented Jan 23, 2019

I have it on excellent authority that the c8 PR will land long before I get around to doing any of this :)

@mohd-akram
Copy link

Any update on this?

@coreyfarrell
Copy link
Member

You should be able to use c8 tap --no-cov now (be sure to npm i -D c8).

I'm not aware of any firm plans to move forward with switching to c8 now, as of right now the tap v15 WIP branch is upgrading nyc to 15.x. Any further updates will be posted here.

@eljefedelrodeodeljefe
Copy link

I'd also favour making the coverage backend configurable. Running with no-cov and piping, works, however not with --watch.

I face a lot of challenges with {"type": "module"}, that got solved through c8 (but not in the watch scenario)

@isaacs
Copy link
Member Author

isaacs commented Sep 3, 2023

This is in tap 18. npm i tap@pre to get it. Be sure to read through the changelog, as a lot has changed.

@isaacs isaacs closed this as completed Sep 3, 2023
@bennycode
Copy link

@isaacs do you have a link to the commit where the switch from nyc to c8 was happening? I also want to swtich to c8 and could learn from it. In the linked changelog I just found this entry (without a link to the code changes):

Options related to nyc are removed, as nyc is no longer used

@isaacs
Copy link
Member Author

isaacs commented Oct 26, 2023

@bennycode Well, there isn't so much "a" commit as much as "completely rewrote tap, using @tapjs/processinfo, which uses the V8 coverage API directly". When building the @tapjs/run component, I made it pull in C8's Report class to generate the coverage reports.

If you're just switching from nyc to c8, and you're using nyc directly like nyc <command>, you can just do c8 <command> instead, as they have pretty much the exact same API. If you're using nyc internals, well, it's a whole different thing, so you might want to take a look at how @tapjs/processinfo works.

@bennycode
Copy link

Thanks a lot for your answer!

Switching from nyc to c8 was way easier than I expected. If I don't provide a config option, c8 automatically looks for a .nycrc.json file. I had mine named nyc.config.js, so all it took was a rename and removing the "require": ["ts-node/register"] option from my config.

I can now run my tests with good ol' Jasmine in a TypeScript project that has ESM import/export syntax:

{
  "scripts": {
    "test": "c8 --config=.c8rc.coverage.json ts-node-esm ./node_modules/.bin/jasmine --config=jasmine.json"
  }
}

Thanks for your help! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan a feature that is accepted and planned
Projects
None yet
Development

No branches or pull requests

6 participants