@@ -18,6 +18,17 @@ const { parseResource } = require("../lib/util/identifier");
18
18
const captureStdio = require ( "./helpers/captureStdio" ) ;
19
19
const asModule = require ( "./helpers/asModule" ) ;
20
20
21
+ const PERSISTENCE_CACHE_INVALIDATE_ERROR = ( log , config ) => {
22
+ if ( config . run < 2 ) return ;
23
+ const match =
24
+ / ^ \[ w e b p a c k \. c a c h e \. P a c k F i l e C a c h e S t r a t e g y \] P a c k g o t i n v a l i d b e c a u s e o f w r i t e t o : ( .+ ) $ / . exec (
25
+ log
26
+ ) ;
27
+ if ( match ) {
28
+ return `Pack got invalid because of write to: ${ match [ 1 ] . trim ( ) } ` ;
29
+ }
30
+ } ;
31
+
21
32
const casesPath = path . join ( __dirname , "configCases" ) ;
22
33
const categories = fs . readdirSync ( casesPath ) . map ( cat => {
23
34
return {
@@ -29,7 +40,53 @@ const categories = fs.readdirSync(casesPath).map(cat => {
29
40
} ;
30
41
} ) ;
31
42
43
+ const createLogger = appendTarget => {
44
+ return {
45
+ log : l => appendTarget . push ( l ) ,
46
+ debug : l => appendTarget . push ( l ) ,
47
+ trace : l => appendTarget . push ( l ) ,
48
+ info : l => appendTarget . push ( l ) ,
49
+ warn : console . warn . bind ( console ) ,
50
+ error : console . error . bind ( console ) ,
51
+ logTime : ( ) => { } ,
52
+ group : ( ) => { } ,
53
+ groupCollapsed : ( ) => { } ,
54
+ groupEnd : ( ) => { } ,
55
+ profile : ( ) => { } ,
56
+ profileEnd : ( ) => { } ,
57
+ clear : ( ) => { } ,
58
+ status : ( ) => { }
59
+ } ;
60
+ } ;
61
+
62
+ const returnLogError = ( logs , errorsFilter , config ) => {
63
+ for ( const log of logs ) {
64
+ for ( const filter of errorsFilter ) {
65
+ const result = filter ( log , config ) ;
66
+ if ( result ) {
67
+ return new Error ( result ) ;
68
+ }
69
+ }
70
+ }
71
+ } ;
72
+
32
73
const describeCases = config => {
74
+ let allowErrorsMap ;
75
+ if ( config . infrastructureLogErrors ) {
76
+ allowErrorsMap = new Map ( ) ;
77
+ if ( config . infrastructureLogErrors . allowList ) {
78
+ for ( const { category, test } of config . infrastructureLogErrors
79
+ . allowList ) {
80
+ let byCategory = allowErrorsMap . get ( category ) ;
81
+ if ( ! byCategory ) {
82
+ byCategory = new Set ( ) ;
83
+ allowErrorsMap . set ( category , byCategory ) ;
84
+ }
85
+ byCategory . add ( test ) ;
86
+ }
87
+ }
88
+ }
89
+
33
90
describe ( config . name , ( ) => {
34
91
let stderr ;
35
92
beforeEach ( ( ) => {
@@ -44,6 +101,11 @@ const describeCases = config => {
44
101
// eslint-disable-next-line no-loop-func
45
102
describe ( category . name , ( ) => {
46
103
for ( const testName of category . tests ) {
104
+ const inAllowErrorsList = ( ) => {
105
+ const byCategory = allowErrorsMap . get ( category . name ) ;
106
+ if ( ! byCategory ) return false ;
107
+ return byCategory . has ( testName ) ;
108
+ } ;
47
109
// eslint-disable-next-line no-loop-func
48
110
describe ( testName , function ( ) {
49
111
const testDirectory = path . join ( casesPath , category . name , testName ) ;
@@ -54,6 +116,7 @@ const describeCases = config => {
54
116
} ) ;
55
117
return ;
56
118
}
119
+ const infraStructureLog = [ ] ;
57
120
const outBaseDir = path . join ( __dirname , "js" ) ;
58
121
const testSubPath = path . join ( config . name , category . name , testName ) ;
59
122
const outputDirectory = path . join ( outBaseDir , testSubPath ) ;
@@ -97,6 +160,10 @@ const describeCases = config => {
97
160
name : `config-${ idx } ` ,
98
161
...config . cache
99
162
} ;
163
+ options . infrastructureLogging = {
164
+ debug : true ,
165
+ console : createLogger ( infraStructureLog )
166
+ } ;
100
167
}
101
168
if ( ! options . snapshot ) options . snapshot = { } ;
102
169
if ( ! options . snapshot . managedPaths ) {
@@ -168,6 +235,7 @@ const describeCases = config => {
168
235
it ( `${ testName } should pre-compile to fill disk cache (1st)` , done => {
169
236
rimraf . sync ( outputDirectory ) ;
170
237
fs . mkdirSync ( outputDirectory , { recursive : true } ) ;
238
+ infraStructureLog . length = 0 ;
171
239
const deprecationTracker = deprecationTracking . start ( ) ;
172
240
require ( ".." ) ( options , err => {
173
241
deprecationTracker ( ) ;
@@ -180,13 +248,29 @@ const describeCases = config => {
180
248
)
181
249
) ;
182
250
}
251
+ if ( config . infrastructureLogErrors ) {
252
+ if ( ! inAllowErrorsList ( ) ) {
253
+ const error = returnLogError (
254
+ infraStructureLog ,
255
+ Array . isArray ( config . infrastructureLogErrors . filter )
256
+ ? config . infrastructureLogErrors . filter
257
+ : [ config . infrastructureLogErrors . filter ] ,
258
+ {
259
+ run : 1 ,
260
+ options
261
+ }
262
+ ) ;
263
+ if ( error ) return done ( error ) ;
264
+ }
265
+ }
183
266
if ( err ) return handleFatalError ( err , done ) ;
184
267
done ( ) ;
185
268
} ) ;
186
269
} , 60000 ) ;
187
270
it ( `${ testName } should pre-compile to fill disk cache (2nd)` , done => {
188
271
rimraf . sync ( outputDirectory ) ;
189
272
fs . mkdirSync ( outputDirectory , { recursive : true } ) ;
273
+ infraStructureLog . length = 0 ;
190
274
const deprecationTracker = deprecationTracking . start ( ) ;
191
275
require ( ".." ) ( options , ( err , stats ) => {
192
276
deprecationTracker ( ) ;
@@ -228,13 +312,29 @@ const describeCases = config => {
228
312
) ;
229
313
}
230
314
}
315
+ if ( config . infrastructureLogErrors ) {
316
+ if ( ! inAllowErrorsList ( ) ) {
317
+ const error = returnLogError (
318
+ infraStructureLog ,
319
+ Array . isArray ( config . infrastructureLogErrors . filter )
320
+ ? config . infrastructureLogErrors . filter
321
+ : [ config . infrastructureLogErrors . filter ] ,
322
+ {
323
+ run : 2 ,
324
+ options
325
+ }
326
+ ) ;
327
+ if ( error ) return done ( error ) ;
328
+ }
329
+ }
231
330
done ( ) ;
232
331
} ) ;
233
332
} , 40000 ) ;
234
333
}
235
334
it ( `${ testName } should compile` , done => {
236
335
rimraf . sync ( outputDirectory ) ;
237
336
fs . mkdirSync ( outputDirectory , { recursive : true } ) ;
337
+ infraStructureLog . length = 0 ;
238
338
const deprecationTracker = deprecationTracking . start ( ) ;
239
339
const onCompiled = ( err , stats ) => {
240
340
const deprecations = deprecationTracker ( ) ;
@@ -298,6 +398,21 @@ const describeCases = config => {
298
398
) {
299
399
return ;
300
400
}
401
+ if ( config . infrastructureLogErrors ) {
402
+ if ( ! inAllowErrorsList ( ) ) {
403
+ const error = returnLogError (
404
+ infraStructureLog ,
405
+ Array . isArray ( config . infrastructureLogErrors . filter )
406
+ ? config . infrastructureLogErrors . filter
407
+ : [ config . infrastructureLogErrors . filter ] ,
408
+ {
409
+ run : 3 ,
410
+ options
411
+ }
412
+ ) ;
413
+ if ( error ) return done ( error ) ;
414
+ }
415
+ }
301
416
302
417
let filesCount = 0 ;
303
418
@@ -623,3 +738,6 @@ const describeCases = config => {
623
738
} ;
624
739
625
740
exports . describeCases = describeCases ;
741
+ exports . logErrors = {
742
+ PERSISTENCE_CACHE_INVALIDATE_ERROR
743
+ } ;
0 commit comments