@@ -38,11 +38,9 @@ function saveCoverage(coverage) {
38
38
}
39
39
40
40
/**
41
- * Looks at all coverage objects in the given JSON coverage file
42
- * and if the file is relative, and exists, changes its path to
43
- * be absolute.
41
+ * A small debug utility to inspect paths saved in NYC output JSON file
44
42
*/
45
- function resolvePaths ( nycFilename ) {
43
+ function showNycInfo ( nycFilename ) {
46
44
const nycCoverage = JSON . parse ( readFileSync ( nycFilename , 'utf8' ) )
47
45
48
46
const coverageKeys = Object . keys ( nycCoverage )
@@ -52,17 +50,39 @@ function resolvePaths(nycFilename) {
52
50
}
53
51
debug ( 'NYC file %s has %d key(s)' , nycFilename , coverageKeys . length )
54
52
55
- let changed
56
53
const maxPrintKeys = 3
54
+ const showKeys = coverageKeys . slice ( 0 , maxPrintKeys )
57
55
58
- Object . keys ( nycCoverage ) . forEach ( ( key , k ) => {
56
+ showKeys . forEach ( ( key , k ) => {
59
57
const coverage = nycCoverage [ key ]
60
58
61
59
// printing a few found keys and file paths from the coverage file
62
60
// will make debugging any problems much much easier
63
61
if ( k < maxPrintKeys ) {
64
62
debug ( '%d key %s file path %s' , k + 1 , key , coverage . path )
65
63
}
64
+ } )
65
+ }
66
+
67
+ /**
68
+ * Looks at all coverage objects in the given JSON coverage file
69
+ * and if the file is relative, and exists, changes its path to
70
+ * be absolute.
71
+ */
72
+ function resolvePaths ( nycFilename ) {
73
+ const nycCoverage = JSON . parse ( readFileSync ( nycFilename , 'utf8' ) )
74
+
75
+ const coverageKeys = Object . keys ( nycCoverage )
76
+ if ( ! coverageKeys . length ) {
77
+ console . error ( '⚠️ file %s has no coverage information' , nycFilename )
78
+ return
79
+ }
80
+ debug ( 'NYC file %s has %d key(s)' , nycFilename , coverageKeys . length )
81
+
82
+ let changed
83
+
84
+ coverageKeys . forEach ( ( key , k ) => {
85
+ const coverage = nycCoverage [ key ]
66
86
67
87
if ( coverage . path && ! isAbsolute ( coverage . path ) ) {
68
88
if ( existsSync ( coverage . path ) ) {
@@ -143,6 +163,7 @@ const tasks = {
143
163
return null
144
164
}
145
165
166
+ showNycInfo ( nycFilename )
146
167
resolvePaths ( nycFilename )
147
168
148
169
if ( customNycReportScript ) {
0 commit comments