Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
The c8 npm package is a code coverage tool for JavaScript that works with the native V8 coverage functionality built into Node.js. It collects and reports on the test coverage of your code, helping you understand which parts of your codebase are covered by tests and which are not.
Code Coverage Reporting
This command runs your Node.js script with coverage tracking, and upon completion, it outputs a coverage report. The report shows the percentage of code executed by your tests, helping you identify untested parts of your codebase.
npx c8 node script.js
Integration with Testing Frameworks
You can use c8 in conjunction with testing frameworks like Mocha. This command will run Mocha tests with coverage tracking, and then generate a coverage report.
npx c8 mocha
Custom Report Formats
c8 allows you to specify one or more reporters that determine the format of the coverage report. In this example, it generates both 'lcov' and 'text' format reports.
npx c8 --reporter=lcov --reporter=text node script.js
Check Coverage Thresholds
This feature allows you to enforce coverage thresholds. If the coverage falls below the specified percentages for lines, functions, or branches, c8 will exit with a non-zero status, which is useful for CI/CD pipelines.
npx c8 --check-coverage --lines 95 --functions 95 --branches 95 node script.js
Previously known as Istanbul, nyc is another popular code coverage tool for JavaScript. It works with a wide range of testing frameworks and can instrument code for coverage reporting. Compared to c8, nyc has been around longer and has more configuration options, but c8 is built to leverage the native V8 coverage and might be faster and more accurate for Node.js applications.
Jest is a testing framework that includes built-in code coverage reporting. While Jest is primarily a testing framework, its coverage tool is often compared to standalone tools like c8. Jest's coverage is implemented using Istanbul under the hood. Compared to c8, Jest provides an all-in-one solution for testing and coverage but may not be as lightweight if you only need coverage reporting.
Coveralls is a web service that helps you track your code coverage over time, ensure that all your new code is fully covered, and integrate with your CI environment. While not a coverage tool itself, it works with tools like c8 or nyc to provide visibility into code coverage statistics. Compared to c8, Coveralls adds a layer of historical tracking and visualization to coverage data.
Code-coverage using v8's Profiler that's compatible with Istanbul's reporters.
Like nyc, c8 just magically works, simply:
npm i c8 -g
c8 node foo.js
The above example will collect coverage for foo.js
using v8's profiler.
TODO:
write logic for converting v8 coverage output to Istanbul Coverage.json format.
talk to Node.js project about silencing messages:
Debugger listening on ws://127.0.0.1:56399/e850110a-c5df-41d8-8ef2-400f6829617f
.
figure out why detailed
mode does not appear to be working.
figure out a better way to determine that all processes in event loop have terminated (except the inspector session).
process.exit() can't perform an async operation; how can we track coverage for scripts that exit?
FAQs
output coverage reports using Node.js' built in coverage
The npm package c8 receives a total of 1,492,563 weekly downloads. As such, c8 popularity was classified as popular.
We found that c8 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.