Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add option to specify custom folder from config
  • Loading branch information
va3y committed May 25, 2022
commit c5d00cc6e8f0ffc431529b0805ef43c1b1e7891a
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ You can specify custom report folder by adding `nyc` object to the `package.json
}
```

In cases, the report folder needs to be set programmatically or outside the root folder config, you can specify it in the plugins. You can modify `reportDir` in the config when passing it to the code-coverage task.

```js
module.exports = (on, config) => {
config.reportDir = 'reports/cypress-report'
require('@cypress/code-coverage/task')(on, config)
return config
}
```


## Custom reporters

You can specify custom coverage reporter(s) to use. For example to output text summary and save JSON report in `cypress-coverage` folder set in your `package.json` folder:
Expand Down
17 changes: 11 additions & 6 deletions task.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const scripts = pkg.scripts || {}
const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report'
const customNycReportScript = scripts[DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME]

const nycReportOptions = (function getNycOption() {
const nycReportOptions = (function getNycOption(a) {
// https://github.com/istanbuljs/nyc#common-configuration-options
const nycReportOptions = readNycOptions(processWorkingDirectory)

Expand Down Expand Up @@ -109,7 +109,7 @@ function maybePrintFinalCoverageFiles(folder) {
})
}

const tasks = {
const createTasks = (config) => ({
/**
* Clears accumulated code coverage information.
*
Expand Down Expand Up @@ -207,10 +207,15 @@ const tasks = {
debug('calling NYC reporter with options %o', nycReportOptions)
debug('current working directory is %s', process.cwd())
const NYC = require('nyc')
const nyc = new NYC(nycReportOptions)
const nyc = new NYC({
...nycReportOptions,
reportDir: config.reportDir
? config.reportDir
: nycReportOptions.reportDir
})

const returnReportFolder = () => {
const reportFolder = nycReportOptions['report-dir']
const reportFolder = config.reportDir || nycReportOptions['report-dir']
debug(
'after reporting, returning the report folder name %s',
reportFolder
Expand All @@ -222,7 +227,7 @@ const tasks = {
}
return nyc.report().then(returnReportFolder)
}
}
})

/**
* Registers code coverage collection and reporting tasks.
Expand All @@ -240,7 +245,7 @@ const tasks = {
```
*/
function registerCodeCoverageTasks(on, config) {
on('task', tasks)
on('task', createTasks(config))

// set a variable to let the hooks running in the browser
// know that they can send coverage commands
Expand Down