File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
- # check-code-coverage [ ![ ci status] [ ci image ]] [ ci url ] ![ mock coverage] ( https://img.shields.io/badge/code--coverage-100%-brightgreen )
1
+ # check-code-coverage [ ![ ci status] [ ci image ]] [ ci url ] ![ check-code- coverage] ( https://img.shields.io/badge/code--coverage-100%-brightgreen )
2
2
> Utilities for checking the coverage produced by NYC against extra or missing files
3
3
4
4
## Use
@@ -34,7 +34,7 @@ check-total --from coverage/coverage-summary.json --min 80
34
34
35
35
If your README.md includes Shields.io badge, like this
36
36
37
- 
37
+ 
38
38
39
39
You can update it using statements covered percentage from ` coverage/coverage-summary.json ` by running
40
40
@@ -44,12 +44,14 @@ update-badge
44
44
45
45
If the coverage summary has 96%, then the above badge would be updated to
46
46
47
- 
47
+ 
48
48
49
49
Related project: [ dependency-version-badge] ( https://github.com/bahmutov/dependency-version-badge )
50
50
51
51
The badges will have different colors, depending on the coverage, see [ bin/update-badge.js] ( bin/update-badge.js )
52
52
53
+ If the code coverage badge is not found, a new badge is inserted on the first line.
54
+
53
55
## Debug
54
56
55
57
To see verbose log messages, run with ` DEBUG=check-code-coverage ` environment variable
Original file line number Diff line number Diff line change 4
4
const debug = require ( 'debug' ) ( 'check-code-coverage' )
5
5
const path = require ( 'path' )
6
6
const fs = require ( 'fs' )
7
+ const os = require ( 'os' )
7
8
8
9
const availableColors = [ 'red' , 'yellow' , 'green' , 'brightgreen' ]
9
10
@@ -47,13 +48,31 @@ function updateBadge() {
47
48
debug ( 'coverage regex: "%s"' , coverageRe )
48
49
debug ( 'new coverage badge: "%s"' , coverageBadge )
49
50
50
- const updatedReadmeText = readmeText . replace (
51
+ let found
52
+ let updatedReadmeText = readmeText . replace (
51
53
coverageRe ,
52
54
( match ) => {
55
+ found = true
53
56
debug ( 'match: %o' , match )
54
57
return coverageBadge
55
58
} ,
56
59
)
60
+
61
+ if ( ! found ) {
62
+ console . log ( '⚠️ Could not find code coverage badge in file %s' , readmeFilename )
63
+ console . log ( 'Insert new badge on the first line' )
64
+ // use NPM package name as label to flag where this badge is coming from
65
+ const badge = ``
66
+ debug ( 'inserting new badge: %s' , badge )
67
+
68
+ const lines = readmeText . split ( os . EOL )
69
+ if ( lines . length < 1 ) {
70
+ console . error ( 'File %s has no lines, cannot insert code coverage badge' , readmeFilename )
71
+ return readmeText
72
+ }
73
+ lines [ 0 ] += ' ' + badge
74
+ updatedReadmeText = lines . join ( os . EOL )
75
+ }
57
76
return updatedReadmeText
58
77
}
59
78
You can’t perform that action at this time.
0 commit comments