@pgiletich/cypress-v8-coverage-plugin
v1.0.1
Published
Cypress V8 coverage chrome plugin
Downloads
2
Readme
Cypress V8 Coverage Plugin
this plugin aims at providing codecoverage using the chrome V8 coverage api
It is adapted from this poc
Abilities and limitation
This plugin does :
- gather coverage on multiple tests
- gather coverage on multiple files
- works with chrome
- converts coverage reports to html or lcov
- apply sourcemaps on a report generation
This plugins doesn't
- handle other browser than chrome ( for technical limitation reasons )
- cure all afflictions, make children behave, or long lost loves come back, this is not black magic 🧙♀️.
Usage
Configuration:
required
{...
"env":{
"v8_coverage":{
"include":["glob/**/to/your/files.*js","other/glob"],
"src_root":"path/to/your/src/root",
"collect_coverage_timeout":120000 //optional, this affects the final code collection step, that may timeout if your codebase is big enough
}
}
}
On coverage collection we will replace the url root with the supplied src_root
, and run the glob matching on the result string
Both thoses settings are required as they are used to recognize which files are to be kept amongst all the browser loaded files.
support/index.js
[...]
import "cypress_v8_coverage_plugin/support"
[...]
This allows the plugin to hook on test lifecyle events
plugins/indes.js
const cypress_v8_plugin = require("cypress_v8_coverage_plugin/plugin")
module.exports = (on, config) => {
...
config = cypress_v8_plugin(on,config)
...
return config
}
This registers the plugin in to cypress
Optional Collect
optional
At the end of each spec a collection spec occurs, gathering coverage data from the spec's tests. This can be a lengthy process, to reduce the run cost, you can add the skip_coverage_collection
option :
{...
"env":{
"v8_coverage":{
...,
skip_coverage_collection:true
...
}
}
}
And run independently the src/scripts/collectCoverage.js
script to collect coverage and convert it to istanbul, while applying the sourcemap
Convertion
optional
You can trigger a report convertion to the html
or lcov
through the convert_coverage
task
This run the nyc command through npx on the generated files.
afterAll(()=>{
cy.task("convertCoverage",'html',"./html/report/dir")//use an empty dir, this generates a lot of files
cy.task("convertCoverage","lcov","./lcovpath.info")
})
Otherwise, you can trigger this convertion manualy using nyc or istanbul