| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 22:01:41 +08:00
										 |  |  | const Tapable = require("tapable").Tapable; | 
					
						
							|  |  |  | const SyncHook = require("tapable").SyncHook; | 
					
						
							| 
									
										
										
										
											2017-11-15 21:08:11 +08:00
										 |  |  | require("should"); | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | const sinon = require("sinon"); | 
					
						
							|  |  |  | const MultiWatching = require("../lib/MultiWatching"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const createWatching = function() { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	return { | 
					
						
							|  |  |  | 		invalidate: sinon.spy(), | 
					
						
							|  |  |  | 		close: sinon.spy() | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-06 11:32:34 +08:00
										 |  |  | const createCompiler = () => { | 
					
						
							|  |  |  | 	const compiler = { | 
					
						
							| 
									
										
										
										
											2017-11-28 22:01:41 +08:00
										 |  |  | 		hooks: { | 
					
						
							|  |  |  | 			watchClose: new SyncHook([]) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-06 11:32:34 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-11-28 22:01:41 +08:00
										 |  |  | 	Tapable.addCompatLayer(compiler); | 
					
						
							| 
									
										
										
										
											2017-03-06 11:32:34 +08:00
										 |  |  | 	return compiler; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | describe("MultiWatching", () => { | 
					
						
							| 
									
										
										
										
											2017-03-06 11:32:34 +08:00
										 |  |  | 	let watchings, compiler, myMultiWatching; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 	beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		watchings = [createWatching(), createWatching()]; | 
					
						
							| 
									
										
										
										
											2017-03-06 11:32:34 +08:00
										 |  |  | 		compiler = createCompiler(); | 
					
						
							|  |  |  | 		myMultiWatching = new MultiWatching(watchings, compiler); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 	describe("invalidate", () => { | 
					
						
							|  |  |  | 		beforeEach(() => myMultiWatching.invalidate()); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		it("invalidates each watching", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			watchings[0].invalidate.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 			watchings[1].invalidate.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 	describe("close", () => { | 
					
						
							|  |  |  | 		let callback; | 
					
						
							|  |  |  | 		const callClosedFinishedCallback = (watching) => watching.close.getCall(0).args[0](); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			callback = sinon.spy(); | 
					
						
							|  |  |  | 			myMultiWatching.close(callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		it("closes each watching", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			watchings[0].close.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 			watchings[1].close.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		it("calls callback after each watching has closed", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			callClosedFinishedCallback(watchings[0]); | 
					
						
							|  |  |  | 			callClosedFinishedCallback(watchings[1]); | 
					
						
							|  |  |  | 			callback.callCount.should.be.exactly(1); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |