Skip to content
Merged
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
Prev Previous commit
Next Next commit
insert empty coverage for missed files
  • Loading branch information
bahmutov committed Apr 21, 2020
commit e87a9e327a8e91c0adb32fbd8ce8502722166051
38 changes: 38 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,43 @@ workflows:
../../node_modules/.bin/only-covered main.js
working_directory: examples/support-files

- cypress/run:
attach-workspace: true
name: example-all-files
requires:
- cypress/install
# there are no jobs to follow this one
# so no need to save the workspace files (saves time)
no-workspace: true
start: npm start --prefix examples/all-files
wait-on: 'http://localhost:1234'
command: npx cypress run --project examples/all-files
# store screenshots and videos
store_artifacts: true
post-steps:
- run: cat examples/all-files/.nyc_output/out.json
- run: cat examples/all-files/coverage/coverage-final.json
# store the created coverage report folder
# you can click on it in the CircleCI UI
# to see live static HTML site
- store_artifacts:
path: examples/all-files/coverage
# make sure the examples captures 100% of code
- run:
command: npx nyc report --check-coverage true --lines 100
working_directory: examples/all-files
- run:
name: Check code coverage 📈
# we will check the final coverage report
# to make sure it only has files we are interested in
# because there are files covered at 0 in the report
# TODO confirm "not-covered.js" is at 0/0 but included in the report
command: |
../../node_modules/.bin/check-coverage main.js
../../node_modules/.bin/check-coverage second.js
# ../../node_modules/.bin/only-covered --from coverage/coverage-final.json main.js
working_directory: examples/all-files

- cypress/run:
attach-workspace: true
name: example-exclude-files
Expand Down Expand Up @@ -467,3 +504,4 @@ workflows:
- example-exclude-files
- example-docker-paths
- example-use-webpack
- example-all-files
3 changes: 2 additions & 1 deletion examples/all-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"cy:open": "../../node_modules/.bin/cypress open",
"cy:run": "../../node_modules/.bin/cypress run",
"dev": "../../node_modules/.bin/start-test 1234 cy:open",
"e2e": "../../node_modules/.bin/start-test 1234 cy:run"
"e2e": "../../node_modules/.bin/start-test 1234 cy:run",
"report": "../../node_modules/.bin/nyc report"
},
"nyc": {
"all": true,
Expand Down
39 changes: 36 additions & 3 deletions task-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function tryFindingLocalFiles(nycFilename) {
*
* @see https://github.com/cypress-io/code-coverage/issues/207
*/
function includeAllFiles(nycOptions) {
function includeAllFiles(nycFilename, nycOptions) {
debug('include all files options: %o', {
all: nycOptions.all,
include: nycOptions.include,
Expand All @@ -298,9 +298,42 @@ function includeAllFiles(nycOptions) {

debug('searching files to include using patterns %o', patterns)

const allFiles = globby.sync(patterns)
const allFiles = globby.sync(patterns, { absolute: true })
debug('found these files %o', allFiles)
// TODO check if any of the files to include are missing from NYC output JSON file

const nycCoverage = JSON.parse(readFileSync(nycFilename, 'utf8'))
const coverageKeys = Object.keys(nycCoverage)
const coveredPaths = coverageKeys.map(key => nycCoverage[key].path)
debug('coverage has the following paths %o', coveredPaths)

let changed
allFiles.forEach(fullPath => {
if (coveredPaths.includes(fullPath)) {
// all good, this file exists in coverage object
return
}
debug('adding empty coverage for file %s', fullPath)
changed = true
// insert placeholder object for now
nycCoverage[fullPath] = {
path: fullPath,
statementMap: {},
fnMap: {},
branchMap: {},
s: {},
f: {},
b: {}
}
})

if (changed) {
debug('saving updated file %s', nycFilename)
writeFileSync(
nycFilename,
JSON.stringify(nycCoverage, null, 2) + '\n',
'utf8'
)
}
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion task.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const tasks = {

if (nycReportOptions.all) {
debug('nyc needs to report on all included files')
includeAllFiles(nycReportOptions)
includeAllFiles(nycFilename, nycReportOptions)
}

debug('calling NYC reporter with options %o', nycReportOptions)
Expand Down