mirror of https://github.com/webpack/webpack.git
				
				
				
			refactor(ES6): WatchDetection.test.js
This commit is contained in:
		
							parent
							
								
									de9323f791
								
							
						
					
					
						commit
						e27901da4d
					
				|  | @ -1,35 +1,37 @@ | |||
| "use strict"; | ||||
| 
 | ||||
| /*globals describe it before after  */ | ||||
| var should = require("should"); | ||||
| var path = require("path"); | ||||
| var fs = require("fs"); | ||||
| var MemoryFs = require("memory-fs"); | ||||
| const should = require("should"); | ||||
| const path = require("path"); | ||||
| const fs = require("fs"); | ||||
| const MemoryFs = require("memory-fs"); | ||||
| 
 | ||||
| var webpack = require("../"); | ||||
| const webpack = require("../"); | ||||
| 
 | ||||
| describe("WatchDetection", function() { | ||||
| 	for(var changeTimeout = 0; changeTimeout < 100; changeTimeout += 10) { | ||||
| describe("WatchDetection", () => { | ||||
| 	for(let changeTimeout = 0; changeTimeout < 100; changeTimeout += 10) { | ||||
| 		createTestCase(changeTimeout); | ||||
| 	} | ||||
| 	for(var changeTimeout = 100; changeTimeout <= 2000; changeTimeout += 100) { | ||||
| 	for(let changeTimeout = 100; changeTimeout <= 2000; changeTimeout += 100) { | ||||
| 		createTestCase(changeTimeout); | ||||
| 	} | ||||
| 
 | ||||
| 	function createTestCase(changeTimeout) { | ||||
| 		describe("time between changes " + changeTimeout + "ms", function() { | ||||
| 			this.timeout(10000); | ||||
| 			var fixturePath = path.join(__dirname, "fixtures", "temp-" + changeTimeout); | ||||
| 			var filePath = path.join(fixturePath, "file.js"); | ||||
| 			var file2Path = path.join(fixturePath, "file2.js"); | ||||
| 			var loaderPath = path.join(__dirname, "fixtures", "delay-loader.js"); | ||||
| 			before(function() { | ||||
| 			const fixturePath = path.join(__dirname, "fixtures", "temp-" + changeTimeout); | ||||
| 			const filePath = path.join(fixturePath, "file.js"); | ||||
| 			const file2Path = path.join(fixturePath, "file2.js"); | ||||
| 			const loaderPath = path.join(__dirname, "fixtures", "delay-loader.js"); | ||||
| 			before(() => { | ||||
| 				try { | ||||
| 					fs.mkdirSync(fixturePath); | ||||
| 				} catch(e) {} | ||||
| 				fs.writeFileSync(filePath, "require('./file2')", "utf-8"); | ||||
| 				fs.writeFileSync(file2Path, "original", "utf-8"); | ||||
| 			}); | ||||
| 			after(function(done) { | ||||
| 				setTimeout(function() { | ||||
| 			after((done) => { | ||||
| 				setTimeout(() => { | ||||
| 					try { | ||||
| 						fs.unlinkSync(filePath); | ||||
| 					} catch(e) {} | ||||
|  | @ -42,33 +44,34 @@ describe("WatchDetection", function() { | |||
| 					done(); | ||||
| 				}, 100); // cool down a bit
 | ||||
| 			}); | ||||
| 			it("should build the bundle correctly", function(done) { | ||||
| 				var compiler = webpack({ | ||||
| 			it("should build the bundle correctly", (done) => { | ||||
| 				const compiler = webpack({ | ||||
| 					entry: loaderPath + "!" + filePath, | ||||
| 					output: { | ||||
| 						path: "/", | ||||
| 						filename: "bundle.js" | ||||
| 					} | ||||
| 				}); | ||||
| 				var memfs = compiler.outputFileSystem = new MemoryFs(); | ||||
| 				var onChange; | ||||
| 				compiler.plugin("done", function() { | ||||
| 					if(onChange) onChange(); | ||||
| 				const memfs = compiler.outputFileSystem = new MemoryFs(); | ||||
| 				let onChange; | ||||
| 				compiler.plugin("done", () => { | ||||
| 					if(onChange) | ||||
| 						onChange(); | ||||
| 				}); | ||||
| 
 | ||||
| 				var watcher; | ||||
| 				let watcher; | ||||
| 
 | ||||
| 				step1(); | ||||
| 
 | ||||
| 				function step1() { | ||||
| 					onChange = function() { | ||||
| 					onChange = () => { | ||||
| 						if(memfs.readFileSync("/bundle.js") && memfs.readFileSync("/bundle.js").toString().indexOf("original") >= 0) | ||||
| 							step2(); | ||||
| 					} | ||||
| 					}; | ||||
| 
 | ||||
| 					watcher = compiler.watch({ | ||||
| 						aggregateTimeout: 50 | ||||
| 					}, function() {}); | ||||
| 					}, () => {}); | ||||
| 				} | ||||
| 
 | ||||
| 				function step2() { | ||||
|  | @ -88,10 +91,10 @@ describe("WatchDetection", function() { | |||
| 				} | ||||
| 
 | ||||
| 				function step4() { | ||||
| 					onChange = function() { | ||||
| 					onChange = () => { | ||||
| 						if(memfs.readFileSync("/bundle.js").toString().indexOf("correct") >= 0) | ||||
| 							step4(); | ||||
| 					} | ||||
| 					}; | ||||
| 
 | ||||
| 					fs.writeFile(file2Path, "correct", "utf-8", handleError); | ||||
| 				} | ||||
|  | @ -108,6 +111,6 @@ describe("WatchDetection", function() { | |||
| 					if(err) done(err); | ||||
| 				} | ||||
| 			}); | ||||
| 		}) | ||||
| 		}); | ||||
| 	} | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue