| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | const NormalModule = require("../lib/NormalModule"); | 
					
						
							|  |  |  | 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(() => { | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 		request = "/some/request"; | 
					
						
							|  |  |  | 		userRequest = "/some/userRequest"; | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		rawRequest = "some/rawRequest"; | 
					
						
							|  |  |  | 		loaders = []; | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 		resource = "/some/resource"; | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		parser = { | 
					
						
							| 
									
										
										
										
											2017-02-16 05:01:09 +08:00
										 |  |  | 			parse() {} | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 		normalModule = new NormalModule({ | 
					
						
							|  |  |  | 			type: "javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			request, | 
					
						
							|  |  |  | 			userRequest, | 
					
						
							|  |  |  | 			rawRequest, | 
					
						
							|  |  |  | 			loaders, | 
					
						
							|  |  |  | 			resource, | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 			parser, | 
					
						
							|  |  |  | 			generator: null, | 
					
						
							|  |  |  | 			resolveOptions: {} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-13 04:21:02 +08:00
										 |  |  | 		normalModule.buildInfo = { | 
					
						
							|  |  |  | 			cacheable: true | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  | 		normalModule.useSimpleSourceMap = 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-08-28 17:50:33 +08:00
										 |  |  | 			expect(normalModule.toString()).toBe("Module[1000: /some/request]"); | 
					
						
							| 
									
										
										
										
											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", () => { | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			const spy = jest.fn(); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			normalModule.readableIdentifier({ | 
					
						
							|  |  |  | 				shorten: spy | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			expect(spy.mock.calls.length).toBe(1); | 
					
						
							|  |  |  | 			expect(spy.mock.calls[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", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			expect( | 
					
						
							|  |  |  | 				normalModule.libIdent({ | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 					context: "/some/context" | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +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(() => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				userRequest = | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 					"/some/userRequest!/some/other/userRequest!/some/thing/is/off/here"; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 				normalModule = new NormalModule({ | 
					
						
							|  |  |  | 					type: "javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					userRequest, | 
					
						
							|  |  |  | 					rawRequest, | 
					
						
							|  |  |  | 					loaders, | 
					
						
							|  |  |  | 					resource, | 
					
						
							|  |  |  | 					parser | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("contextifies every path in the userRequest", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				expect( | 
					
						
							|  |  |  | 					normalModule.libIdent({ | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 						context: "/some/context" | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +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", () => { | 
					
						
							| 
									
										
										
										
											2022-01-18 17:38:06 +08:00
										 |  |  | 				// cspell:word testpath
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				userRequest = | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 					"F:\\some\\context\\loader?query=foo\\bar&otherPath=testpath/other"; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 				normalModule = new NormalModule({ | 
					
						
							|  |  |  | 					type: "javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-08-30 05:50:22 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					userRequest, | 
					
						
							|  |  |  | 					rawRequest, | 
					
						
							|  |  |  | 					loaders, | 
					
						
							|  |  |  | 					resource, | 
					
						
							|  |  |  | 					parser | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				expect( | 
					
						
							|  |  |  | 					normalModule.libIdent({ | 
					
						
							| 
									
										
										
										
											2018-06-01 20:54:54 +08:00
										 |  |  | 						context: "F:\\some\\context" | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +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"; | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 				normalModule = new NormalModule({ | 
					
						
							|  |  |  | 					type: "javascript/auto", | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 					request, | 
					
						
							|  |  |  | 					userRequest, | 
					
						
							|  |  |  | 					rawRequest, | 
					
						
							|  |  |  | 					loaders, | 
					
						
							|  |  |  | 					resource, | 
					
						
							|  |  |  | 					parser | 
					
						
							| 
									
										
										
										
											2018-01-24 06:09:26 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											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", () => { | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 				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", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				expect( | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 					normalModule.createSourceForAsset("/", name, content, sourceMap) | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				).toBeInstanceOf(OriginalSource); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  | 		describe("given a some other kind of sourcemap (source maps disabled)", () => { | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 				sourceMap = () => {}; | 
					
						
							| 
									
										
										
										
											2020-10-26 21:41:46 +08:00
										 |  |  | 				normalModule.useSimpleSourceMap = false; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			it("returns a SourceMapSource", () => { | 
					
						
							|  |  |  | 				expect( | 
					
						
							|  |  |  | 					normalModule.createSourceForAsset("/", name, content, sourceMap) | 
					
						
							|  |  |  | 				).toBeInstanceOf(RawSource); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		describe("given a some other kind of sourcemap (simple source maps enabled)", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				sourceMap = () => {}; | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			it("returns a SourceMapSource", () => { | 
					
						
							|  |  |  | 				expect( | 
					
						
							|  |  |  | 					normalModule.createSourceForAsset("/", name, content, sourceMap) | 
					
						
							|  |  |  | 				).toBeInstanceOf(RawSource); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		describe("given a some other kind of sourcemap (source maps enabled)", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							|  |  |  | 				sourceMap = () => {}; | 
					
						
							|  |  |  | 				normalModule.useSourceMap = true; | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns a SourceMapSource", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				expect( | 
					
						
							| 
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 |  |  | 					normalModule.createSourceForAsset("/", name, content, sourceMap) | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				).toBeInstanceOf(SourceMapSource); | 
					
						
							| 
									
										
										
										
											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("#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(() => { | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			applyNoParseRuleSpy = jest.fn(); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 			normalModule.applyNoParseRule = applyNoParseRuleSpy; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given no noParseRule", () => { | 
					
						
							|  |  |  | 			it("returns false", () => { | 
					
						
							|  |  |  | 				expect(normalModule.shouldPreventParsing()).toBe(false); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 				expect(applyNoParseRuleSpy.mock.calls.length).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; | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 				applyNoParseRuleSpy.mockReturnValue(returnValOfSpy); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("that is a string", () => { | 
					
						
							|  |  |  | 				it("calls and returns whatever applyNoParseRule returns", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 					expect(normalModule.shouldPreventParsing("some rule")).toBe( | 
					
						
							|  |  |  | 						returnValOfSpy | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 					expect(applyNoParseRuleSpy.mock.calls.length).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", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 					expect(normalModule.shouldPreventParsing("some rule")).toBe( | 
					
						
							|  |  |  | 						returnValOfSpy | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 					expect(applyNoParseRuleSpy.mock.calls.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			describe("that is an array", () => { | 
					
						
							| 
									
										
										
										
											2022-01-18 17:38:06 +08:00
										 |  |  | 				describe("of strings and or regexps", () => { | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 					let someRules; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 					beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 						someRules = ["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; | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 							applyNoParseRuleSpy.mockReturnValue(returnValOfSpy); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 						it("returns false", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 							expect(normalModule.shouldPreventParsing(someRules)).toBe( | 
					
						
							|  |  |  | 								returnValOfSpy | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 							expect(applyNoParseRuleSpy.mock.calls.length).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; | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 							applyNoParseRuleSpy.mockReturnValue(returnValOfSpy); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 						it("returns true", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 							expect(normalModule.shouldPreventParsing(someRules)).toBe( | 
					
						
							|  |  |  | 								returnValOfSpy | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 							expect(applyNoParseRuleSpy.mock.calls.length).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; | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 							applyNoParseRuleSpy.mockReturnValueOnce(false); | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.mockReturnValueOnce(false); | 
					
						
							|  |  |  | 							applyNoParseRuleSpy.mockReturnValue(true); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 						it("returns true", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 							expect(normalModule.shouldPreventParsing(someRules)).toBe( | 
					
						
							|  |  |  | 								returnValOfSpy | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 							expect(applyNoParseRuleSpy.mock.calls.length).toBe(3); | 
					
						
							| 
									
										
										
										
											2017-02-14 18:14:57 +08:00
										 |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-02-14 17:38:47 +08:00
										 |  |  | }); |