| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | var should = require("should"); | 
					
						
							|  |  |  | var path = require("path"); | 
					
						
							|  |  |  | var fs = require("fs"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var webpack = require("../"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("HotModuleReplacementPlugin", function() { | 
					
						
							|  |  |  | 	it("should not have circular hashes but equal if unmodified", function(done) { | 
					
						
							|  |  |  | 		var entryFile = path.join(__dirname, "js", "entry.js"); | 
					
						
							|  |  |  | 		var recordsFile = path.join(__dirname, "js", "records.json"); | 
					
						
							| 
									
										
										
										
											2013-07-05 21:03:10 +08:00
										 |  |  | 		try { fs.mkdirSync(path.join(__dirname, "js")); } catch(e) {} | 
					
						
							| 
									
										
										
										
											2013-07-08 14:12:48 +08:00
										 |  |  | 		try { fs.unlinkSync(recordsFile); } catch(e) {} | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 		var 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: { | 
					
						
							|  |  |  | 				path: path.join(__dirname, "js") | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 			plugins: [ | 
					
						
							| 
									
										
										
										
											2014-02-11 20:27:41 +08:00
										 |  |  | 				new webpack.HotModuleReplacementPlugin(), | 
					
						
							|  |  |  | 				new webpack.optimize.OccurenceOrderPlugin() | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 			] | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		fs.writeFileSync(entryFile, "1", "utf-8"); | 
					
						
							|  |  |  | 		compiler.run(function(err, stats) { | 
					
						
							|  |  |  | 			if(err) throw err; | 
					
						
							|  |  |  | 			var oldHash1 = stats.toJson().hash; | 
					
						
							|  |  |  | 			compiler.run(function(err, stats) { | 
					
						
							|  |  |  | 				if(err) throw err; | 
					
						
							|  |  |  | 				var lastHash1 = stats.toJson().hash; | 
					
						
							|  |  |  | 				lastHash1.should.be.eql(oldHash1); | 
					
						
							|  |  |  | 				fs.writeFileSync(entryFile, "2", "utf-8"); | 
					
						
							|  |  |  | 				compiler.run(function(err, stats) { | 
					
						
							|  |  |  | 					if(err) throw err; | 
					
						
							|  |  |  | 					var lastHash2 = stats.toJson().hash; | 
					
						
							| 
									
										
										
										
											2014-03-21 23:21:59 +08:00
										 |  |  | 					lastHash2.should.not.be.eql(lastHash1); | 
					
						
							| 
									
										
										
										
											2013-07-05 20:56:16 +08:00
										 |  |  | 					fs.writeFileSync(entryFile, "1", "utf-8"); | 
					
						
							|  |  |  | 					compiler.run(function(err, stats) { | 
					
						
							|  |  |  | 						if(err) throw err; | 
					
						
							|  |  |  | 						var currentHash1 = stats.toJson().hash; | 
					
						
							|  |  |  | 						currentHash1.should.not.be.eql(lastHash1); | 
					
						
							|  |  |  | 						fs.writeFileSync(entryFile, "2", "utf-8"); | 
					
						
							|  |  |  | 						compiler.run(function(err, stats) { | 
					
						
							|  |  |  | 							if(err) throw err; | 
					
						
							|  |  |  | 							var currentHash2 = stats.toJson().hash; | 
					
						
							|  |  |  | 							compiler.run(function(err, stats) { | 
					
						
							|  |  |  | 								if(err) throw err; | 
					
						
							|  |  |  | 								stats.toJson().hash.should.be.eql(currentHash2); | 
					
						
							|  |  |  | 								currentHash2.should.not.be.eql(lastHash2); | 
					
						
							|  |  |  | 								currentHash1.should.not.be.eql(currentHash2); | 
					
						
							|  |  |  | 								lastHash1.should.not.be.eql(lastHash2); | 
					
						
							|  |  |  | 								done(); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |