@@ -9,14 +9,15 @@ const cacheDirectory = path.resolve(__dirname, "js/buildDepsCache");
99const outputDirectory = path . resolve ( __dirname , "js/buildDeps" ) ;
1010const inputDirectory = path . resolve ( __dirname , "js/buildDepsInput" ) ;
1111
12- const exec = n => {
12+ const exec = ( n , options = { } ) => {
1313 return new Promise ( ( resolve , reject ) => {
1414 const p = child_process . fork (
1515 path . resolve ( __dirname , "fixtures/buildDependencies/run.js" ) ,
16- [ n ] ,
17- { stdio : [ "ignore" , "pipe" , "inherit " , "ipc" ] }
16+ [ n , JSON . stringify ( options ) ] ,
17+ { stdio : [ "ignore" , "pipe" , "pipe " , "ipc" ] }
1818 ) ;
1919 const chunks = [ ] ;
20+ p . stderr . on ( "data" , chunk => chunks . push ( chunk ) ) ;
2021 p . stdout . on ( "data" , chunk => chunks . push ( chunk ) ) ;
2122 p . once ( "exit" , code => {
2223 const stdout = Buffer . concat ( chunks ) . toString ( "utf-8" ) ;
@@ -45,6 +46,15 @@ describe("BuildDependencies", () => {
4546 fs . mkdir ( inputDirectory , { recursive : true } , done ) ;
4647 } ) ;
4748 it ( "should capture loader and config dependencies" , async ( ) => {
49+ fs . writeFileSync (
50+ path . resolve ( inputDirectory , "loader-dependency.js" ) ,
51+ "module.exports = 0;"
52+ ) ;
53+ fs . writeFileSync (
54+ path . resolve ( inputDirectory , "config-dependency.js" ) ,
55+ "module.exports = 0;"
56+ ) ;
57+ await exec ( "0" , { invalidBuildDepdencies : true , buildTwice : true } ) ;
4858 fs . writeFileSync (
4959 path . resolve ( inputDirectory , "loader-dependency.js" ) ,
5060 "module.exports = 1;"
@@ -53,48 +63,52 @@ describe("BuildDependencies", () => {
5363 path . resolve ( inputDirectory , "config-dependency.js" ) ,
5464 "module.exports = 1;"
5565 ) ;
56- await exec ( "0 " ) ;
66+ await exec ( "1 " ) ;
5767 fs . writeFileSync (
5868 path . resolve ( inputDirectory , "loader-dependency.js" ) ,
5969 "module.exports = Date.now();"
6070 ) ;
6171 const now1 = Date . now ( ) ;
62- await exec ( "1" ) ;
6372 await exec ( "2" ) ;
73+ await exec ( "3" ) ;
6474 fs . writeFileSync (
6575 path . resolve ( inputDirectory , "config-dependency" ) ,
6676 "module.exports = Date.now();"
6777 ) ;
6878 const now2 = Date . now ( ) ;
69- await exec ( "3" ) ;
70- const now3 = Date . now ( ) ;
7179 await exec ( "4" ) ;
72- const results = Array . from ( { length : 5 } ) . map ( ( _ , i ) =>
80+ const now3 = Date . now ( ) ;
81+ await exec ( "5" ) ;
82+ const results = Array . from ( { length : 6 } ) . map ( ( _ , i ) =>
7383 require ( `./js/buildDeps/${ i } /main.js` )
7484 ) ;
7585 for ( const r of results ) {
7686 expect ( typeof r . loader ) . toBe ( "number" ) ;
7787 expect ( typeof r . config ) . toBe ( "number" ) ;
7888 expect ( typeof r . uncached ) . toBe ( "number" ) ;
7989 }
80- expect ( results [ 0 ] . loader ) . toBe ( 1 ) ;
81- expect ( results [ 0 ] . config ) . toBe ( 1 ) ;
82- expect ( results [ 0 ] . uncached ) . toBe ( 1 ) ;
83- // 0 -> 1 should be invalidated
84- expect ( results [ 1 ] . loader ) . toBeGreaterThan ( now1 ) ;
90+ expect ( results [ 0 ] . loader ) . toBe ( 0 ) ;
91+ expect ( results [ 0 ] . config ) . toBe ( 0 ) ;
92+ expect ( results [ 0 ] . uncached ) . toBe ( 0 ) ;
93+ // 0 -> 1 should not cache at all because of invalid buildDeps
94+ expect ( results [ 1 ] . loader ) . toBe ( 1 ) ;
8595 expect ( results [ 1 ] . config ) . toBe ( 1 ) ;
8696 expect ( results [ 1 ] . uncached ) . toBe ( 1 ) ;
87- // 1 -> 2 should stay cached
88- expect ( results [ 2 ] . loader ) . toBe ( results [ 1 ] . loader ) ;
97+ // 1 -> 2 should be invalidated
98+ expect ( results [ 2 ] . loader ) . toBeGreaterThan ( now1 ) ;
8999 expect ( results [ 2 ] . config ) . toBe ( 1 ) ;
90100 expect ( results [ 2 ] . uncached ) . toBe ( 1 ) ;
91- // 2 -> 3 should be invalidated
92- expect ( results [ 3 ] . loader ) . toBeGreaterThan ( now2 ) ;
93- expect ( results [ 3 ] . config ) . toBeGreaterThan ( now2 ) ;
94- expect ( results [ 3 ] . uncached ) . toBe ( results [ 3 ] . config ) ;
95- // 3 -> 4 should stay cached, but uncacheable module still rebuilds
96- expect ( results [ 4 ] . loader ) . toBe ( results [ 3 ] . loader ) ;
97- expect ( results [ 4 ] . config ) . toBe ( results [ 3 ] . config ) ;
98- expect ( results [ 4 ] . uncached ) . toBeGreaterThan ( now3 ) ;
101+ // 2 -> 3 should stay cached
102+ expect ( results [ 3 ] . loader ) . toBe ( results [ 2 ] . loader ) ;
103+ expect ( results [ 3 ] . config ) . toBe ( 1 ) ;
104+ expect ( results [ 3 ] . uncached ) . toBe ( 1 ) ;
105+ // 3 -> 4 should be invalidated
106+ expect ( results [ 4 ] . loader ) . toBeGreaterThan ( now2 ) ;
107+ expect ( results [ 4 ] . config ) . toBeGreaterThan ( now2 ) ;
108+ expect ( results [ 4 ] . uncached ) . toBe ( results [ 4 ] . config ) ;
109+ // 4 -> 5 should stay cached, but uncacheable module still rebuilds
110+ expect ( results [ 5 ] . loader ) . toBe ( results [ 4 ] . loader ) ;
111+ expect ( results [ 5 ] . config ) . toBe ( results [ 4 ] . config ) ;
112+ expect ( results [ 5 ] . uncached ) . toBeGreaterThan ( now3 ) ;
99113 } , 100000 ) ;
100114} ) ;
0 commit comments