| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* globals describe it */ | 
					
						
							|  |  |  | const path = require("path"); | 
					
						
							|  |  |  | const MemoryFs = require("memory-fs"); | 
					
						
							|  |  |  | const webpack = require("../"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const createMultiCompiler = () => { | 
					
						
							|  |  |  | 	const compiler = webpack([{ | 
					
						
							|  |  |  | 		context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 		entry: "./a.js" | 
					
						
							|  |  |  | 	}, { | 
					
						
							|  |  |  | 		context: path.join(__dirname, "fixtures"), | 
					
						
							|  |  |  | 		entry: "./b.js" | 
					
						
							|  |  |  | 	}]); | 
					
						
							|  |  |  | 	compiler.outputFileSystem = new MemoryFs(); | 
					
						
							|  |  |  | 	return compiler; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("MultiCompiler", function() { | 
					
						
							|  |  |  | 	it("should trigger 'run' for each child compiler", done => { | 
					
						
							|  |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							|  |  |  | 		let called = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.hooks.run.tap("MultiCompiler test", () => called++); | 
					
						
							|  |  |  | 		compiler.run(err => { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				throw err; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | 				expect(called).toBe(2); | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it("should trigger 'watchRun' for each child compiler", done => { | 
					
						
							|  |  |  | 		const compiler = createMultiCompiler(); | 
					
						
							|  |  |  | 		let called = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.hooks.watchRun.tap("MultiCompiler test", () => called++); | 
					
						
							|  |  |  | 		const watcher = compiler.watch(1000, err => { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				throw err; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				watcher.close(); | 
					
						
							| 
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 |  |  | 				expect(called).toBe(2); | 
					
						
							| 
									
										
										
										
											2017-12-29 18:23:14 +08:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |