1 | initial version |
To integrate TypeScript language with Cypress code coverage plugin, you can follow the below steps:
@cypress/code-coverage
plugin and istanbul-lib-report
package.npm install --save-dev @cypress/code-coverage istanbul-lib-report
tsconfig.test.json
file in the root directory with the following configuration:{
"compilerOptions": {
"target": "es5",
"lib": ["es6", "dom"],
"types": ["cypress"],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"strict": true,
"sourceMap": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "cypress/**/*.ts"]
}
cypress/plugins/index.js
file, add the following code:const cypressTypeScriptPreprocessor = require('./cy-ts-preprocessor')
module.exports = (on) => {
on('file:preprocessor', cypressTypeScriptPreprocessor)
require('@cypress/code-coverage/task')(on, { istanbulLibReport: require('istanbul-lib-report') })
}
cy-ts-preprocessor.js
file in the cypress/plugins
directory with the following code:const preprocessor = require('cypress/typescript-preprocessor')
module.exports = (on) => {
on('file:preprocessor', preprocessor)
}
coverage
flag:npx cypress run --spec cypress/integration/myTest.spec.ts --headed --coverage
By following these steps, you can integrate TypeScript language with Cypress code coverage plugin for generating code coverage reports.