@@ -39,10 +39,49 @@ const exec = (n, options = {}) => {
3939 p . stderr . on ( "data" , chunk => chunks . push ( chunk ) ) ;
4040 p . stdout . on ( "data" , chunk => chunks . push ( chunk ) ) ;
4141 p . once ( "exit" , code => {
42- const stdout = chunks . join ( "" ) ;
42+ const errors = [ ] ;
43+ const warnings = [ ] ;
44+ const rawStdout = chunks . join ( "" ) ;
45+ const stdout = rawStdout . replace (
46+ // This warning is expected
47+ / < ( [ e w ] ) > \[ .+ \n (?: < ( [ e w ] ) > [ ^ [ ] .+ \n ) * / g,
48+ ( message , type ) => {
49+ ( type === "e" ? errors : warnings ) . push ( message ) ;
50+ return "" ;
51+ }
52+ ) ;
53+ if ( errors . length > 0 ) {
54+ return reject (
55+ new Error (
56+ `Unexpected errors in ${ n } output:\n${ errors . join (
57+ "\n"
58+ ) } \n\n${ rawStdout } `
59+ )
60+ ) ;
61+ }
62+ for ( const regexp of options . warnings || [ ] ) {
63+ const idx = warnings . findIndex ( w => regexp . test ( w ) ) ;
64+ if ( idx < 0 ) {
65+ return reject (
66+ new Error (
67+ `Warning ${ regexp } was not found in ${ n } output:\n${ rawStdout } `
68+ )
69+ ) ;
70+ }
71+ warnings . splice ( idx , 1 ) ;
72+ }
73+ if ( warnings . length > 0 ) {
74+ return reject (
75+ new Error (
76+ `Unexpected warnings in ${ n } output:\n${ warnings . join (
77+ "\n"
78+ ) } \n\n${ rawStdout } `
79+ )
80+ ) ;
81+ }
4382 if ( code === 0 ) {
4483 if ( ! options . ignoreErrors && / < [ e w ] > / . test ( stdout ) )
45- return reject ( stdout ) ;
84+ return reject ( new Error ( stdout ) ) ;
4685 resolve ( stdout ) ;
4786 } else {
4887 reject ( new Error ( `Code ${ code } : ${ stdout } ` ) ) ;
@@ -99,7 +138,7 @@ describe("BuildDependencies", () => {
99138 await exec ( "0" , {
100139 invalidBuildDepdencies : true ,
101140 buildTwice : true ,
102- ignoreErrors : true
141+ warnings : [ / C a n ' t r e s o l v e ' s h o u l d - f a i l - r e s o l v i n g ' / ]
103142 } ) ;
104143 fs . writeFileSync (
105144 path . resolve ( inputDirectory , "loader-dependency.js" ) ,
@@ -113,13 +152,21 @@ describe("BuildDependencies", () => {
113152 path . resolve ( inputDirectory , "esm-dependency.js" ) ,
114153 "module.exports = 1;"
115154 ) ;
116- await exec ( "1" ) ;
155+ await exec ( "1" , {
156+ warnings : supportsEsm && [
157+ / M a n a g e d i t e m .+ d e p - w i t h o u t - p a c k a g e \. j s o n i s n ' t a d i r e c t o r y o r d o e s n ' t c o n t a i n a p a c k a g e \. j s o n /
158+ ]
159+ } ) ;
117160 fs . writeFileSync (
118161 path . resolve ( inputDirectory , "loader-dependency.js" ) ,
119162 "module.exports = Date.now();"
120163 ) ;
121164 const now1 = Date . now ( ) ;
122- const output2 = await exec ( "2" ) ;
165+ const output2 = await exec ( "2" , {
166+ warnings : supportsEsm && [
167+ / M a n a g e d i t e m .+ d e p - w i t h o u t - p a c k a g e \. j s o n i s n ' t a d i r e c t o r y o r d o e s n ' t c o n t a i n a p a c k a g e \. j s o n /
168+ ]
169+ } ) ;
123170 expect ( output2 ) . toMatch ( / b u t b u i l d d e p e n d e n c i e s h a v e c h a n g e d / ) ;
124171 expect ( output2 ) . toMatch ( / C a p t u r e d b u i l d d e p e n d e n c i e s / ) ;
125172 expect ( output2 ) . not . toMatch ( / A s s u m i n g / ) ;
@@ -137,7 +184,11 @@ describe("BuildDependencies", () => {
137184 version : "2.0.0"
138185 } )
139186 ) ;
140- const output4 = await exec ( "4" ) ;
187+ const output4 = await exec ( "4" , {
188+ warnings : supportsEsm && [
189+ / M a n a g e d i t e m .+ d e p - w i t h o u t - p a c k a g e \. j s o n i s n ' t a d i r e c t o r y o r d o e s n ' t c o n t a i n a p a c k a g e \. j s o n /
190+ ]
191+ } ) ;
141192 expect ( output4 ) . toMatch ( / r e s o l v i n g o f b u i l d d e p e n d e n c i e s i s i n v a l i d / ) ;
142193 expect ( output4 ) . not . toMatch ( / b u t b u i l d d e p e n d e n c i e s h a v e c h a n g e d / ) ;
143194 expect ( output4 ) . toMatch ( / C a p t u r e d b u i l d d e p e n d e n c i e s / ) ;
@@ -146,7 +197,11 @@ describe("BuildDependencies", () => {
146197 "module.exports = Date.now();"
147198 ) ;
148199 const now2 = Date . now ( ) ;
149- await exec ( "5" ) ;
200+ await exec ( "5" , {
201+ warnings : supportsEsm && [
202+ / M a n a g e d i t e m .+ d e p - w i t h o u t - p a c k a g e \. j s o n i s n ' t a d i r e c t o r y o r d o e s n ' t c o n t a i n a p a c k a g e \. j s o n /
203+ ]
204+ } ) ;
150205 const now3 = Date . now ( ) ;
151206 await exec ( "6" ) ;
152207 await exec ( "7" , {
@@ -160,7 +215,10 @@ describe("BuildDependencies", () => {
160215 ) ;
161216 now4 = Date . now ( ) ;
162217 await exec ( "8" , {
163- definedValue : "other"
218+ definedValue : "other" ,
219+ warnings : [
220+ / M a n a g e d i t e m .+ d e p - w i t h o u t - p a c k a g e \. j s o n i s n ' t a d i r e c t o r y o r d o e s n ' t c o n t a i n a p a c k a g e \. j s o n /
221+ ]
164222 } ) ;
165223 fs . writeFileSync (
166224 path . resolve ( inputDirectory , "esm-async-dependency.mjs" ) ,
@@ -169,7 +227,10 @@ describe("BuildDependencies", () => {
169227 now5 = Date . now ( ) ;
170228
171229 await exec ( "9" , {
172- definedValue : "other"
230+ definedValue : "other" ,
231+ warnings : [
232+ / M a n a g e d i t e m .+ d e p - w i t h o u t - p a c k a g e \. j s o n i s n ' t a d i r e c t o r y o r d o e s n ' t c o n t a i n a p a c k a g e \. j s o n /
233+ ]
173234 } ) ;
174235 }
175236 const results = Array . from ( { length : supportsEsm ? 10 : 8 } ) . map ( ( _ , i ) =>
0 commit comments