What is the best way to remove "node_modules" from my code coverage analysis?

Developing a web application in TypeScript involves using gulp with various plugins like browserify, tsify, babel, and istanbul to convert TypeScript code into JavaScript, instrument it for coverage analysis, and create sourcemaps. Testing this instrumented code is done using Cypress.

(TypeScript -> Gulp, Browserify, Babel -> Javascript -> Cypress)

However, running Cypress tests shows incorrect code coverage as it includes the node_modules directory. The goal is to exclude node_modules from code coverage to ensure accurate results.

The command npm run test:coverage (found in package.json) executes all necessary steps.

tsconfig.json

{
    "compilerOptions": {
        // Configuration options 
        ...
    },
    "exclude": [
        "dist",
        "docs",
        "gulpfile.js",
        "node_modules"
    ]
}

package.json

{
    // Package details, scripts, dependencies, etc.
    ...
}

gulpfile.js


// Gulp task configuration
...

Project Directory Structure

.
├── coverage
├── cypress
├── docs
│  └── static
│     ├── coverage_badge.svg
├── node_modules
├── src
│  ├── classes
│  ├── components
│  ├── helpers
│  ├── index.ts
│  └── mocks
├── tsconfig.json

Coverage Report Output https://i.sstatic.net/kXqYq.png

NYC Output

npx nyc report
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

Answer №1

Make sure to review the code-coverage README.md. It's important to properly configure the nyc settings in your package.json.

"nyc": {
   "include": [...],
   "exclude": [...]
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Google Sheets displaying blank values after submission via an AJAX call

I have been working on transferring data from my web app to a Google spreadsheet and I am encountering some issues. I followed the script provided by Martin Hawksey, which can be found here: https://gist.github.com/mhawksey/1276293 Despite setting everyth ...

What could be causing the need for RxJs TypeScript files to be requested exclusively when my website is hosted on IIS?

When I develop my site using Visual Studio / IIS Express, everything runs smoothly without any unusual requests or 404 errors. However, once I publish the site to IIS and try to run it, I start receiving multiple requests for typescript files (.ts), prima ...

Tips on transforming JSON into nested JSON using parent_id as a reference

In the given JSON array, each object contains properties 'is_parent' and 'parent_id'. If an object has children objects, its 'is_parent' property is set to 1, otherwise it is set to 0. let list = [ {id: 4, name: 'dd&a ...

A step-by-step guide to activating multi-selection in the Primary SideBar of Visual Studio Code using your custom extension

Currently, I'm in the process of developing an extension for Visual Studio Code where I've added a new activityBar containing treeViews that showcase information pulled from a JSON file. My goal is to enable users to multi-select certain displaye ...

What is the integration between redux and next.js like?

I am currently trying to integrate Redux into an existing Next.js project, but I am struggling to grasp how the store functions server-side. I came across this example that I am following: https://github.com/vercel/next.js/blob/canary/examples/with-redux ...

Leveraging variables retrieved from an asynchronous operation within an Angular template

After logging in, I am trying to retrieve user details but facing delays in getting the data. This issue seems to be caused by an undefined variable at the moment the template loads. How can I prevent this from happening? onLogin() { if (this.loginPass ...

Tips for managing promise rejection when generating a highland stream from a promise?

When working with [email protected] and [email protected] via typescript, the following code snippet is utilized: import * as highland from "highland"; import * as lodash from "lodash/fp"; const range = lodash.range(0, 10); const createPromise ...

JavaScript - Utilizing appendChild as soon as an element becomes available

I'm encountering an issue with my Chrome Extension where I am unable to detect some of the elements that I need to select within a page. var innerChat = document.querySelector('.chat-list'); My goal is to appendChild to this element, but t ...

The interconnected layers of Callback Scope in AngularJS and the overarching rootScope concept

I've been working on an Angular controller to fetch records from a database and display them in a calendar. However, I'm facing an issue where the events array is returning empty. I tried using $rootScope.events as a workaround but encountered an ...

JavaScript encounters difficulty in reading the text file

I am working on a project where I need to read a local text file located at /home/myname/Desktop/iot/public/sensordata.txt using JavaScript when a button is clicked on a web page. Below is the code snippet I have been using: <html> <head> ...

JS: When the 'less than' operator falls short

I am facing an issue with a script that sends an AJAX request every 10 seconds (technically 11) to the user. I have created a simple countdown from 10 to 0 that repeats continuously. The countit function is triggered after each AJAX request to reset the c ...

Tips on creating a unique d3js tree design

I am a beginner when it comes to d3js and javascript in general. My goal is to create an interactive IP administration overview using d3js by modeling json data. I know that the key tool for this job is likely d3.layout.tree, which will provide me with the ...

Initiate a JavaScript promise chain using Bluebird that effectively manages and deals with potential errors

My goal is to efficiently handle all types of errors using the .catch method, including those occurring in initial synchronous code. The approach I want to take for my promise chain is as follows: const bbPromise = require('bluebird'); bbPromis ...

When multiple checkboxes are selected, the corresponding form fields will be automatically filled with shared information

When the user checks multiple checkboxes, corresponding form fields should appear based on the checkboxes selected. For example, if the user checks both the flight and hotel checkboxes, the fields for full name and last name should be displayed, while othe ...

Tips for obtaining the correct Javascript output for the number pyramid

I'm currently in the process of creating a half pyramid of numbers, but I'm facing an issue with getting the output to show the total for each line while maintaining everything except the * sign between the numbers. If anyone is able to offer som ...

Having trouble setting the selected option in Jquery by value?

I have exhausted all options found on the internet. What could I be overlooking? The desired option is not getting selected. Here is the troublesome section of code. I have also included some other attempts that I have commented out. If it helps, this li ...

Variable should contain only two words, with the option to include a dash

I am looking for a way to limit users from inputting more than two words, but still allow words with a dash in them. Allowed Mike-David Smith Not Allowed Mike David Smith The code I have only restricts input to two words and does not consider words wi ...

Hide the selection box when hovering over the Div

Looking for a quick solution. I want the option drop down to close when another div element is hovered over. First, open the drop down and hover over the red element on the right side. When hovering over the red element, I would like the drop down to clos ...

Hovering over the Chart.js tooltip does not display the labels as expected

How can I show the numberValue value as a label on hover over the bar chart? Despite trying various methods, nothing seems to appear when hovering over the bars. Below is the code snippet: getBarChart() { this.http.get(API).subscribe({ next: (d ...

The notifier in gulp-notify is displaying an error message: Plugin 'gulp-notify' could not be found - notify-send

I'm having trouble setting up Gulp in my Laravel 5.1 installation. I followed the instructions in the Laravel documentation and ran npm install, which went smoothly. However, when I try to execute the gulp command, I receive the following message: u ...