| 
									
										
										
										
											2017-02-19 10:44:42 +08:00
										 |  |  | /* globals describe, it, beforeEach */ | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | const ExternalModule = require("../lib/ExternalModule"); | 
					
						
							|  |  |  | const OriginalSource = require("webpack-sources").OriginalSource; | 
					
						
							|  |  |  | const RawSource = require("webpack-sources").RawSource; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | describe("ExternalModule", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 	let externalModule; | 
					
						
							|  |  |  | 	let request; | 
					
						
							|  |  |  | 	let type; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		request = "some/request"; | 
					
						
							|  |  |  | 		type = "some-type"; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 		externalModule = new ExternalModule(request, type, `${type} ${request}`); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#identifier", () => { | 
					
						
							|  |  |  | 		it("returns an identifier for this module", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			const expected = `external "${request}"`; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(externalModule.identifier()).toBe(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#readableIdentifier", () => { | 
					
						
							|  |  |  | 		it("returns an identifier for this module", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			const expected = `external "${request}"`; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(externalModule.identifier()).toBe(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#needRebuild", () => { | 
					
						
							|  |  |  | 		it("always returns false", () => { | 
					
						
							|  |  |  | 			expect(externalModule.needRebuild()).toBe(false); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#size", () => { | 
					
						
							|  |  |  | 		it("always returns 42", () => { | 
					
						
							|  |  |  | 			expect(externalModule.size()).toBe(42); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#source", () => { | 
					
						
							|  |  |  | 		it("calls getSource with the result of getSourceString", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			// set up
 | 
					
						
							|  |  |  | 			const expectedString = "something expected stringy"; | 
					
						
							| 
									
										
										
										
											2018-02-26 10:48:26 +08:00
										 |  |  | 			const expectedSource = "something expected source"; | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			externalModule.getSource = jest.fn(() => expectedSource); | 
					
						
							|  |  |  | 			externalModule.getSourceString = jest.fn(() => expectedString); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// invoke
 | 
					
						
							|  |  |  | 			const result = externalModule.source(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// check
 | 
					
						
							| 
									
										
										
										
											2018-05-07 21:26:04 +08:00
										 |  |  | 			expect(externalModule.getSource.mock.calls.length).toBe(1); | 
					
						
							|  |  |  | 			expect(externalModule.getSourceString.mock.calls.length).toBe(1); | 
					
						
							|  |  |  | 			expect(externalModule.getSource.mock.calls[0][0]).toBe(expectedString); | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 			expect(result).toEqual(expectedSource); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#getSource", () => { | 
					
						
							|  |  |  | 		describe("given it should use source maps", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				externalModule.useSourceMap = true; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns an instance of OriginalSource", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const someSourceString = "some source string"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							|  |  |  | 				const result = externalModule.getSource(someSourceString); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 23:34:38 +08:00
										 |  |  | 				expect(result).toBeInstanceOf(OriginalSource); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given it does not use source maps", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				externalModule.useSourceMap = false; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns an instance of RawSource", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const someSourceString = "some source string"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							|  |  |  | 				const result = externalModule.getSource(someSourceString); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 23:34:38 +08:00
										 |  |  | 				expect(result).toBeInstanceOf(RawSource); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#getSourceForGlobalVariableExternal", () => { | 
					
						
							|  |  |  | 		describe("given an array as variable name in the global namespace", () => { | 
					
						
							|  |  |  | 			it("use the array as lookup in the global object", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const type = "window"; | 
					
						
							|  |  |  | 				const varName = ["foo", "bar"]; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const expected = | 
					
						
							|  |  |  | 					'(function() { module.exports = window["foo"]["bar"]; }());'; | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const result = externalModule.getSourceForGlobalVariableExternal( | 
					
						
							|  |  |  | 					varName, | 
					
						
							|  |  |  | 					type | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 				expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given an single variable name", () => { | 
					
						
							|  |  |  | 			it("look it up in the global namespace", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const type = "window"; | 
					
						
							|  |  |  | 				const varName = "foo"; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const expected = '(function() { module.exports = window["foo"]; }());'; | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const result = externalModule.getSourceForGlobalVariableExternal( | 
					
						
							|  |  |  | 					varName, | 
					
						
							|  |  |  | 					type | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 				expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#getSourceForCommonJsExternal", () => { | 
					
						
							|  |  |  | 		describe("given an array as names in the global namespace", () => { | 
					
						
							|  |  |  | 			it("use the first to require a module and the rest as lookup on the required module", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const varName = ["module", "look", "up"]; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const expected = 'module.exports = require(module)["look"]["up"];'; | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const result = externalModule.getSourceForCommonJsExternal( | 
					
						
							|  |  |  | 					varName, | 
					
						
							|  |  |  | 					type | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 				expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		describe("given an single variable name", () => { | 
					
						
							|  |  |  | 			it("require a module with that name", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const type = "window"; | 
					
						
							|  |  |  | 				const varName = "foo"; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const expected = 'module.exports = require("foo");'; | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const result = externalModule.getSourceForCommonJsExternal( | 
					
						
							|  |  |  | 					varName, | 
					
						
							|  |  |  | 					type | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 				expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#checkExternalVariable", () => { | 
					
						
							|  |  |  | 		it("creates a check that fails if a variable does not exist", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 			// set up
 | 
					
						
							|  |  |  | 			const variableToCheck = "foo"; | 
					
						
							|  |  |  | 			const request = "bar"; | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 			const expected = `if(typeof foo === 'undefined') {var e = new Error("Cannot find module 'bar'"); e.code = 'MODULE_NOT_FOUND'; throw e;}
 | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | `;
 | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			const result = externalModule.checkExternalVariable( | 
					
						
							|  |  |  | 				variableToCheck, | 
					
						
							|  |  |  | 				request | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 			expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#getSourceForAmdOrUmdExternal", () => { | 
					
						
							|  |  |  | 		it("looks up a global variable as specified by the id", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 			// set up
 | 
					
						
							|  |  |  | 			const id = "someId"; | 
					
						
							|  |  |  | 			const optional = false; | 
					
						
							|  |  |  | 			const expected = "module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			const result = externalModule.getSourceForAmdOrUmdExternal( | 
					
						
							|  |  |  | 				id, | 
					
						
							|  |  |  | 				optional, | 
					
						
							|  |  |  | 				request | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 			expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-26 10:36:27 +08:00
										 |  |  | 		describe("given an optional check is set", function() { | 
					
						
							| 
									
										
										
										
											2018-03-08 04:56:06 +08:00
										 |  |  | 			it("ads a check for the existence of the variable before looking it up", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const id = "someId"; | 
					
						
							|  |  |  | 				const optional = true; | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 				const expected = `if(typeof __WEBPACK_EXTERNAL_MODULE_someId__ === 'undefined') {var e = new Error("Cannot find module 'some/request'"); e.code = 'MODULE_NOT_FOUND'; throw e;}
 | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | module.exports = __WEBPACK_EXTERNAL_MODULE_someId__;`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const result = externalModule.getSourceForAmdOrUmdExternal( | 
					
						
							|  |  |  | 					id, | 
					
						
							|  |  |  | 					optional, | 
					
						
							|  |  |  | 					request | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 				expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#getSourceForDefaultCase", () => { | 
					
						
							|  |  |  | 		it("returns the given request as lookup", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 			// set up
 | 
					
						
							|  |  |  | 			const optional = false; | 
					
						
							|  |  |  | 			const expected = "module.exports = some/request;"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// invoke
 | 
					
						
							|  |  |  | 			const result = externalModule.getSourceForDefaultCase(optional, request); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 			expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-02-26 10:36:27 +08:00
										 |  |  | 		describe("given an optional check is requested", function() { | 
					
						
							| 
									
										
										
										
											2018-03-08 04:56:06 +08:00
										 |  |  | 			it("checks for the existence of the request setting it", () => { | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 				// set up
 | 
					
						
							|  |  |  | 				const optional = true; | 
					
						
							| 
									
										
										
										
											2018-05-15 14:16:39 +08:00
										 |  |  | 				const expected = `if(typeof some/request === 'undefined') {var e = new Error("Cannot find module 'some/request'"); e.code = 'MODULE_NOT_FOUND'; throw e;}
 | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | module.exports = some/request;`;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// invoke
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				const result = externalModule.getSourceForDefaultCase( | 
					
						
							|  |  |  | 					optional, | 
					
						
							|  |  |  | 					request | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// check
 | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 				expect(result).toEqual(expected); | 
					
						
							| 
									
										
										
										
											2017-02-19 09:11:08 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-02-19 10:44:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#updateHash", () => { | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 		let hashedText; | 
					
						
							|  |  |  | 		let hash; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 			hashedText = ""; | 
					
						
							|  |  |  | 			hash = { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				update: text => { | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 					hashedText += text; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2017-09-18 15:34:13 +08:00
										 |  |  | 			externalModule.id = 12345678; | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 			externalModule.updateHash(hash); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with request", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("some/request"); | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with type", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("some-type"); | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with module id", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("12345678"); | 
					
						
							| 
									
										
										
										
											2017-09-18 15:34:13 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-18 00:18:40 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	describe("#updateHash without optional", () => { | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 		let hashedText; | 
					
						
							|  |  |  | 		let hash; | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 			hashedText = ""; | 
					
						
							|  |  |  | 			hash = { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				update: text => { | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 					hashedText += text; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			// Note no set of `externalModule.optional`, which crashed externals in 3.7.0
 | 
					
						
							|  |  |  | 			externalModule.id = 12345678; | 
					
						
							|  |  |  | 			externalModule.updateHash(hash); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with request", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("some/request"); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with type", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("some-type"); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with optional flag", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("false"); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("updates hash with module id", () => { | 
					
						
							|  |  |  | 			expect(hashedText).toMatch("12345678"); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:53:12 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-02-19 08:55:07 +08:00
										 |  |  | }); |