1010'use strict' ;
1111
1212const path = require ( 'path' ) ;
13- const { cleanup, writeFiles} = require ( '../Utils' ) ;
13+ const { cleanup, writeFiles, extractSummary } = require ( '../Utils' ) ;
1414const runJest = require ( '../runJest' ) ;
1515
1616const DIR = path . resolve ( __dirname , '../coverage-threshold' ) ;
1717
1818beforeEach ( ( ) => cleanup ( DIR ) ) ;
1919afterAll ( ( ) => cleanup ( DIR ) ) ;
2020
21- const replaceTime = str => {
22- return str . replace ( / \d * \. ? \d + m ? s / g, '<<REPLACED>>' ) ;
23- } ;
24-
2521test ( 'exits with 1 if coverage threshold is not met' , ( ) => {
2622 const pkgJson = {
2723 jest : {
@@ -49,9 +45,12 @@ test('exits with 1 if coverage threshold is not met', () => {
4945 } ) ;
5046
5147 const { stdout, stderr, status} = runJest ( DIR , [ '--coverage' , '--ci=false' ] ) ;
48+ const { rest, summary} = extractSummary ( stderr ) ;
49+
5250 expect ( status ) . toBe ( 1 ) ;
51+ expect ( rest ) . toMatchSnapshot ( ) ;
52+ expect ( summary ) . toMatchSnapshot ( ) ;
5353 expect ( stdout ) . toMatchSnapshot ( 'stdout' ) ;
54- expect ( replaceTime ( stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
5554} ) ;
5655
5756test ( 'exits with 1 if path threshold group is not found in coverage data' , ( ) => {
@@ -81,10 +80,12 @@ test('exits with 1 if path threshold group is not found in coverage data', () =>
8180 } ) ;
8281
8382 const { stdout, stderr, status} = runJest ( DIR , [ '--coverage' , '--ci=false' ] ) ;
83+ const { rest, summary} = extractSummary ( stderr ) ;
8484
8585 expect ( status ) . toBe ( 1 ) ;
86+ expect ( rest ) . toMatchSnapshot ( ) ;
87+ expect ( summary ) . toMatchSnapshot ( ) ;
8688 expect ( stdout ) . toMatchSnapshot ( 'stdout' ) ;
87- expect ( replaceTime ( stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
8889} ) ;
8990
9091test ( 'exits with 0 if global threshold group is not found in coverage data' , ( ) => {
@@ -157,10 +158,12 @@ test('excludes tests matched by path threshold groups from global group', () =>
157158 } ) ;
158159
159160 const { stdout, stderr, status} = runJest ( DIR , [ '--coverage' , '--ci=false' ] ) ;
161+ const { rest, summary} = extractSummary ( stderr ) ;
160162
161163 expect ( status ) . toBe ( 1 ) ;
164+ expect ( rest ) . toMatchSnapshot ( ) ;
165+ expect ( summary ) . toMatchSnapshot ( ) ;
162166 expect ( stdout ) . toMatchSnapshot ( 'stdout' ) ;
163- expect ( replaceTime ( stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
164167} ) ;
165168
166169test ( 'file is matched by all path and glob threshold groups' , ( ) => {
@@ -172,10 +175,10 @@ test('file is matched by all path and glob threshold groups', () => {
172175 './' : {
173176 lines : 100 ,
174177 } ,
175- 'ban*.js' : {
178+ './ ban*.js' : {
176179 lines : 100 ,
177180 } ,
178- 'banana.js' : {
181+ './ banana.js' : {
179182 lines : 100 ,
180183 } ,
181184 } ,
@@ -196,10 +199,17 @@ test('file is matched by all path and glob threshold groups', () => {
196199 } ) ;
197200
198201 const { stdout, stderr, status} = runJest ( DIR , [ '--coverage' , '--ci=false' ] ) ;
202+ const { rest, summary} = extractSummary (
203+ /* This test also runs on windows and when the glob fails it outputs
204+ the system specific absolute path to the test file. */
205+ stderr . replace (
206+ path . resolve ( DIR , './banana.js' ) ,
207+ '<<FULL_PATH_TO_BANANA_JS>>' ,
208+ ) ,
209+ ) ;
199210
200211 expect ( status ) . toBe ( 1 ) ;
212+ expect ( rest ) . toMatchSnapshot ( ) ;
213+ expect ( summary ) . toMatchSnapshot ( ) ;
201214 expect ( stdout ) . toMatchSnapshot ( 'stdout' ) ;
202- expect (
203- replaceTime ( stderr ) . replace ( process . cwd ( ) , '<<REPLACED>>' ) ,
204- ) . toMatchSnapshot ( 'stderr' ) ;
205215} ) ;
0 commit comments