| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 20:51:52 +08:00
										 |  |  | require("./helpers/warmup-webpack"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const { Volume, createFsFromVolume } = require("memfs"); | 
					
						
							| 
									
										
										
										
											2018-12-09 21:26:35 +08:00
										 |  |  | const webpack = require(".."); | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const createMultiCompiler = (options) => { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 	const compiler = webpack( | 
					
						
							|  |  |  | 		Object.assign( | 
					
						
							|  |  |  | 			[ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: "a", | 
					
						
							|  |  |  | 					context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 					entry: "./a.js" | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: "b", | 
					
						
							|  |  |  | 					context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 					entry: "./b.js" | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			], | 
					
						
							|  |  |  | 			options | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2020-02-15 13:54:52 +08:00
										 |  |  | 	compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							| 
									
										
										
										
											2020-07-08 16:21:31 +08:00
										 |  |  | 	compiler.watchFileSystem = { | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		watch(_a, _b, _c, _d, _e, _f, _g) {} | 
					
						
							| 
									
										
										
										
											2020-07-08 16:21:31 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 	return compiler; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | describe("MultiCompiler", () => { | 
					
						
							| 
									
										
										
										
											2018-05-18 22:34:01 +08:00
										 |  |  | 	jest.setTimeout(20000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should trigger 'run' for each child compiler", (done) => { | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							|  |  |  | 		let called = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.hooks.run.tap("MultiCompiler test", () => called++); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		compiler.run((err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 				throw err; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-05-07 01:08:43 +08:00
										 |  |  | 			expect(called).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			compiler.close(done); | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should trigger 'watchRun' for each child compiler", (done) => { | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							|  |  |  | 		let called = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.hooks.watchRun.tap("MultiCompiler test", () => called++); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		compiler.watch(1000, (err) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 				throw err; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-05-07 01:08:43 +08:00
										 |  |  | 			expect(called).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 			compiler.close(done); | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should not be running twice at a time (run)", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				compiler.close(done); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should not be running twice at a time (watch)", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should not be running twice at a time (run - watch)", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				compiler.close(done); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should not be running twice at a time (watch - run)", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			if (err) { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should not be running twice at a time (instance cb)", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = webpack( | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				context: __dirname, | 
					
						
							|  |  |  | 				mode: "production", | 
					
						
							|  |  |  | 				entry: "./c", | 
					
						
							|  |  |  | 				output: { | 
					
						
							|  |  |  | 					path: "/", | 
					
						
							|  |  |  | 					filename: "bundle.js" | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			() => {} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-02-15 13:54:52 +08:00
										 |  |  | 		compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			if (err) { | 
					
						
							|  |  |  | 				compiler.close(done); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should run again correctly after first compilation", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 			compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 				if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should watch again correctly after first compilation", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 			compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 				if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should run again correctly after first closed watch", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		const watching = compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		watching.close(() => { | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 			compiler.run((err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 				if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should watch again correctly after first closed watch", (done) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		const watching = compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		watching.close(() => { | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 			compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 				if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2018-03-07 18:45:38 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should respect parallelism and dependencies for running", (done) => { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		const compiler = createMultiCompiler({ | 
					
						
							|  |  |  | 			parallelism: 1, | 
					
						
							|  |  |  | 			2: { | 
					
						
							|  |  |  | 				name: "c", | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 				entry: "./a.js", | 
					
						
							|  |  |  | 				dependencies: ["d", "e"] | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			3: { | 
					
						
							|  |  |  | 				name: "d", | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 				entry: "./a.js" | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			4: { | 
					
						
							|  |  |  | 				name: "e", | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 				entry: "./a.js" | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		const events = []; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		for (const c of compiler.compilers) { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			c.hooks.run.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} run`); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			c.hooks.done.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} done`); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.run((_err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			expect(events.join(" ")).toBe( | 
					
						
							|  |  |  | 				"a run a done b run b done d run d done e run e done c run c done" | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should respect parallelism and dependencies for watching", (done) => { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 		const compiler = webpack( | 
					
						
							|  |  |  | 			Object.assign( | 
					
						
							|  |  |  | 				[ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						name: "a", | 
					
						
							|  |  |  | 						mode: "development", | 
					
						
							|  |  |  | 						context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 						entry: "./a.js", | 
					
						
							|  |  |  | 						dependencies: ["b", "c"] | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						name: "b", | 
					
						
							|  |  |  | 						mode: "development", | 
					
						
							|  |  |  | 						context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 						entry: "./b.js" | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						name: "c", | 
					
						
							|  |  |  | 						mode: "development", | 
					
						
							|  |  |  | 						context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 						entry: "./a.js" | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 				{ parallelism: 1 } | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							|  |  |  | 		const watchCallbacks = []; | 
					
						
							|  |  |  | 		const watchCallbacksUndelayed = []; | 
					
						
							|  |  |  | 		compiler.watchFileSystem = { | 
					
						
							|  |  |  | 			watch( | 
					
						
							|  |  |  | 				files, | 
					
						
							|  |  |  | 				directories, | 
					
						
							|  |  |  | 				missing, | 
					
						
							|  |  |  | 				startTime, | 
					
						
							|  |  |  | 				options, | 
					
						
							|  |  |  | 				callback, | 
					
						
							|  |  |  | 				callbackUndelayed | 
					
						
							|  |  |  | 			) { | 
					
						
							|  |  |  | 				watchCallbacks.push(callback); | 
					
						
							|  |  |  | 				watchCallbacksUndelayed.push(callbackUndelayed); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		const events = []; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		for (const c of compiler.compilers) { | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 			c.hooks.invalid.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} invalid`); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			c.hooks.watchRun.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} run`); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			c.hooks.done.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} done`); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		let update = 0; | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 		compiler.watch({}, (err, stats) => { | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 			const info = () => stats.toString({ preset: "summary", version: false }); | 
					
						
							|  |  |  | 			switch (update++) { | 
					
						
							|  |  |  | 				case 0: | 
					
						
							|  |  |  | 					expect(info()).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 							"a: | 
					
						
							|  |  |  | 							  a compiled successfully | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							b: | 
					
						
							|  |  |  | 							  b compiled successfully | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							c: | 
					
						
							|  |  |  | 							  c compiled successfully" | 
					
						
							|  |  |  | 					`);
 | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 					expect(compiler.compilers[0].modifiedFiles).toBeUndefined(); | 
					
						
							|  |  |  | 					expect(compiler.compilers[0].removedFiles).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 					expect(events).toMatchInlineSnapshot(`
 | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				Array [ | 
					
						
							|  |  |  | 				  "b run", | 
					
						
							|  |  |  | 				  "b done", | 
					
						
							|  |  |  | 				  "c run", | 
					
						
							|  |  |  | 				  "c done", | 
					
						
							|  |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			`);
 | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 					events.length = 0; | 
					
						
							|  |  |  | 					// wait until watching begins
 | 
					
						
							|  |  |  | 					setTimeout(() => { | 
					
						
							|  |  |  | 						watchCallbacksUndelayed[0](); | 
					
						
							|  |  |  | 						watchCallbacks[0](null, new Map(), new Map(), new Set(), new Set()); | 
					
						
							|  |  |  | 					}, 100); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 1: | 
					
						
							|  |  |  | 					expect(info()).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				"a: | 
					
						
							|  |  |  | 				  a compiled successfully | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				b: | 
					
						
							|  |  |  | 				  b compiled successfully" | 
					
						
							|  |  |  | 			`);
 | 
					
						
							| 
									
										
										
										
											2021-02-25 03:12:32 +08:00
										 |  |  | 					expect(compiler.compilers[1].modifiedFiles).toEqual(new Set()); | 
					
						
							|  |  |  | 					expect(compiler.compilers[1].removedFiles).toEqual(new Set()); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 					expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				Array [ | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "b invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "b run", | 
					
						
							|  |  |  | 				  "b done", | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "a invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					watchCallbacksUndelayed[2](); | 
					
						
							|  |  |  | 					watchCallbacks[2](null, new Map(), new Map(), new Set(), new Set()); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 2: | 
					
						
							|  |  |  | 					expect(info()).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				"a: | 
					
						
							|  |  |  | 				  a compiled successfully" | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				Array [ | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "b invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "b run", | 
					
						
							|  |  |  | 				  "b done", | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "a invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "a invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					events.length = 0; | 
					
						
							|  |  |  | 					watchCallbacksUndelayed[0](); | 
					
						
							|  |  |  | 					watchCallbacksUndelayed[1](); | 
					
						
							|  |  |  | 					watchCallbacks[0](null, new Map(), new Map(), new Set(), new Set()); | 
					
						
							|  |  |  | 					watchCallbacks[1](null, new Map(), new Map(), new Set(), new Set()); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 3: | 
					
						
							|  |  |  | 					expect(info()).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				"a: | 
					
						
							|  |  |  | 				  a compiled successfully | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				b: | 
					
						
							|  |  |  | 				  b compiled successfully | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				c: | 
					
						
							|  |  |  | 				  c compiled successfully" | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				Array [ | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "b invalid", | 
					
						
							|  |  |  | 				  "c invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "b run", | 
					
						
							|  |  |  | 				  "b done", | 
					
						
							|  |  |  | 				  "c run", | 
					
						
							|  |  |  | 				  "c done", | 
					
						
							| 
									
										
										
										
											2021-04-09 23:51:58 +08:00
										 |  |  | 				  "a invalid", | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					events.length = 0; | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 					compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-02-14 02:53:50 +08:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					done(new Error("unexpected")); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2021-03-20 03:31:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should respect parallelism when using invalidate", (done) => { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 		const configs = [ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "a", | 
					
						
							|  |  |  | 				mode: "development", | 
					
						
							|  |  |  | 				entry: { a: "./a.js" }, | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures") | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "b", | 
					
						
							|  |  |  | 				mode: "development", | 
					
						
							|  |  |  | 				entry: { b: "./b.js" }, | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures") | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		]; | 
					
						
							|  |  |  | 		configs.parallelism = 1; | 
					
						
							|  |  |  | 		const compiler = webpack(configs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const events = []; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		for (const c of compiler.compilers) { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 			c.hooks.invalid.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} invalid`); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			c.hooks.watchRun.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} run`); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			c.hooks.done.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} done`); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		compiler.watchFileSystem = { watch() {} }; | 
					
						
							|  |  |  | 		compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		let state = 0; | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const watching = compiler.watch({}, (error) => { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 			if (error) { | 
					
						
							|  |  |  | 				done(error); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (state !== 0) return; | 
					
						
							|  |  |  | 			state++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 			Array [ | 
					
						
							|  |  |  | 			  "a run", | 
					
						
							|  |  |  | 			  "a done", | 
					
						
							|  |  |  | 			  "b run", | 
					
						
							|  |  |  | 			  "b done", | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 		`);
 | 
					
						
							|  |  |  | 			events.length = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			watching.invalidate((err) => { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 				try { | 
					
						
							|  |  |  | 					if (err) return done(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				Array [ | 
					
						
							|  |  |  | 				  "a invalid", | 
					
						
							|  |  |  | 				  "b invalid", | 
					
						
							|  |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							|  |  |  | 				  "b run", | 
					
						
							|  |  |  | 				  "b done", | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					events.length = 0; | 
					
						
							|  |  |  | 					expect(state).toBe(1); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 					setTimeout(() => { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 						compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 					}, 1000); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 				} catch (err) { | 
					
						
							|  |  |  | 					console.error(err); | 
					
						
							|  |  |  | 					done(err); | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}, 2000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("should respect dependencies when using invalidate", (done) => { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 		const compiler = webpack([ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "a", | 
					
						
							|  |  |  | 				mode: "development", | 
					
						
							|  |  |  | 				entry: { a: "./a.js" }, | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 				dependencies: ["b"] | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "b", | 
					
						
							|  |  |  | 				mode: "development", | 
					
						
							|  |  |  | 				entry: { b: "./b.js" }, | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures") | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const events = []; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		for (const c of compiler.compilers) { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 			c.hooks.invalid.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} invalid`); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			c.hooks.watchRun.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} run`); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			c.hooks.done.tap("test", () => { | 
					
						
							|  |  |  | 				events.push(`${c.name} done`); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		compiler.watchFileSystem = { watch() {} }; | 
					
						
							|  |  |  | 		compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		let state = 0; | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const watching = compiler.watch({}, (error) => { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 			if (error) { | 
					
						
							|  |  |  | 				done(error); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (state !== 0) return; | 
					
						
							|  |  |  | 			state++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 			Array [ | 
					
						
							|  |  |  | 			  "b run", | 
					
						
							|  |  |  | 			  "b done", | 
					
						
							|  |  |  | 			  "a run", | 
					
						
							|  |  |  | 			  "a done", | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 		`);
 | 
					
						
							|  |  |  | 			events.length = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			watching.invalidate((err) => { | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 				try { | 
					
						
							|  |  |  | 					if (err) return done(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					expect(events).toMatchInlineSnapshot(`
 | 
					
						
							|  |  |  | 				Array [ | 
					
						
							|  |  |  | 				  "a invalid", | 
					
						
							|  |  |  | 				  "b invalid", | 
					
						
							|  |  |  | 				  "b run", | 
					
						
							|  |  |  | 				  "b done", | 
					
						
							|  |  |  | 				  "a run", | 
					
						
							|  |  |  | 				  "a done", | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			`);
 | 
					
						
							|  |  |  | 					events.length = 0; | 
					
						
							|  |  |  | 					expect(state).toBe(1); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 					setTimeout(() => { | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 						compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 					}, 1000); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 				} catch (err) { | 
					
						
							|  |  |  | 					console.error(err); | 
					
						
							|  |  |  | 					done(err); | 
					
						
							| 
									
										
										
										
											2021-05-17 19:49:43 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}, 2000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("shouldn't hang when invalidating watchers", (done) => { | 
					
						
							| 
									
										
										
										
											2021-03-20 03:31:40 +08:00
										 |  |  | 		const entriesA = { a: "./a.js" }; | 
					
						
							|  |  |  | 		const entriesB = { b: "./b.js" }; | 
					
						
							|  |  |  | 		const compiler = webpack([ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "a", | 
					
						
							|  |  |  | 				mode: "development", | 
					
						
							|  |  |  | 				entry: () => entriesA, | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures") | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "b", | 
					
						
							|  |  |  | 				mode: "development", | 
					
						
							|  |  |  | 				entry: () => entriesB, | 
					
						
							|  |  |  | 				context: path.join(__dirname, "fixtures") | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.watchFileSystem = { watch() {} }; | 
					
						
							|  |  |  | 		compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const watching = compiler.watch({}, (error) => { | 
					
						
							| 
									
										
										
										
											2021-03-20 03:31:40 +08:00
										 |  |  | 			if (error) { | 
					
						
							|  |  |  | 				done(error); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			entriesA.b = "./b.js"; | 
					
						
							|  |  |  | 			entriesB.a = "./a.js"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 			watching.invalidate((err) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 				if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 				compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2021-03-20 03:31:40 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}, 2000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 	it("shouldn't hang when invalidating during build", (done) => { | 
					
						
							| 
									
										
										
										
											2021-03-17 18:04:41 +08:00
										 |  |  | 		const compiler = webpack( | 
					
						
							|  |  |  | 			Object.assign([ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: "a", | 
					
						
							|  |  |  | 					mode: "development", | 
					
						
							|  |  |  | 					context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 					entry: "./a.js" | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					name: "b", | 
					
						
							|  |  |  | 					mode: "development", | 
					
						
							|  |  |  | 					context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 					entry: "./b.js", | 
					
						
							|  |  |  | 					dependencies: ["a"] | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			]) | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		compiler.outputFileSystem = createFsFromVolume(new Volume()); | 
					
						
							|  |  |  | 		const watchCallbacks = []; | 
					
						
							|  |  |  | 		const watchCallbacksUndelayed = []; | 
					
						
							|  |  |  | 		let firstRun = true; | 
					
						
							|  |  |  | 		compiler.watchFileSystem = { | 
					
						
							|  |  |  | 			watch( | 
					
						
							|  |  |  | 				files, | 
					
						
							|  |  |  | 				directories, | 
					
						
							|  |  |  | 				missing, | 
					
						
							|  |  |  | 				startTime, | 
					
						
							|  |  |  | 				options, | 
					
						
							|  |  |  | 				callback, | 
					
						
							|  |  |  | 				callbackUndelayed | 
					
						
							|  |  |  | 			) { | 
					
						
							|  |  |  | 				watchCallbacks.push(callback); | 
					
						
							|  |  |  | 				watchCallbacksUndelayed.push(callbackUndelayed); | 
					
						
							|  |  |  | 				if (firstRun && files.has(path.join(__dirname, "fixtures", "a.js"))) { | 
					
						
							|  |  |  | 					process.nextTick(() => { | 
					
						
							|  |  |  | 						callback(null, new Map(), new Map(), new Set(), new Set()); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					firstRun = false; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2025-07-08 22:46:17 +08:00
										 |  |  | 		compiler.watch({}, (err, _stats) => { | 
					
						
							| 
									
										
										
										
											2021-07-13 16:50:29 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2021-08-30 21:01:24 +08:00
										 |  |  | 			compiler.close(done); | 
					
						
							| 
									
										
										
										
											2021-03-17 18:04:41 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | }); |