| 
									
										
										
										
											2020-08-11 20:42:32 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const extractUrlAndGlobal = require("../lib/util/extractUrlAndGlobal"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("extractUrlAndGlobal", () => { | 
					
						
							|  |  |  | 	it("should return jQuery", () => { | 
					
						
							|  |  |  | 		const result = extractUrlAndGlobal( | 
					
						
							|  |  |  | 			"jQuery@https://code.jquery.com/jquery-3.5.1.min.js" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		expect(result).toEqual([ | 
					
						
							|  |  |  | 			"https://code.jquery.com/jquery-3.5.1.min.js", | 
					
						
							|  |  |  | 			"jQuery" | 
					
						
							|  |  |  | 		]); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 20:42:32 +08:00
										 |  |  | 	it("should return _", () => { | 
					
						
							|  |  |  | 		const result = extractUrlAndGlobal( | 
					
						
							|  |  |  | 			"_@https://cdn.jsdelivr.net/npm/lodash@4.17.19/lodash.min.js" | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		expect(result).toEqual([ | 
					
						
							|  |  |  | 			"https://cdn.jsdelivr.net/npm/lodash@4.17.19/lodash.min.js", | 
					
						
							|  |  |  | 			"_" | 
					
						
							|  |  |  | 		]); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-28 18:08:25 +08:00
										 |  |  | 	it("should throw error if starts with @", () => { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		expect(() => extractUrlAndGlobal("@something")).toThrow( | 
					
						
							|  |  |  | 			/Invalid request "@something"/ | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-11-28 18:08:25 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it("should throw error if ends with @", () => { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		expect(() => extractUrlAndGlobal("something@")).toThrow( | 
					
						
							|  |  |  | 			/Invalid request "something@"/ | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-11-28 18:08:25 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it("should throw error if do not have @", () => { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 		expect(() => extractUrlAndGlobal("something")).toThrow( | 
					
						
							|  |  |  | 			/Invalid request "something"/ | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-11-28 18:08:25 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2020-08-11 20:42:32 +08:00
										 |  |  | }); |