| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const fs = require("graceful-fs"); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 21:26:35 +08:00
										 |  |  | const webpack = require(".."); | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | describe("HotModuleReplacementPlugin", () => { | 
					
						
							| 
									
										
										
										
											2018-04-12 05:54:22 +08:00
										 |  |  | 	jest.setTimeout(20000); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 	it("should not have circular hashes but equal if unmodified", done => { | 
					
						
							|  |  |  | 		const entryFile = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"entry.js" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const statsFile1 = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin.test.stats1.txt" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const statsFile2 = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin.test.stats2.txt" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const recordsFile = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"records.json" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2015-08-09 18:42:43 +08:00
										 |  |  | 		try { | 
					
						
							| 
									
										
										
										
											2020-01-13 23:29:12 +08:00
										 |  |  | 			fs.mkdirSync(path.join(__dirname, "js", "HotModuleReplacementPlugin"), { | 
					
						
							|  |  |  | 				recursive: true | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2018-04-12 02:31:28 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-08-09 18:42:43 +08:00
										 |  |  | 		try { | 
					
						
							|  |  |  | 			fs.unlinkSync(recordsFile); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2018-04-12 02:31:28 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 		const compiler = webpack({ | 
					
						
							| 
									
										
										
										
											2014-03-21 23:21:59 +08:00
										 |  |  | 			cache: false, | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 			entry: entryFile, | 
					
						
							|  |  |  | 			recordsPath: recordsFile, | 
					
						
							|  |  |  | 			output: { | 
					
						
							| 
									
										
										
										
											2018-02-25 08:20:45 +08:00
										 |  |  | 				path: path.join(__dirname, "js", "HotModuleReplacementPlugin") | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-07-13 21:37:06 +08:00
										 |  |  | 			plugins: [new webpack.HotModuleReplacementPlugin()], | 
					
						
							|  |  |  | 			optimization: { | 
					
						
							|  |  |  | 				moduleIds: "size", | 
					
						
							|  |  |  | 				chunkIds: "size" | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		fs.writeFileSync(entryFile, "1", "utf-8"); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 		compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			if (err) throw err; | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 			const oldHash1 = stats.toJson().hash; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 			fs.writeFileSync(statsFile1, stats.toString()); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 			compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				if (err) throw err; | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 				const lastHash1 = stats.toJson().hash; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 				fs.writeFileSync(statsFile2, stats.toString()); | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | 				expect(lastHash1).toBe(oldHash1); // hash shouldn't change when bundle stay equal
 | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 				fs.writeFileSync(entryFile, "2", "utf-8"); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 				compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 					if (err) throw err; | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 					const lastHash2 = stats.toJson().hash; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 					fs.writeFileSync(statsFile1, stats.toString()); | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | 					expect(lastHash2).not.toBe(lastHash1); // hash should change when bundle changes
 | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 					fs.writeFileSync(entryFile, "1", "utf-8"); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 					compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 						if (err) throw err; | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 						const currentHash1 = stats.toJson().hash; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 						fs.writeFileSync(statsFile2, stats.toString()); | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | 						expect(currentHash1).not.toBe(lastHash1); // hash shouldn't change to the first hash if bundle changed back to first bundle
 | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 						fs.writeFileSync(entryFile, "2", "utf-8"); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 						compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 							if (err) throw err; | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 							const currentHash2 = stats.toJson().hash; | 
					
						
							| 
									
										
										
										
											2015-06-13 17:45:28 +08:00
										 |  |  | 							fs.writeFileSync(statsFile1, stats.toString()); | 
					
						
							| 
									
										
										
										
											2017-01-18 18:38:06 +08:00
										 |  |  | 							compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 								if (err) throw err; | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | 								expect(stats.toJson().hash).toBe(currentHash2); | 
					
						
							|  |  |  | 								expect(currentHash2).not.toBe(lastHash2); | 
					
						
							|  |  |  | 								expect(currentHash1).not.toBe(currentHash2); | 
					
						
							|  |  |  | 								expect(lastHash1).not.toBe(lastHash2); | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 								done(); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-11-30 21:24:16 +08:00
										 |  |  | 	}, 120000); | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 23:12:59 +08:00
										 |  |  | 	it("output.clean=true should keep 1 last update", done => { | 
					
						
							|  |  |  | 		const outputPath = path.join(__dirname, "js", "HotModuleReplacementPlugin"); | 
					
						
							|  |  |  | 		const entryFile = path.join(outputPath, "entry.js"); | 
					
						
							|  |  |  | 		const recordsFile = path.join(outputPath, "records.json"); | 
					
						
							|  |  |  | 		let step = 0; | 
					
						
							|  |  |  | 		let firstUpdate; | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			fs.mkdirSync(outputPath, { recursive: true }); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2022-02-16 23:12:59 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		fs.writeFileSync(entryFile, `${++step}`, "utf-8"); | 
					
						
							|  |  |  | 		const updates = new Set(); | 
					
						
							|  |  |  | 		const hasFile = file => { | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				fs.statSync(path.join(outputPath, file)); | 
					
						
							|  |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 			} catch (_err) { | 
					
						
							| 
									
										
										
										
											2022-02-16 23:12:59 +08:00
										 |  |  | 				return false; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		const compiler = webpack({ | 
					
						
							|  |  |  | 			mode: "development", | 
					
						
							|  |  |  | 			cache: false, | 
					
						
							|  |  |  | 			entry: { | 
					
						
							|  |  |  | 				0: entryFile | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			recordsPath: recordsFile, | 
					
						
							|  |  |  | 			output: { | 
					
						
							|  |  |  | 				path: outputPath, | 
					
						
							|  |  |  | 				clean: true | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			plugins: [new webpack.HotModuleReplacementPlugin()] | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		const callback = (err, stats) => { | 
					
						
							|  |  |  | 			if (err) return done(err); | 
					
						
							|  |  |  | 			const jsonStats = stats.toJson(); | 
					
						
							|  |  |  | 			const hash = jsonStats.hash; | 
					
						
							|  |  |  | 			const hmrUpdateMainFileName = `0.${hash}.hot-update.json`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			switch (step) { | 
					
						
							|  |  |  | 				case 1: | 
					
						
							|  |  |  | 					expect(updates.size).toBe(0); | 
					
						
							|  |  |  | 					firstUpdate = hmrUpdateMainFileName; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 2: | 
					
						
							|  |  |  | 					expect(updates.size).toBe(1); | 
					
						
							|  |  |  | 					expect(updates.has(firstUpdate)).toBe(true); | 
					
						
							|  |  |  | 					expect(hasFile(firstUpdate)).toBe(true); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case 3: | 
					
						
							|  |  |  | 					expect(updates.size).toBe(2); | 
					
						
							|  |  |  | 					for (const file of updates) { | 
					
						
							|  |  |  | 						expect(hasFile(file)).toBe(true); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return setTimeout(() => { | 
					
						
							|  |  |  | 						fs.writeFileSync(entryFile, `${++step}`, "utf-8"); | 
					
						
							|  |  |  | 						compiler.run(err => { | 
					
						
							|  |  |  | 							if (err) return done(err); | 
					
						
							|  |  |  | 							for (const file of updates) { | 
					
						
							|  |  |  | 								expect(hasFile(file)).toBe(false); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							done(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, 10100); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			updates.add(hmrUpdateMainFileName); | 
					
						
							|  |  |  | 			fs.writeFileSync(entryFile, `${++step}`, "utf-8"); | 
					
						
							|  |  |  | 			compiler.run(callback); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.run(callback); | 
					
						
							|  |  |  | 	}, 20000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 	it("should correct working when entry is Object and key is a number", done => { | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 		const outputPath = path.join(__dirname, "js", "HotModuleReplacementPlugin"); | 
					
						
							| 
									
										
										
										
											2019-02-19 15:58:46 +08:00
										 |  |  | 		const entryFile = path.join(outputPath, "entry.js"); | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 		const statsFile3 = path.join( | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 			outputPath, | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			"HotModuleReplacementPlugin.test.stats3.txt" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const statsFile4 = path.join( | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 			outputPath, | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			"HotModuleReplacementPlugin.test.stats4.txt" | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-02-19 15:58:46 +08:00
										 |  |  | 		const recordsFile = path.join(outputPath, "records.json"); | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 		try { | 
					
						
							| 
									
										
										
										
											2020-01-13 23:29:12 +08:00
										 |  |  | 			fs.mkdirSync(outputPath, { recursive: true }); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			fs.unlinkSync(recordsFile); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const compiler = webpack({ | 
					
						
							|  |  |  | 			mode: "development", | 
					
						
							|  |  |  | 			cache: false, | 
					
						
							|  |  |  | 			entry: { | 
					
						
							| 
									
										
										
										
											2020-09-01 17:30:46 +08:00
										 |  |  | 				0: entryFile | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			recordsPath: recordsFile, | 
					
						
							|  |  |  | 			output: { | 
					
						
							| 
									
										
										
										
											2019-01-19 03:38:34 +08:00
										 |  |  | 				path: outputPath | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			plugins: [new webpack.HotModuleReplacementPlugin()], | 
					
						
							|  |  |  | 			optimization: { | 
					
						
							| 
									
										
										
										
											2018-11-03 20:04:13 +08:00
										 |  |  | 				chunkIds: "named" | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		fs.writeFileSync(entryFile, "1", "utf-8"); | 
					
						
							|  |  |  | 		compiler.run((err, stats) => { | 
					
						
							|  |  |  | 			if (err) throw err; | 
					
						
							|  |  |  | 			const jsonStats = stats.toJson(); | 
					
						
							|  |  |  | 			const hash = jsonStats.hash; | 
					
						
							| 
									
										
										
										
											2018-11-30 18:54:43 +08:00
										 |  |  | 			const chunkName = Object.keys(jsonStats.assetsByChunkName)[0]; | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 			fs.writeFileSync(statsFile3, stats.toString()); | 
					
						
							|  |  |  | 			compiler.run((err, stats) => { | 
					
						
							|  |  |  | 				if (err) throw err; | 
					
						
							|  |  |  | 				fs.writeFileSync(statsFile4, stats.toString()); | 
					
						
							|  |  |  | 				fs.writeFileSync(entryFile, "2", "utf-8"); | 
					
						
							|  |  |  | 				compiler.run((err, stats) => { | 
					
						
							|  |  |  | 					if (err) throw err; | 
					
						
							|  |  |  | 					fs.writeFileSync(statsFile3, stats.toString()); | 
					
						
							|  |  |  | 					const result = JSON.parse( | 
					
						
							| 
									
										
										
										
											2019-02-19 15:58:46 +08:00
										 |  |  | 						fs.readFileSync( | 
					
						
							| 
									
										
										
										
											2020-11-29 01:27:44 +08:00
										 |  |  | 							path.join(outputPath, `0.${hash}.hot-update.json`), | 
					
						
							| 
									
										
										
										
											2019-02-19 15:58:46 +08:00
										 |  |  | 							"utf-8" | 
					
						
							|  |  |  | 						) | 
					
						
							| 
									
										
										
										
											2024-07-31 09:37:24 +08:00
										 |  |  | 					).c; | 
					
						
							| 
									
										
										
										
											2018-11-30 18:54:43 +08:00
										 |  |  | 					expect(result).toEqual([chunkName]); | 
					
						
							| 
									
										
										
										
											2018-10-30 15:49:48 +08:00
										 |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	it("should handle entryFile that contains path variable", done => { | 
					
						
							|  |  |  | 		const entryFile = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"[name]", | 
					
						
							|  |  |  | 			"entry.js" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const statsFile3 = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin.test.stats3.txt" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const statsFile4 = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin.test.stats4.txt" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const recordsFile = path.join( | 
					
						
							|  |  |  | 			__dirname, | 
					
						
							|  |  |  | 			"js", | 
					
						
							|  |  |  | 			"HotModuleReplacementPlugin", | 
					
						
							|  |  |  | 			"records.json" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		try { | 
					
						
							| 
									
										
										
										
											2020-01-13 23:29:12 +08:00
										 |  |  | 			fs.mkdirSync( | 
					
						
							|  |  |  | 				path.join(__dirname, "js", "HotModuleReplacementPlugin", "[name]"), | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					recursive: true | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 			); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		try { | 
					
						
							|  |  |  | 			fs.unlinkSync(recordsFile); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 		} catch (_err) { | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 			// empty
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		const compiler = webpack({ | 
					
						
							|  |  |  | 			mode: "development", | 
					
						
							|  |  |  | 			cache: false, | 
					
						
							|  |  |  | 			entry: { | 
					
						
							|  |  |  | 				"[name]/entry.js": entryFile | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			recordsPath: recordsFile, | 
					
						
							|  |  |  | 			output: { | 
					
						
							|  |  |  | 				filename: "[name]", | 
					
						
							|  |  |  | 				chunkFilename: "[name].js", | 
					
						
							|  |  |  | 				path: path.join(__dirname, "js", "HotModuleReplacementPlugin"), | 
					
						
							| 
									
										
										
										
											2025-03-18 12:43:47 +08:00
										 |  |  | 				hotUpdateChunkFilename: "static/webpack/[id].[fullhash].hot-update.js", | 
					
						
							|  |  |  | 				hotUpdateMainFilename: "static/webpack/[fullhash].hot-update.json" | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 			plugins: [new webpack.HotModuleReplacementPlugin()], | 
					
						
							|  |  |  | 			optimization: { | 
					
						
							| 
									
										
										
										
											2019-08-05 18:15:03 +08:00
										 |  |  | 				chunkIds: "named" | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		fs.writeFileSync(entryFile, "1", "utf-8"); | 
					
						
							|  |  |  | 		compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2019-07-23 23:37:07 +08:00
										 |  |  | 			if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 			fs.writeFileSync(statsFile3, stats.toString()); | 
					
						
							|  |  |  | 			compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2019-07-23 23:37:07 +08:00
										 |  |  | 				if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 				fs.writeFileSync(statsFile4, stats.toString()); | 
					
						
							|  |  |  | 				fs.writeFileSync(entryFile, "2", "utf-8"); | 
					
						
							|  |  |  | 				compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2019-07-23 23:37:07 +08:00
										 |  |  | 					if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 					fs.writeFileSync(statsFile3, stats.toString()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					let foundUpdates = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 					for (const key of Object.keys(stats.compilation.assets)) { | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 						foundUpdates = | 
					
						
							|  |  |  | 							foundUpdates || | 
					
						
							| 
									
										
										
										
											2024-07-31 11:11:11 +08:00
										 |  |  | 							Boolean( | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 								/static\/webpack\/\[name\]\/entry\.js\..*?\.hot-update\.js/.test( | 
					
						
							|  |  |  | 									key | 
					
						
							| 
									
										
										
										
											2024-07-31 11:11:11 +08:00
										 |  |  | 								) | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 							); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2019-07-23 04:41:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					expect(foundUpdates).toBe(true); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2015-08-09 18:42:43 +08:00
										 |  |  | }); |