Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
test-exclude
Advanced tools
The test-exclude npm package is used to filter out files that should not be included in test coverage calculations. It allows developers to specify patterns for files to be excluded from coverage reports, typically when using a coverage tool like Istanbul.
Exclude files from coverage
This feature allows developers to define patterns for files that should be excluded from test coverage. The code sample shows an example configuration where files in the node_modules and test directories, as well as files ending with .spec.js, are excluded.
{"exclude": ["**/node_modules/**", "test/**", "**/*.spec.js"]}
Include files in coverage
In contrast to excluding files, this feature allows developers to specify which files should be included in the coverage report. The code sample demonstrates how to include all JavaScript files in the src directory.
{"include": ["src/**/*.js"]}
Use with coverage tools
This feature integrates with coverage tools to determine if a file should be instrumented for coverage. The code sample shows how to use test-exclude to check if a file, in this case './src/index.js', should be included in the coverage report.
const testExclude = require('test-exclude');
const exclude = testExclude({
exclude: ['**/node_modules/**', 'test/**']
});
console.log(exclude.shouldInstrument('./src/index.js')); // true or false
nyc is a command-line-interface for Istanbul, a popular JavaScript test coverage tool. It includes functionality similar to test-exclude for specifying which files to include or exclude from coverage reports. nyc provides a more comprehensive set of features for handling test coverage.
c8 is a test coverage tool that uses V8's built-in code-coverage rather than instrumenting the code like Istanbul. It also allows for excluding files from coverage reports. c8 is built to work well with modern JavaScript features and provides a simpler setup compared to Istanbul and test-exclude.
The file include/exclude logic used by nyc.
const exclude = require('test-exclude')
if (exclude().shouldInstrument('./foo.js')) {
// let's instrument this file for test coverage!
}
you can load configuration from a key in package.json:
package.json
{
"name": "awesome-module",
"test": {
"include": ["**/index.js"]
}
}
app.js
const exclude = require('test-exclude')
if (exclude({configKey: 'test'}).shouldInstrument('./index.js')) {
// let's instrument this file for test coverage!
}
by default the node_modules
folder is added to all groups of
exclude rules. In the rare case that you wish to instrument files
stored in node_modules
, a negative glob can be used:
const exclude = require('test-exclude')
const e = exclude({
exclude: ['!**/node_modules/**']
})
ISC
FAQs
test for inclusion or exclusion of paths using globs
The npm package test-exclude receives a total of 26,820,653 weekly downloads. As such, test-exclude popularity was classified as popular.
We found that test-exclude demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.