77 showNycInfo,
88 resolveRelativePaths,
99 checkAllPathsNotFound,
10- tryFindingLocalFiles
10+ tryFindingLocalFiles,
11+ readNycOptions
1112} = require ( './task-utils' )
1213const { fixSourcePaths } = require ( './support-utils' )
1314const NYC = require ( 'nyc' )
@@ -28,7 +29,6 @@ const pkgFilename = join(processWorkingDirectory, 'package.json')
2829const pkg = existsSync ( pkgFilename )
2930 ? JSON . parse ( readFileSync ( pkgFilename , 'utf8' ) )
3031 : { }
31- const nycOptions = pkg . nyc || { }
3232const scripts = pkg . scripts || { }
3333const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report'
3434const customNycReportScript = scripts [ DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME ]
@@ -42,6 +42,37 @@ function saveCoverage(coverage) {
4242 writeFileSync ( nycFilename , JSON . stringify ( coverage , null , 2 ) )
4343}
4444
45+ function maybePrintFinalCoverageFiles ( folder ) {
46+ const jsonReportFilename = join ( folder , 'coverage-final.json' )
47+ if ( ! existsSync ) {
48+ debug ( 'Did not find final coverage file %s' , jsonReportFilename )
49+ return
50+ }
51+
52+ debug ( 'Final coverage in %s' , jsonReportFilename )
53+ const finalCoverage = JSON . parse ( readFileSync ( jsonReportFilename , 'utf8' ) )
54+ Object . keys ( finalCoverage ) . forEach ( key => {
55+ const s = finalCoverage [ key ] . s || { }
56+ const statements = Object . keys ( s )
57+ const totalStatements = statements . length
58+ let coveredStatements = 0
59+ statements . forEach ( statementKey => {
60+ if ( s [ statementKey ] ) {
61+ coveredStatements += 1
62+ }
63+ } )
64+
65+ const allCovered = coveredStatements === totalStatements
66+ debug (
67+ '%s %s statements covered %d/%d' ,
68+ allCovered ? '✅' : '⚠️' ,
69+ key ,
70+ coveredStatements ,
71+ totalStatements
72+ )
73+ } )
74+ }
75+
4576const tasks = {
4677 /**
4778 * Clears accumulated code coverage information.
@@ -122,41 +153,29 @@ const tasks = {
122153 } )
123154 }
124155
125- const reportFolder = nycOptions [ 'report-dir' ] || './coverage'
126- const reportDir = resolve ( reportFolder )
127- const reporter = nycOptions [ 'reporter' ] || [ 'lcov' , 'clover' , 'json' ]
128-
129- // TODO we could look at how NYC is parsing its CLI arguments
130- // I am mostly worried about additional NYC options that are stored in
131- // package.json and .nycrc resource files.
132- // for now let's just camel case all options
133156 // https://github.com/istanbuljs/nyc#common-configuration-options
134- const nycReportOptions = {
135- reportDir,
136- tempDir : coverageFolder ,
137- reporter : [ ] . concat ( reporter ) , // make sure this is a list
138- include : nycOptions . include ,
139- exclude : nycOptions . exclude ,
140- // from working with TypeScript code seems we need these settings too
141- excludeAfterRemap : true ,
142- extension : nycOptions . extension || [
143- '.js' ,
144- '.cjs' ,
145- '.mjs' ,
146- '.ts' ,
147- '.tsx' ,
148- '.jsx'
149- ] ,
150- all : nycOptions . all
157+ const nycReportOptions = readNycOptions ( processWorkingDirectory )
158+
159+ // override a couple of options
160+ nycReportOptions . tempDir = coverageFolder
161+ if ( nycReportOptions [ 'report-dir' ] ) {
162+ nycReportOptions [ 'report-dir' ] = resolve ( nycReportOptions [ 'report-dir' ] )
151163 }
152164
153165 debug ( 'calling NYC reporter with options %o' , nycReportOptions )
154166 debug ( 'current working directory is %s' , process . cwd ( ) )
155167 const nyc = new NYC ( nycReportOptions )
156168
157169 const returnReportFolder = ( ) => {
158- debug ( 'after reporting, returning the report folder name %s' , reportDir )
159- return reportDir
170+ const reportFolder = nycReportOptions [ 'report-dir' ]
171+ debug (
172+ 'after reporting, returning the report folder name %s' ,
173+ reportFolder
174+ )
175+
176+ maybePrintFinalCoverageFiles ( reportFolder )
177+
178+ return reportFolder
160179 }
161180 return nyc . report ( ) . then ( returnReportFolder )
162181 }
0 commit comments