7
7
showNycInfo,
8
8
resolveRelativePaths,
9
9
checkAllPathsNotFound,
10
- tryFindingLocalFiles
10
+ tryFindingLocalFiles,
11
+ readNycOptions
11
12
} = require ( './task-utils' )
12
13
const { fixSourcePaths } = require ( './support-utils' )
13
14
const NYC = require ( 'nyc' )
@@ -28,7 +29,6 @@ const pkgFilename = join(processWorkingDirectory, 'package.json')
28
29
const pkg = existsSync ( pkgFilename )
29
30
? JSON . parse ( readFileSync ( pkgFilename , 'utf8' ) )
30
31
: { }
31
- const nycOptions = pkg . nyc || { }
32
32
const scripts = pkg . scripts || { }
33
33
const DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME = 'coverage:report'
34
34
const customNycReportScript = scripts [ DEFAULT_CUSTOM_COVERAGE_SCRIPT_NAME ]
@@ -42,6 +42,37 @@ function saveCoverage(coverage) {
42
42
writeFileSync ( nycFilename , JSON . stringify ( coverage , null , 2 ) )
43
43
}
44
44
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
+
45
76
const tasks = {
46
77
/**
47
78
* Clears accumulated code coverage information.
@@ -122,41 +153,29 @@ const tasks = {
122
153
} )
123
154
}
124
155
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
133
156
// 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' ] )
151
163
}
152
164
153
165
debug ( 'calling NYC reporter with options %o' , nycReportOptions )
154
166
debug ( 'current working directory is %s' , process . cwd ( ) )
155
167
const nyc = new NYC ( nycReportOptions )
156
168
157
169
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
160
179
}
161
180
return nyc . report ( ) . then ( returnReportFolder )
162
181
}
0 commit comments