Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to specify custom folder from config #566

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 a custom report folder by adding `nyc` object to the `package.js
}
```

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