@@ -10,6 +10,7 @@ const assert = require('assert');
1010const { spawnSync } = require ( 'child_process' ) ;
1111const tmpdir = require ( '../common/tmpdir' ) ;
1212const fixtures = require ( '../common/fixtures' ) ;
13+ const { expectSyncExitWithoutError } = require ( '../common/child_process' ) ;
1314const fs = require ( 'fs' ) ;
1415
1516const warningScript = fixtures . path ( 'snapshot' , 'warning.js' ) ;
@@ -27,12 +28,7 @@ tmpdir.refresh();
2728 ] , {
2829 cwd : tmpdir . path
2930 } ) ;
30- console . log ( '[stderr]:' , child . stderr . toString ( ) ) ;
31- console . log ( '[stdout]:' , child . stdout . toString ( ) ) ;
32- if ( child . status !== 0 ) {
33- console . log ( child . signal ) ;
34- assert . strictEqual ( child . status , 0 ) ;
35- }
31+ expectSyncExitWithoutError ( child ) ;
3632 const stats = fs . statSync ( blobPath ) ;
3733 assert ( stats . isFile ( ) ) ;
3834
@@ -43,14 +39,14 @@ tmpdir.refresh();
4339 ] , {
4440 cwd : tmpdir . path
4541 } ) ;
46- console . log ( '[stderr]:' , child . stderr . toString ( ) ) ;
47- console . log ( '[stdout]:' , child . stdout . toString ( ) ) ;
48- if ( child . status !== 0 ) {
49- console . log ( child . signal ) ;
50- assert . strictEqual ( child . status , 0 ) ;
51- }
52- const match = child . stderr . toString ( ) . match ( / W a r n i n g : t e s t w a r n i n g / g ) ;
53- assert . strictEqual ( match . length , 1 ) ;
42+ expectSyncExitWithoutError ( child , {
43+ stderr ( output ) {
44+ const match = output . match ( / W a r n i n g : t e s t w a r n i n g / g ) ;
45+ assert . strictEqual ( match . length , 1 ) ;
46+ return true ;
47+ }
48+ } ) ;
49+
5450}
5551
5652tmpdir . refresh ( ) ;
@@ -65,18 +61,17 @@ tmpdir.refresh();
6561 ] , {
6662 cwd : tmpdir . path
6763 } ) ;
68- console . log ( '[stderr]:' , child . stderr . toString ( ) ) ;
69- console . log ( '[stdout]:' , child . stdout . toString ( ) ) ;
70- if ( child . status !== 0 ) {
71- console . log ( child . signal ) ;
72- assert . strictEqual ( child . status , 0 ) ;
73- }
64+ expectSyncExitWithoutError ( child , {
65+ stderr ( output ) {
66+ let match = output . match ( / W a r n i n g : t e s t w a r n i n g / g) ;
67+ assert . strictEqual ( match . length , 1 ) ;
68+ match = output . match ( / U s e ` n o d e - - t r a c e - w a r n i n g s / g) ;
69+ assert . strictEqual ( match . length , 1 ) ;
70+ return true ;
71+ }
72+ } ) ;
7473 const stats = fs . statSync ( blobPath ) ;
7574 assert ( stats . isFile ( ) ) ;
76- let match = child . stderr . toString ( ) . match ( / W a r n i n g : t e s t w a r n i n g / g) ;
77- assert . strictEqual ( match . length , 1 ) ;
78- match = child . stderr . toString ( ) . match ( / U s e ` n o d e - - t r a c e - w a r n i n g s / g) ;
79- assert . strictEqual ( match . length , 1 ) ;
8075
8176 child = spawnSync ( process . execPath , [
8277 '--snapshot-blob' ,
@@ -85,17 +80,17 @@ tmpdir.refresh();
8580 ] , {
8681 cwd : tmpdir . path
8782 } ) ;
88- console . log ( '[stderr]:' , child . stderr . toString ( ) ) ;
89- console . log ( '[stdout]:' , child . stdout . toString ( ) ) ;
90- if ( child . status !== 0 ) {
91- console . log ( child . signal ) ;
92- assert . strictEqual ( child . status , 0 ) ;
93- }
94- // Warnings should not be handled more than once.
95- match = child . stderr . toString ( ) . match ( / W a r n i n g : t e s t w a r n i n g / g ) ;
96- assert . strictEqual ( match . length , 1 ) ;
97- match = child . stderr . toString ( ) . match ( / U s e ` n o d e - - t r a c e - w a r n i n g s / g ) ;
98- assert . strictEqual ( match . length , 1 ) ;
83+
84+ expectSyncExitWithoutError ( child , {
85+ stderr ( output ) {
86+ // Warnings should not be handled more than once.
87+ let match = output . match ( / W a r n i n g : t e s t w a r n i n g / g ) ;
88+ assert . strictEqual ( match . length , 1 ) ;
89+ match = output . match ( / U s e ` n o d e - - t r a c e - w a r n i n g s / g ) ;
90+ assert . strictEqual ( match . length , 1 ) ;
91+ return true ;
92+ }
93+ } ) ;
9994}
10095
10196tmpdir . refresh ( ) ;
@@ -114,25 +109,26 @@ tmpdir.refresh();
114109 ] , {
115110 cwd : tmpdir . path
116111 } ) ;
117- console . log ( '[stderr]:' , child . stderr . toString ( ) ) ;
118- console . log ( '[stdout]:' , child . stdout . toString ( ) ) ;
119- if ( child . status !== 0 ) {
120- console . log ( child . signal ) ;
121- assert . strictEqual ( child . status , 0 ) ;
122- }
112+
113+ expectSyncExitWithoutError ( child , {
114+ stderr ( output ) {
115+ assert . doesNotMatch ( output , / W a r n i n g : t e s t w a r n i n g / ) ;
116+ }
117+ } ) ;
118+
123119 const stats = fs . statSync ( blobPath ) ;
124120 assert ( stats . isFile ( ) ) ;
121+
125122 const warnings1 = fs . readFileSync ( warningFile1 , 'utf8' ) ;
126123 console . log ( warningFile1 , ':' , warnings1 ) ;
127124 let match = warnings1 . match ( / W a r n i n g : t e s t w a r n i n g / g) ;
128125 assert . strictEqual ( match . length , 1 ) ;
129126 match = warnings1 . match ( / U s e ` n o d e - - t r a c e - w a r n i n g s / g) ;
130127 assert . strictEqual ( match . length , 1 ) ;
131- assert . doesNotMatch ( child . stderr . toString ( ) , / W a r n i n g : t e s t w a r n i n g / ) ;
132-
133128 fs . rmSync ( warningFile1 , {
134129 maxRetries : 3 , recursive : false , force : true
135130 } ) ;
131+
136132 child = spawnSync ( process . execPath , [
137133 '--snapshot-blob' ,
138134 blobPath ,
@@ -142,12 +138,13 @@ tmpdir.refresh();
142138 ] , {
143139 cwd : tmpdir . path
144140 } ) ;
145- console . log ( '[stderr]:' , child . stderr . toString ( ) ) ;
146- console . log ( '[stdout]:' , child . stdout . toString ( ) ) ;
147- if ( child . status !== 0 ) {
148- console . log ( child . signal ) ;
149- assert . strictEqual ( child . status , 0 ) ;
150- }
141+
142+ expectSyncExitWithoutError ( child , {
143+ stderr ( output ) {
144+ assert . doesNotMatch ( output , / W a r n i n g : t e s t w a r n i n g / ) ;
145+ return true ;
146+ }
147+ } ) ;
151148 assert ( ! fs . existsSync ( warningFile1 ) ) ;
152149
153150 const warnings2 = fs . readFileSync ( warningFile2 , 'utf8' ) ;
@@ -156,5 +153,4 @@ tmpdir.refresh();
156153 assert . strictEqual ( match . length , 1 ) ;
157154 match = warnings2 . match ( / U s e ` n o d e - - t r a c e - w a r n i n g s / g) ;
158155 assert . strictEqual ( match . length , 1 ) ;
159- assert . doesNotMatch ( child . stderr . toString ( ) , / W a r n i n g : t e s t w a r n i n g / ) ;
160156}
0 commit comments