| 
									
										
										
										
											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 SyncHook = require("tapable").SyncHook; | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | const MultiWatching = require("../lib/MultiWatching"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | const createWatching = () => ({ | 
					
						
							|  |  |  | 	invalidate: jest.fn(), | 
					
						
							|  |  |  | 	suspend: jest.fn(), | 
					
						
							|  |  |  | 	resume: jest.fn(), | 
					
						
							|  |  |  | 	close: jest.fn() | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	}; | 
					
						
							|  |  |  | 	return compiler; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | describe("MultiWatching", () => { | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 	let watchings; | 
					
						
							|  |  |  | 	let compiler; | 
					
						
							|  |  |  | 	let 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", () => { | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							|  |  |  | 			myMultiWatching.invalidate(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		it("invalidates each watching", () => { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			expect(watchings[0].invalidate.mock.calls).toHaveLength(1); | 
					
						
							|  |  |  | 			expect(watchings[1].invalidate.mock.calls).toHaveLength(1); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-01 01:05:10 +08:00
										 |  |  | 	describe("suspend", () => { | 
					
						
							|  |  |  | 		it("suspends each watching", () => { | 
					
						
							|  |  |  | 			myMultiWatching.suspend(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			expect(watchings[0].suspend.mock.calls).toHaveLength(1); | 
					
						
							|  |  |  | 			expect(watchings[1].suspend.mock.calls).toHaveLength(1); | 
					
						
							| 
									
										
										
										
											2019-06-01 01:05:10 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("resume each watching", () => { | 
					
						
							|  |  |  | 			myMultiWatching.resume(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			expect(watchings[0].resume.mock.calls).toHaveLength(1); | 
					
						
							|  |  |  | 			expect(watchings[1].resume.mock.calls).toHaveLength(1); | 
					
						
							| 
									
										
										
										
											2019-06-01 01:05:10 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 	describe("close", () => { | 
					
						
							|  |  |  | 		let callback; | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		const callClosedFinishedCallback = (watching) => { | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			watching.close.mock.calls[0][0](); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			callback = jest.fn(); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			myMultiWatching.close(callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 21:42:59 +08:00
										 |  |  | 		it("closes each watching", () => { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			expect(watchings[0].close.mock.calls).toHaveLength(1); | 
					
						
							|  |  |  | 			expect(watchings[1].close.mock.calls).toHaveLength(1); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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]); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			expect(callback.mock.calls).toHaveLength(1); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |