11const process = require ( "process" ) ;
22const cp = require ( "child_process" ) ;
33const path = require ( "path" ) ;
4+ const { fail } = require ( "assert" ) ;
45
5- test ( "test runs " , ( ) => {
6- const lcovPath = "./fixtures/lcov.info" ;
6+ test ( "invalid LCOV format throws an error " , ( ) => {
7+ const lcovPath = "./fixtures/lcov.error. info" ;
78 process . env [ "INPUT_PATH" ] = lcovPath ;
89 const ip = path . join ( __dirname , "index.js" ) ;
9- const actual = cp . execSync ( `node ${ ip } ` , { env : process . env } ) . toString ( ) ;
10- const expected = '::debug::100\n' ;
11- expect ( actual ) . toEqual ( expected ) ;
10+ try {
11+ cp . execSync ( `node ${ ip } ` , { env : process . env } ) . toString ( ) ;
12+ fail ( 'this code should fail' ) ;
13+ } catch ( err ) {
14+ expect ( err ) . toBeDefined ( ) ;
15+ }
1216} ) ;
17+
18+ test ( "completes when the coverage is 100 and min_coverage is not provided" , ( ) => {
19+ const lcovPath = "./fixtures/lcov.100.info" ;
20+ process . env [ "INPUT_PATH" ] = lcovPath ;
21+ const ip = path . join ( __dirname , "index.js" ) ;
22+ cp . execSync ( `node ${ ip } ` , { env : process . env } ) . toString ( ) ;
23+ } ) ;
24+
25+ test ( "fails when the coverage is not 100 and min_coverage is not provided" , ( ) => {
26+ const lcovPath = "./fixtures/lcov.95.info" ;
27+ process . env [ "INPUT_PATH" ] = lcovPath ;
28+ const ip = path . join ( __dirname , "index.js" ) ;
29+ try {
30+ cp . execSync ( `node ${ ip } ` , { env : process . env } ) . toString ( ) ;
31+ fail ( 'this code should fail' ) ;
32+ } catch ( err ) {
33+ expect ( err ) . toBeDefined ( ) ;
34+ }
35+ } ) ;
36+
37+ test ( "completes when the coverage is above the given min_threshold" , ( ) => {
38+ const lcovPath = "./fixtures/lcov.95.info" ;
39+ const minCoverage = 80 ;
40+ process . env [ "INPUT_PATH" ] = lcovPath ;
41+ process . env [ "INPUT_MIN_COVERAGE" ] = minCoverage ;
42+ const ip = path . join ( __dirname , "index.js" ) ;
43+ cp . execSync ( `node ${ ip } ` , { env : process . env } ) . toString ( ) ;
44+ } ) ;
45+
46+ test ( "fails when the coverage is below the given min_threshold" , ( ) => {
47+ const lcovPath = "./fixtures/lcov.95.info" ;
48+ const minCoverage = 98 ;
49+ process . env [ "INPUT_PATH" ] = lcovPath ;
50+ process . env [ "INPUT_MIN_COVERAGE" ] = minCoverage ;
51+ const ip = path . join ( __dirname , "index.js" ) ;
52+ try {
53+ cp . execSync ( `node ${ ip } ` , { env : process . env } ) . toString ( ) ;
54+ fail ( 'this code should fail' ) ;
55+ } catch ( err ) {
56+ expect ( err ) . toBeDefined ( ) ;
57+ }
58+ } ) ;
0 commit comments