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 |
----------|---------|----------|---------|---------|-------------------