| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | /* globals describe, it, beforeEach, afterEach */ | 
					
						
							|  |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | const sinon = require("sinon"); | 
					
						
							|  |  |  | const NormalModule = require("../lib/NormalModule"); | 
					
						
							| 
									
										
										
										
											2017-04-04 07:07:14 +08:00
										 |  |  | const NullDependency = require("../lib/dependencies/NullDependency"); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | const SourceMapSource = require("webpack-sources").SourceMapSource; | 
					
						
							|  |  |  | const OriginalSource = require("webpack-sources").OriginalSource; | 
					
						
							|  |  |  | const RawSource = require("webpack-sources").RawSource; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | describe("NormalModule", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 	let normalModule; | 
					
						
							|  |  |  | 	let request; | 
					
						
							|  |  |  | 	let userRequest; | 
					
						
							|  |  |  | 	let rawRequest; | 
					
						
							|  |  |  | 	let loaders; | 
					
						
							|  |  |  | 	let resource; | 
					
						
							|  |  |  | 	let parser; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		request = "some/request"; | 
					
						
							|  |  |  | 		userRequest = "some/userRequest"; | 
					
						
							|  |  |  | 		rawRequest = "some/rawRequest"; | 
					
						
							|  |  |  | 		loaders = []; | 
					
						
							|  |  |  | 		resource = "some/resource"; | 
					
						
							|  |  |  | 		parser = { | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 			parse() {} | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		normalModule = new NormalModule( | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 			"javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			request, | 
					
						
							|  |  |  | 			userRequest, | 
					
						
							|  |  |  | 			rawRequest, | 
					
						
							|  |  |  | 			loaders, | 
					
						
							|  |  |  | 			resource, | 
					
						
							|  |  |  | 			parser | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-12-13 04:21:02 +08:00
										 |  |  | 		normalModule.buildInfo = { | 
					
						
							|  |  |  | 			cacheable: true | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#identifier", () => { | 
					
						
							|  |  |  | 		it("returns an identifier for this module", () => { | 
					
						
							|  |  |  | 			expect(normalModule.identifier()).toBe(request); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("returns an identifier from toString", () => { | 
					
						
							| 
									
										
										
										
											2017-04-04 06:40:13 +08:00
										 |  |  | 			normalModule.debugId = 1000; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(normalModule.toString()).toBe("Module[1000]"); | 
					
						
							| 
									
										
										
										
											2017-04-04 06:40:13 +08:00
										 |  |  | 			normalModule.id = 1; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(normalModule.toString()).toBe("Module[1]"); | 
					
						
							| 
									
										
										
										
											2017-04-04 06:40:13 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#readableIdentifier", () => { | 
					
						
							|  |  |  | 		it("calls the given requestShortener with the user request", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			const spy = sinon.spy(); | 
					
						
							|  |  |  | 			normalModule.readableIdentifier({ | 
					
						
							|  |  |  | 				shorten: spy | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(spy.callCount).toBe(1); | 
					
						
							|  |  |  | 			expect(spy.args[0][0]).toBe(userRequest); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#libIdent", () => { | 
					
						
							|  |  |  | 		it("contextifies the userRequest of the module", () => { | 
					
						
							|  |  |  | 			expect(normalModule.libIdent({ | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				context: "some/context" | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			})).toBe("../userRequest"); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a userRequest containing loaders", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				userRequest = "some/userRequest!some/other/userRequest!some/thing/is/off/here"; | 
					
						
							|  |  |  | 				normalModule = new NormalModule( | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 					"javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					userRequest, | 
					
						
							|  |  |  | 					rawRequest, | 
					
						
							|  |  |  | 					loaders, | 
					
						
							|  |  |  | 					resource, | 
					
						
							|  |  |  | 					parser | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("contextifies every path in the userRequest", () => { | 
					
						
							|  |  |  | 				expect(normalModule.libIdent({ | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 					context: "some/context" | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				})).toBe("../userRequest!../other/userRequest!../thing/is/off/here"); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a userRequest containing query parameters", () => { | 
					
						
							|  |  |  | 			it("ignores paths in query parameters", () => { | 
					
						
							| 
									
										
										
										
											2017-08-30 05:50:22 +08:00
										 |  |  | 				userRequest = "some/context/loader?query=foo\\bar&otherPath=testpath/other"; | 
					
						
							|  |  |  | 				normalModule = new NormalModule( | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 					"javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-08-30 05:50:22 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					userRequest, | 
					
						
							|  |  |  | 					rawRequest, | 
					
						
							|  |  |  | 					loaders, | 
					
						
							|  |  |  | 					resource, | 
					
						
							|  |  |  | 					parser | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				expect(normalModule.libIdent({ | 
					
						
							| 
									
										
										
										
											2017-08-30 05:50:22 +08:00
										 |  |  | 					context: "some/context", | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				})).toBe("./loader?query=foo\\bar&otherPath=testpath/other"); | 
					
						
							| 
									
										
										
										
											2017-08-30 05:50:22 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#nameForCondition", () => { | 
					
						
							|  |  |  | 		it("return the resource", () => { | 
					
						
							|  |  |  | 			expect(normalModule.nameForCondition()).toBe(resource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a resource containing a ?-sign", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			const baseResource = "some/resource"; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				resource = baseResource + "?some=query"; | 
					
						
							|  |  |  | 				normalModule = new NormalModule( | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 					"javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					userRequest, | 
					
						
							|  |  |  | 					rawRequest, | 
					
						
							|  |  |  | 					loaders, | 
					
						
							|  |  |  | 					resource, | 
					
						
							|  |  |  | 					parser | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("return only the part before the ?-sign", () => { | 
					
						
							|  |  |  | 				expect(normalModule.nameForCondition()).toBe(baseResource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#createSourceForAsset", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		let name; | 
					
						
							|  |  |  | 		let content; | 
					
						
							|  |  |  | 		let sourceMap; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			name = "some name"; | 
					
						
							|  |  |  | 			content = "some content"; | 
					
						
							|  |  |  | 			sourceMap = "some sourcemap"; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given no sourcemap", () => { | 
					
						
							|  |  |  | 			it("returns a RawSource", () => { | 
					
						
							|  |  |  | 				expect(normalModule.createSourceForAsset(name, content)).toBeInstanceOf(RawSource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a string as the sourcemap", () => { | 
					
						
							|  |  |  | 			it("returns a OriginalSource", () => { | 
					
						
							|  |  |  | 				expect(normalModule.createSourceForAsset(name, content, sourceMap)).toBeInstanceOf(OriginalSource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a some other kind of sourcemap", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				sourceMap = () => {}; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns a SourceMapSource", () => { | 
					
						
							|  |  |  | 				expect(normalModule.createSourceForAsset(name, content, sourceMap)).toBeInstanceOf(SourceMapSource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#source", () => { | 
					
						
							|  |  |  | 		describe("without the module having any source", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				normalModule._source = null; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns a Source containing an Error", () => { | 
					
						
							|  |  |  | 				expect(normalModule.source()).toBeInstanceOf(RawSource); | 
					
						
							|  |  |  | 				expect(normalModule.source().source()).toBe("throw new Error('No source available');"); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#originalSource", () => { | 
					
						
							| 
									
										
										
										
											2017-04-03 15:48:55 +08:00
										 |  |  | 		let expectedSource = "some source"; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-04-03 15:48:55 +08:00
										 |  |  | 			normalModule._source = new RawSource(expectedSource); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("returns an original Source", () => { | 
					
						
							|  |  |  | 			expect(normalModule.originalSource()).toBe(normalModule._source); | 
					
						
							| 
									
										
										
										
											2017-04-03 15:48:55 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#updateHashWithSource", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		let hashSpy; | 
					
						
							|  |  |  | 		let hash; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			hashSpy = sinon.spy(); | 
					
						
							|  |  |  | 			hash = { | 
					
						
							|  |  |  | 				update: hashSpy | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("without the module having any source", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				normalModule._source = null; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("calls hash function with \"null\"", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				normalModule.updateHashWithSource(hash); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				expect(hashSpy.callCount).toBe(1); | 
					
						
							|  |  |  | 				expect(hashSpy.args[0][0]).toBe("null"); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("without the module having source", () => { | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 			let expectedSource = "some source"; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				normalModule._source = new RawSource(expectedSource); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			it("calls hash function with \"source\" and then the actual source of the module", function() { | 
					
						
							|  |  |  | 				normalModule.updateHashWithSource(hash); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				expect(hashSpy.callCount).toBe(2); | 
					
						
							|  |  |  | 				expect(hashSpy.args[0][0]).toBe("source"); | 
					
						
							|  |  |  | 				expect(hashSpy.args[1][0]).toBe(expectedSource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#hasDependencies", () => { | 
					
						
							|  |  |  | 		it("returns true if has dependencies", () => { | 
					
						
							| 
									
										
										
										
											2017-04-04 07:07:14 +08:00
										 |  |  | 			normalModule.addDependency(new NullDependency()); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(normalModule.hasDependencies()).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-04-04 07:07:14 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("returns false if has dependencies", () => { | 
					
						
							|  |  |  | 			expect(normalModule.hasDependencies()).toBe(false); | 
					
						
							| 
									
										
										
										
											2017-04-04 07:07:14 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#needRebuild", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		let fileTimestamps; | 
					
						
							|  |  |  | 		let contextTimestamps; | 
					
						
							|  |  |  | 		let fileDependencies; | 
					
						
							|  |  |  | 		let contextDependencies; | 
					
						
							|  |  |  | 		let fileA; | 
					
						
							|  |  |  | 		let fileB; | 
					
						
							| 
									
										
										
										
											2017-02-14 18:47:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		function setDeps(fileDependencies, contextDependencies) { | 
					
						
							| 
									
										
										
										
											2017-12-13 04:21:02 +08:00
										 |  |  | 			normalModule.buildInfo.fileDependencies = fileDependencies; | 
					
						
							|  |  |  | 			normalModule.buildInfo.contextDependencies = contextDependencies; | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-14 18:47:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			fileA = "fileA"; | 
					
						
							|  |  |  | 			fileB = "fileB"; | 
					
						
							| 
									
										
										
										
											2017-02-14 18:47:55 +08:00
										 |  |  | 			fileDependencies = [fileA, fileB]; | 
					
						
							|  |  |  | 			contextDependencies = [fileA, fileB]; | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 			fileTimestamps = new Map([ | 
					
						
							|  |  |  | 				[fileA, 1], | 
					
						
							|  |  |  | 				[fileB, 1] | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			contextTimestamps = new Map([ | 
					
						
							|  |  |  | 				[fileA, 1], | 
					
						
							|  |  |  | 				[fileB, 1], | 
					
						
							|  |  |  | 			]); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			normalModule.buildTimestamp = 2; | 
					
						
							|  |  |  | 			setDeps(fileDependencies, contextDependencies); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given all timestamps are older than the buildTimestamp", () => { | 
					
						
							|  |  |  | 			it("returns false", () => { | 
					
						
							|  |  |  | 				expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(false); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a file timestamp is newer than the buildTimestamp", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 				fileTimestamps.set(fileA, 3); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a no file timestamp exists", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 				fileTimestamps = new Map(); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a context timestamp is newer than the buildTimestamp", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 				contextTimestamps.set(fileA, 3); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a no context timestamp exists", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2018-01-23 15:30:22 +08:00
										 |  |  | 				contextTimestamps = new Map(); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(normalModule.needRebuild(fileTimestamps, contextTimestamps)).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#splitVariablesInUniqueNamedChunks", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		let variables; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:47:55 +08:00
										 |  |  | 			variables = [{ | 
					
						
							| 
									
										
										
										
											2017-02-16 16:31:58 +08:00
										 |  |  | 				name: "foo" | 
					
						
							|  |  |  | 			}, { | 
					
						
							|  |  |  | 				name: "bar" | 
					
						
							|  |  |  | 			}, { | 
					
						
							|  |  |  | 				name: "baz" | 
					
						
							|  |  |  | 			}, { | 
					
						
							|  |  |  | 				name: "some" | 
					
						
							|  |  |  | 			}, { | 
					
						
							|  |  |  | 				name: "more" | 
					
						
							|  |  |  | 			}]; | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given an empty array of vars", () => { | 
					
						
							|  |  |  | 			it("returns an empty array", () => { | 
					
						
							|  |  |  | 				expect(normalModule.splitVariablesInUniqueNamedChunks([])).toEqual([ | 
					
						
							| 
									
										
										
										
											2017-02-16 16:31:58 +08:00
										 |  |  | 					[] | 
					
						
							|  |  |  | 				]); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given an array of distrinct variables", () => { | 
					
						
							|  |  |  | 			it("returns an array containing an array containing the variables", () => { | 
					
						
							|  |  |  | 				expect(normalModule.splitVariablesInUniqueNamedChunks(variables)).toEqual([variables]); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given an array with duplicate variables", () => { | 
					
						
							|  |  |  | 			it("returns several arrays each containing only distinct variable names", () => { | 
					
						
							|  |  |  | 				expect(normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables))).toEqual([variables, variables]); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("and a duplicate as the last variable", () => { | 
					
						
							|  |  |  | 				it("returns correctly split distinct arrays", () => { | 
					
						
							|  |  |  | 					expect(normalModule.splitVariablesInUniqueNamedChunks(variables.concat(variables).concat(variables[0]))).toEqual([variables, variables, [variables[0]]]); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#applyNoParseRule", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 		let rule; | 
					
						
							|  |  |  | 		let content; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a string as rule", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				rule = "some-rule"; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("and the content starting with the string specified in rule", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 					content = rule + "some-content"; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				it("returns true", () => { | 
					
						
							|  |  |  | 					expect(normalModule.shouldPreventParsing(rule, content)).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("and the content does not start with the string specified in rule", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 					content = "some-content"; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				it("returns false", () => { | 
					
						
							|  |  |  | 					expect(normalModule.shouldPreventParsing(rule, content)).toBe(false); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a regex as rule", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				rule = /some-rule/; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("and the content matches the rule", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 					content = rule + "some-content"; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				it("returns true", () => { | 
					
						
							|  |  |  | 					expect(normalModule.shouldPreventParsing(rule, content)).toBe(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("and the content does not match the rule", () => { | 
					
						
							|  |  |  | 				beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 					content = "some-content"; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 				it("returns false", () => { | 
					
						
							|  |  |  | 					expect(normalModule.shouldPreventParsing(rule, content)).toBe(false); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#shouldPreventParsing", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 		let applyNoParseRuleSpy; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 			applyNoParseRuleSpy = sinon.stub(); | 
					
						
							|  |  |  | 			normalModule.applyNoParseRule = applyNoParseRuleSpy; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given no noParseRule", () => { | 
					
						
							|  |  |  | 			it("returns false", () => { | 
					
						
							|  |  |  | 				expect(normalModule.shouldPreventParsing()).toBe(false); | 
					
						
							|  |  |  | 				expect(applyNoParseRuleSpy.callCount).toBe(0); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given a noParseRule", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 			let returnValOfSpy; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 				returnValOfSpy = true; | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				applyNoParseRuleSpy.returns(returnValOfSpy); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("that is a string", () => { | 
					
						
							|  |  |  | 				it("calls and returns whatever applyNoParseRule returns", () => { | 
					
						
							|  |  |  | 					expect(normalModule.shouldPreventParsing("some rule")).toBe(returnValOfSpy); | 
					
						
							|  |  |  | 					expect(applyNoParseRuleSpy.callCount).toBe(1); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("that is a regex", () => { | 
					
						
							|  |  |  | 				it("calls and returns whatever applyNoParseRule returns", () => { | 
					
						
							|  |  |  | 					expect(normalModule.shouldPreventParsing("some rule")).toBe(returnValOfSpy); | 
					
						
							|  |  |  | 					expect(applyNoParseRuleSpy.callCount).toBe(1); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("that is an array", () => { | 
					
						
							|  |  |  | 				describe("of strings and or regexs", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 					let someRules; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						someRules = [ | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 							"some rule", | 
					
						
							|  |  |  | 							/some rule1/, | 
					
						
							|  |  |  | 							"some rule2", | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						]; | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 					describe("and none of them match", () => { | 
					
						
							|  |  |  | 						beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 							returnValOfSpy = false; | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.returns(returnValOfSpy); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 						it("returns false", () => { | 
					
						
							|  |  |  | 							expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy); | 
					
						
							|  |  |  | 							expect(applyNoParseRuleSpy.callCount).toBe(3); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 					describe("and the first of them matches", () => { | 
					
						
							|  |  |  | 						beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 							returnValOfSpy = true; | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.returns(returnValOfSpy); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 						it("returns true", () => { | 
					
						
							|  |  |  | 							expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy); | 
					
						
							|  |  |  | 							expect(applyNoParseRuleSpy.callCount).toBe(1); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 					describe("and the last of them matches", () => { | 
					
						
							|  |  |  | 						beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 							returnValOfSpy = true; | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.onCall(0).returns(false); | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.onCall(1).returns(false); | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.onCall(2).returns(true); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 						it("returns true", () => { | 
					
						
							|  |  |  | 							expect(normalModule.shouldPreventParsing(someRules)).toBe(returnValOfSpy); | 
					
						
							|  |  |  | 							expect(applyNoParseRuleSpy.callCount).toBe(3); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | }); |