| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const should = require("should"); | 
					
						
							|  |  |  | const sinon = require("sinon"); | 
					
						
							|  |  |  | const MultiCompiler = require("../lib/MultiCompiler"); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function CompilerEnvironment() { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	const pluginEvents = []; | 
					
						
							|  |  |  | 	const runCallbacks = []; | 
					
						
							|  |  |  | 	const watchCallbacks = []; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	this.getCompilerStub = function() { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			plugin: function(name, handler) { | 
					
						
							|  |  |  | 				pluginEvents.push({ | 
					
						
							|  |  |  | 					name, | 
					
						
							|  |  |  | 					handler | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			run: function(callback) { | 
					
						
							|  |  |  | 				runCallbacks.push({ | 
					
						
							|  |  |  | 					callback | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			watch: function(options, callback) { | 
					
						
							|  |  |  | 				watchCallbacks.push({ | 
					
						
							|  |  |  | 					options, | 
					
						
							|  |  |  | 					callback | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				return this.name; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	this.getPluginEventBindings = () => pluginEvents; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	this.getRunCallbacks = () => runCallbacks; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	this.getWatchCallbacks = () => watchCallbacks; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | const createCompiler = function(overrides) { | 
					
						
							|  |  |  | 	const compilerEnvironment = new CompilerEnvironment(); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	return Object.assign({ | 
					
						
							|  |  |  | 		outputPath: "/" | 
					
						
							|  |  |  | 	}, compilerEnvironment.getCompilerStub(), overrides); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | const setupTwoCompilerEnvironment = function(env, compiler1Values, compiler2Values) { | 
					
						
							| 
									
										
										
										
											2017-09-17 22:29:09 +08:00
										 |  |  | 	return setupMutliCompilerEnvironment(env, 2, [compiler1Values, compiler2Values]); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const setupMutliCompilerEnvironment = function(env, count, compilerValues) { | 
					
						
							|  |  |  | 	const values = Array.isArray(compilerValues) ? compilerValues : new Array(count); | 
					
						
							|  |  |  | 	const environments = values.map(() => new CompilerEnvironment()); | 
					
						
							|  |  |  | 	const compilers = environments.map((e, i) => Object.assign({ | 
					
						
							|  |  |  | 		name: `compiler${i + 1}` | 
					
						
							|  |  |  | 	}, (values[i] || {}), e.getCompilerStub())); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	env.myMultiCompiler = new MultiCompiler(compilers); | 
					
						
							| 
									
										
										
										
											2017-09-17 22:29:09 +08:00
										 |  |  | 	environments.forEach((compilerEnvironment, i) => { | 
					
						
							|  |  |  | 		env[`compiler${i + 1}EventBindings`] = compilerEnvironment.getPluginEventBindings(); | 
					
						
							|  |  |  | 		env[`compiler${i + 1}WatchCallbacks`] = compilerEnvironment.getWatchCallbacks(); | 
					
						
							|  |  |  | 		env[`compiler${i + 1}RunCallbacks`] = compilerEnvironment.getRunCallbacks(); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | describe("MultiCompiler", () => { | 
					
						
							|  |  |  | 	let env; | 
					
						
							|  |  |  | 	beforeEach(() => env = {}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	describe("constructor", () => { | 
					
						
							|  |  |  | 		describe("when provided an array of compilers", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compilers = [createCompiler(), createCompiler()]; | 
					
						
							|  |  |  | 				env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("sets the compilers property to the array", () => env.myMultiCompiler.compilers.should.be.exactly(env.compilers)); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 		describe("when provided a compiler mapping", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				const compilers = { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					compiler1: createCompiler(), | 
					
						
							|  |  |  | 					compiler2: createCompiler() | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				env.myMultiCompiler = new MultiCompiler(compilers); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("sets the compilers property to an array of compilers", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.myMultiCompiler.compilers.should.deepEqual([ | 
					
						
							|  |  |  | 					Object.assign({ | 
					
						
							|  |  |  | 						name: "compiler1" | 
					
						
							|  |  |  | 					}, createCompiler()), | 
					
						
							|  |  |  | 					Object.assign({ | 
					
						
							|  |  |  | 						name: "compiler2" | 
					
						
							|  |  |  | 					}, createCompiler()) | 
					
						
							|  |  |  | 				]); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 		describe("defined properties", () => { | 
					
						
							|  |  |  | 			describe("outputFileSystem", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.compilers = [createCompiler(), createCompiler()]; | 
					
						
							|  |  |  | 					env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("throws an error when reading the value", () => { | 
					
						
							|  |  |  | 					should(() => { | 
					
						
							|  |  |  | 						env.myMultiCompiler.outputFileSystem; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}).throw("Cannot read outputFileSystem of a MultiCompiler"); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("updates all compilers when setting the value", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.myMultiCompiler.outputFileSystem = "foo"; | 
					
						
							|  |  |  | 					env.compilers[0].outputFileSystem.should.be.exactly("foo"); | 
					
						
							|  |  |  | 					env.compilers[1].outputFileSystem.should.be.exactly("foo"); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("inputFileSystem", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.compilers = [createCompiler(), createCompiler()]; | 
					
						
							|  |  |  | 					env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("throws an error when reading the value", () => { | 
					
						
							|  |  |  | 					should(() => { | 
					
						
							|  |  |  | 						env.myMultiCompiler.inputFileSystem; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}).throw("Cannot read inputFileSystem of a MultiCompiler"); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("updates all compilers when setting the value", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.myMultiCompiler.inputFileSystem = "foo"; | 
					
						
							|  |  |  | 					env.compilers[0].inputFileSystem.should.be.exactly("foo"); | 
					
						
							|  |  |  | 					env.compilers[1].inputFileSystem.should.be.exactly("foo"); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("outputPath", () => { | 
					
						
							|  |  |  | 				describe("when common path cannot be found and output path is absolute", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compilers = [ | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "/foo/bar" | 
					
						
							|  |  |  | 							}), | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "quux" | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						]; | 
					
						
							|  |  |  | 						env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("returns the root path", () => env.myMultiCompiler.outputPath.should.be.exactly("/")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("when common path cannot be found and output path is relative", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compilers = [ | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "foo/bar/baz" | 
					
						
							|  |  |  | 							}), | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "quux" | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						]; | 
					
						
							|  |  |  | 						env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("returns the first segment of relative path", () => | 
					
						
							|  |  |  | 						env.myMultiCompiler.outputPath.should.be.exactly("foo")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("when common path can be found and output path is absolute", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compilers = [ | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "/foo" | 
					
						
							|  |  |  | 							}), | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "/foo/bar/baz" | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						]; | 
					
						
							|  |  |  | 						env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("returns the shared path", () => env.myMultiCompiler.outputPath.should.be.exactly("/foo")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("when common path can be found and output path is relative", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compilers = [ | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "foo" | 
					
						
							|  |  |  | 							}), | 
					
						
							|  |  |  | 							createCompiler({ | 
					
						
							|  |  |  | 								outputPath: "foo/bar/baz" | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						]; | 
					
						
							|  |  |  | 						env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("returns the shared path", () => env.myMultiCompiler.outputPath.should.be.exactly("foo")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 		describe("compiler events", () => { | 
					
						
							|  |  |  | 			beforeEach(() => setupTwoCompilerEnvironment(env)); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("binds two event handler", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1EventBindings.length.should.be.exactly(2); | 
					
						
							|  |  |  | 				env.compiler2EventBindings.length.should.be.exactly(2); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("done handler", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.doneEventBinding1 = env.compiler1EventBindings[0]; | 
					
						
							|  |  |  | 					env.doneEventBinding2 = env.compiler2EventBindings[0]; | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("binds to done event", () => env.doneEventBinding1.name.should.be.exactly("done")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("when called for first compiler", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.mockDonePlugin = sinon.spy(); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						env.myMultiCompiler.plugin("done", env.mockDonePlugin); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.doneEventBinding1.handler({ | 
					
						
							|  |  |  | 							hash: "foo" | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("does not call the done plugin when not all compilers are finished", () => | 
					
						
							|  |  |  | 						env.mockDonePlugin.callCount.should.be.exactly(0)); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					describe("and called for second compiler", () => { | 
					
						
							|  |  |  | 						beforeEach(() => | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 							env.doneEventBinding2.handler({ | 
					
						
							|  |  |  | 								hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 							})); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						it("calls the done plugin", () => env.mockDonePlugin.callCount.should.be.exactly(1)); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("invalid handler", () => { | 
					
						
							|  |  |  | 				beforeEach(() => env.invalidEventBinding = env.compiler1EventBindings[1]); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("binds to invalid event", () => env.invalidEventBinding.name.should.be.exactly("invalid")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("when called", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.mockInvalidPlugin = sinon.spy(); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						env.myMultiCompiler.plugin("invalid", env.mockInvalidPlugin); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.invalidEventBinding.handler(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("calls the invalid plugin", () => env.mockInvalidPlugin.callCount.should.be.exactly(1)); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	describe("watch", () => { | 
					
						
							|  |  |  | 		describe("without compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				setupTwoCompilerEnvironment(env); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							| 
									
										
										
										
											2017-02-02 07:14:18 +08:00
										 |  |  | 				env.options = [{ | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					testWatchOptions: true | 
					
						
							| 
									
										
										
										
											2017-04-04 17:40:25 +08:00
										 |  |  | 				}, { | 
					
						
							|  |  |  | 					testWatchOptions2: true | 
					
						
							|  |  |  | 				}]; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.result = env.myMultiCompiler.watch(env.options, env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("returns a multi-watching object", () => { | 
					
						
							|  |  |  | 				const result = JSON.stringify(env.result); | 
					
						
							| 
									
										
										
										
											2017-11-15 21:08:11 +08:00
										 |  |  | 				result.should.be.exactly("{\"watchings\":[\"compiler1\",\"compiler2\"],\"compiler\":{\"_plugins\":{},\"compilers\":[{\"name\":\"compiler1\"},{\"name\":\"compiler2\"}]}}"); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls watch on each compiler with original options", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1WatchCallbacks.length.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-02-02 07:14:18 +08:00
										 |  |  | 				env.compiler1WatchCallbacks[0].options.should.be.exactly(env.options[0]); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler2WatchCallbacks.length.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-02-02 07:14:18 +08:00
										 |  |  | 				env.compiler2WatchCallbacks[0].options.should.be.exactly(env.options[1]); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls the callback when all compilers watch", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("on first run", () => { | 
					
						
							|  |  |  | 				describe("callback called with no compiler errors", () => { | 
					
						
							|  |  |  | 					beforeEach(() => env.compiler1WatchCallbacks[0].callback(new Error("Test error"))); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("has failure parameters", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 						env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 						should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("callback called with no compiler errors", () => { | 
					
						
							|  |  |  | 					beforeEach(() => | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compiler1WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 							hash: "foo" | 
					
						
							|  |  |  | 						})); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("does not call the callback", () => env.callback.callCount.should.be.exactly(0)); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("on subsequent runs", () => { | 
					
						
							|  |  |  | 				describe("callback called with compiler errors", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compiler1WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 							hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						env.compiler2WatchCallbacks[0].callback(new Error("Test error")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("has failure parameters", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 						env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 						should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				describe("callback called with no compiler errors", () => { | 
					
						
							|  |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.compiler1WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 							hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 						env.compiler2WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 							hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					it("has success parameters", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 						env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 						should(env.callback.getCall(0).args[0]).be.Null(); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						const stats = JSON.stringify(env.callback.getCall(0).args[1]); | 
					
						
							| 
									
										
										
										
											2017-11-15 21:08:11 +08:00
										 |  |  | 						stats.should.be.exactly("{\"stats\":[{\"hash\":\"foo\"},{\"hash\":\"bar\"}],\"hash\":\"foobar\"}"); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 		describe("with compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				setupTwoCompilerEnvironment(env, { | 
					
						
							|  |  |  | 					name: "compiler1", | 
					
						
							|  |  |  | 					dependencies: ["compiler2"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "compiler2" | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							| 
									
										
										
										
											2017-02-02 07:14:18 +08:00
										 |  |  | 				env.options = [{ | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					testWatchOptions: true | 
					
						
							| 
									
										
										
										
											2017-04-04 17:40:25 +08:00
										 |  |  | 				}, { | 
					
						
							|  |  |  | 					testWatchOptions2: true | 
					
						
							|  |  |  | 				}]; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.result = env.myMultiCompiler.watch(env.options, env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls run on each compiler in dependency order", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1WatchCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2WatchCallbacks.length.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-02-02 07:14:18 +08:00
										 |  |  | 				env.compiler2WatchCallbacks[0].options.should.be.exactly(env.options[1]); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler2WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.compiler1WatchCallbacks.length.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-02-02 07:14:18 +08:00
										 |  |  | 				env.compiler1WatchCallbacks[0].options.should.be.exactly(env.options[0]); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls the callback when all compilers run in dependency order", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler2WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler1WatchCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-09 00:27:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		describe("with missing compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				setupTwoCompilerEnvironment(env, { | 
					
						
							|  |  |  | 					name: "compiler1", | 
					
						
							|  |  |  | 					dependencies: ["compiler2"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "compiler3" | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.options = [{ | 
					
						
							|  |  |  | 					testWatchOptions: true | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					testWatchOptions2: true | 
					
						
							|  |  |  | 				}]; | 
					
						
							|  |  |  | 				env.result = env.myMultiCompiler.watch(env.options, env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			it("should call the callback with an error message", () => { | 
					
						
							|  |  |  | 				env.compiler1WatchCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2WatchCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-09-11 21:55:28 +08:00
										 |  |  | 				env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 				should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							| 
									
										
										
										
											2017-09-09 00:27:55 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		describe("with circular compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				setupTwoCompilerEnvironment(env, { | 
					
						
							|  |  |  | 					name: "compiler1", | 
					
						
							|  |  |  | 					dependencies: ["compiler2"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "compiler2", | 
					
						
							|  |  |  | 					dependencies: ["compiler1"] | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.options = [{ | 
					
						
							|  |  |  | 					testWatchOptions: true | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					testWatchOptions2: true | 
					
						
							|  |  |  | 				}]; | 
					
						
							|  |  |  | 				env.result = env.myMultiCompiler.watch(env.options, env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			it("should call the callback with an error message", () => { | 
					
						
							|  |  |  | 				env.compiler1WatchCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2WatchCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-09-11 21:55:28 +08:00
										 |  |  | 				env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 				should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							| 
									
										
										
										
											2017-09-09 00:27:55 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-17 22:29:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		describe("with no root compiler", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				setupMutliCompilerEnvironment(env, 3, [{ | 
					
						
							|  |  |  | 					name: "a", | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "b", | 
					
						
							|  |  |  | 					dependencies: ["a", "c"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "c", | 
					
						
							|  |  |  | 					dependencies: ["b"] | 
					
						
							|  |  |  | 				}]); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.options = [{ | 
					
						
							|  |  |  | 					testWatchOptions: true | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					testWatchOptions2: true | 
					
						
							|  |  |  | 				}]; | 
					
						
							|  |  |  | 				env.result = env.myMultiCompiler.watch(env.options, env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			it("should call the callback with an error message", () => { | 
					
						
							|  |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler3RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 				env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 				should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	describe("run", () => { | 
					
						
							|  |  |  | 		describe("without compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				setupTwoCompilerEnvironment(env); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.myMultiCompiler.run(env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls run on each compiler", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(1); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks.length.should.be.exactly(1); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls the callback when all compilers run", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("callback called with no compiler errors", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.compiler1RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 					env.compiler2RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("has success parameters", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 					should(env.callback.getCall(0).args[0]).be.Null(); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					const stats = JSON.stringify(env.callback.getCall(0).args[1]); | 
					
						
							| 
									
										
										
										
											2017-11-15 21:08:11 +08:00
										 |  |  | 					stats.should.be.exactly("{\"stats\":[{\"hash\":\"foo\"},{\"hash\":\"bar\"}],\"hash\":\"foobar\"}"); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			describe("callback called with compiler errors", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.compiler1RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 						hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					env.compiler2RunCallbacks[0].callback(new Error("Test error")); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 				it("has failure parameters", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 					env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 					env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 					should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 		describe("with compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				setupTwoCompilerEnvironment(env, { | 
					
						
							|  |  |  | 					name: "compiler1", | 
					
						
							|  |  |  | 					dependencies: ["compiler2"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "compiler2" | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.myMultiCompiler.run(env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls run on each compiler in dependency order", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks.length.should.be.exactly(1); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(1); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 			it("calls the callback when all compilers run in dependency order", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				env.compiler2RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "bar" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler1RunCallbacks[0].callback(null, { | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 					hash: "foo" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-09 00:27:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		describe("with missing compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				setupTwoCompilerEnvironment(env, { | 
					
						
							|  |  |  | 					name: "compiler1", | 
					
						
							|  |  |  | 					dependencies: ["compiler2"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "compiler3" | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.myMultiCompiler.run(env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			it("should call the callback with an error message", () => { | 
					
						
							|  |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-09-11 21:55:28 +08:00
										 |  |  | 				env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 				should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							| 
									
										
										
										
											2017-09-09 00:27:55 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		describe("with circular compiler dependencies", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				setupTwoCompilerEnvironment(env, { | 
					
						
							|  |  |  | 					name: "compiler1", | 
					
						
							|  |  |  | 					dependencies: ["compiler2"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "compiler2", | 
					
						
							|  |  |  | 					dependencies: ["compiler1"] | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.myMultiCompiler.run(env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			it("should call the callback with an error message", () => { | 
					
						
							|  |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							| 
									
										
										
										
											2017-09-11 21:55:28 +08:00
										 |  |  | 				env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 				should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							| 
									
										
										
										
											2017-09-09 00:27:55 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-17 22:29:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		describe("with no root compiler", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				setupMutliCompilerEnvironment(env, 3, [{ | 
					
						
							|  |  |  | 					name: "a", | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "b", | 
					
						
							|  |  |  | 					dependencies: ["a", "c"] | 
					
						
							|  |  |  | 				}, { | 
					
						
							|  |  |  | 					name: "c", | 
					
						
							|  |  |  | 					dependencies: ["b"] | 
					
						
							|  |  |  | 				}]); | 
					
						
							|  |  |  | 				env.callback = sinon.spy(); | 
					
						
							|  |  |  | 				env.myMultiCompiler.run(env.callback); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			it("should call the callback with an error message", () => { | 
					
						
							|  |  |  | 				env.compiler1RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler2RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.compiler3RunCallbacks.length.should.be.exactly(0); | 
					
						
							|  |  |  | 				env.callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 				env.callback.getCall(0).args[0].should.be.Error(); | 
					
						
							|  |  |  | 				should(env.callback.getCall(0).args[1]).be.undefined(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 	describe("purgeInputFileSystem", () => { | 
					
						
							|  |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			env.compilers = [ | 
					
						
							|  |  |  | 				Object.assign({ | 
					
						
							|  |  |  | 					inputFileSystem: { | 
					
						
							|  |  |  | 						purge: sinon.spy() | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}, createCompiler()), | 
					
						
							|  |  |  | 				createCompiler() | 
					
						
							|  |  |  | 			]; | 
					
						
							|  |  |  | 			env.myMultiCompiler = new MultiCompiler(env.compilers); | 
					
						
							|  |  |  | 			env.myMultiCompiler.purgeInputFileSystem(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:31:32 +08:00
										 |  |  | 		it("calls the compilers purge if available", () => { | 
					
						
							|  |  |  | 			const purgeSpy = env.compilers[0].inputFileSystem.purge; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			purgeSpy.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |