@@ -193,6 +193,46 @@ function parseCommandLine() {
193
193
194
194
const isTestRunner = getOptionValue ( '--test' ) ;
195
195
const coverage = getOptionValue ( '--experimental-test-coverage' ) ;
196
+ const checkCoverage = getOptionValue ( '--check-coverage' ) ;
197
+ let coverageCheckThresholds ;
198
+
199
+ if ( checkCoverage ) {
200
+ const coveredLinesThreshold = getOptionValue ( '--lines' ) ;
201
+
202
+ if ( coveredLinesThreshold < 0 || coveredLinesThreshold > 100 ) {
203
+ throw new ERR_INVALID_ARG_VALUE (
204
+ '--lines' ,
205
+ coveredLinesThreshold ,
206
+ 'must be a value between 0 and 100' ,
207
+ ) ;
208
+ }
209
+
210
+ const coveredBranchesThreshold = getOptionValue ( '--branches' ) ;
211
+ if ( coveredBranchesThreshold < 0 || coveredBranchesThreshold > 100 ) {
212
+ throw new ERR_INVALID_ARG_VALUE (
213
+ '--branches' ,
214
+ coveredBranchesThreshold ,
215
+ 'must be a value between 0 and 100' ,
216
+ ) ;
217
+ }
218
+
219
+ const coveredFunctionsThreshold = getOptionValue ( '--functions' ) ;
220
+ if ( coveredFunctionsThreshold < 0 || coveredFunctionsThreshold > 100 ) {
221
+ throw new ERR_INVALID_ARG_VALUE (
222
+ '--functions' ,
223
+ coveredFunctionsThreshold ,
224
+ 'must be a value between 0 and 100' ,
225
+ ) ;
226
+ }
227
+
228
+ coverageCheckThresholds = {
229
+ __proto__ : null ,
230
+ coveredLinesThreshold,
231
+ coveredBranchesThreshold,
232
+ coveredFunctionsThreshold,
233
+ } ;
234
+ }
235
+
196
236
const isChildProcess = process . env . NODE_TEST_CONTEXT === 'child' ;
197
237
const isChildProcessV8 = process . env . NODE_TEST_CONTEXT === 'child-v8' ;
198
238
let destinations ;
@@ -244,6 +284,7 @@ function parseCommandLine() {
244
284
__proto__ : null ,
245
285
isTestRunner,
246
286
coverage,
287
+ coverageCheckThresholds,
247
288
testOnlyFlag,
248
289
testNamePatterns,
249
290
reporters,
@@ -386,8 +427,8 @@ function getCoverageReport(pad, summary, symbol, color, table) {
386
427
// Head
387
428
if ( table ) report += addTableLine ( prefix , tableWidth ) ;
388
429
report += `${ prefix } ${ getCell ( 'file' , filePadLength , StringPrototypePadEnd , truncateEnd ) } ${ kSeparator } ` +
389
- `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( kColumns , ( column , i ) => getCell ( column , columnPadLengths [ i ] , StringPrototypePadStart ) ) , kSeparator ) } ${ kSeparator } ` +
390
- `${ getCell ( 'uncovered lines' , uncoveredLinesPadLength , false , truncateEnd ) } \n` ;
430
+ `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( kColumns , ( column , i ) => getCell ( column , columnPadLengths [ i ] , StringPrototypePadStart ) ) , kSeparator ) } ${ kSeparator } ` +
431
+ `${ getCell ( 'uncovered lines' , uncoveredLinesPadLength , false , truncateEnd ) } \n` ;
391
432
if ( table ) report += addTableLine ( prefix , tableWidth ) ;
392
433
393
434
// Body
@@ -404,14 +445,14 @@ function getCoverageReport(pad, summary, symbol, color, table) {
404
445
fileCoverage /= kColumnsKeys . length ;
405
446
406
447
report += `${ prefix } ${ getCell ( relativePath , filePadLength , StringPrototypePadEnd , truncateStart , fileCoverage ) } ${ kSeparator } ` +
407
- `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( coverages , ( coverage , j ) => getCell ( NumberPrototypeToFixed ( coverage , 2 ) , columnPadLengths [ j ] , StringPrototypePadStart , false , coverage ) ) , kSeparator ) } ${ kSeparator } ` +
408
- `${ getCell ( formatUncoveredLines ( getUncoveredLines ( file . lines ) , table ) , uncoveredLinesPadLength , false , truncateEnd ) } \n` ;
448
+ `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( coverages , ( coverage , j ) => getCell ( NumberPrototypeToFixed ( coverage , 2 ) , columnPadLengths [ j ] , StringPrototypePadStart , false , coverage ) ) , kSeparator ) } ${ kSeparator } ` +
449
+ `${ getCell ( formatUncoveredLines ( getUncoveredLines ( file . lines ) , table ) , uncoveredLinesPadLength , false , truncateEnd ) } \n` ;
409
450
}
410
451
411
452
// Foot
412
453
if ( table ) report += addTableLine ( prefix , tableWidth ) ;
413
454
report += `${ prefix } ${ getCell ( 'all files' , filePadLength , StringPrototypePadEnd , truncateEnd ) } ${ kSeparator } ` +
414
- `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( kColumnsKeys , ( columnKey , j ) => getCell ( NumberPrototypeToFixed ( summary . totals [ columnKey ] , 2 ) , columnPadLengths [ j ] , StringPrototypePadStart , false , summary . totals [ columnKey ] ) ) , kSeparator ) } |\n` ;
455
+ `${ ArrayPrototypeJoin ( ArrayPrototypeMap ( kColumnsKeys , ( columnKey , j ) => getCell ( NumberPrototypeToFixed ( summary . totals [ columnKey ] , 2 ) , columnPadLengths [ j ] , StringPrototypePadStart , false , summary . totals [ columnKey ] ) ) , kSeparator ) } |\n` ;
415
456
if ( table ) report += addTableLine ( prefix , tableWidth ) ;
416
457
417
458
report += `${ prefix } end of coverage report\n` ;
0 commit comments