mirror of https://github.com/webpack/webpack.git
				
				
				
			test: stability and avoid extra output
This commit is contained in:
		
							parent
							
								
									568bb1d789
								
							
						
					
					
						commit
						9b1a25089a
					
				|  | @ -3,7 +3,7 @@ import * as style from "./style.css"; | |||
| import * as text1 from "./text-with-bom.txt"; | ||||
| import * as text2 from "./test-without-bom.text"; | ||||
| 
 | ||||
| it("should remove BOM", function() { | ||||
| it("should remove BOM", async function() { | ||||
| 	const url = new URL("./resource-with-bom.ext", import.meta.url); | ||||
| 
 | ||||
| 	expect(mod).toBeDefined(); | ||||
|  | @ -13,7 +13,7 @@ it("should remove BOM", function() { | |||
| 	expect(url).toBeDefined(); | ||||
| 
 | ||||
| 	const module = "module.js" | ||||
| 	const modules = import("./dir/" + module); | ||||
| 	const modules = await import("./dir/" + module); | ||||
| 
 | ||||
| 	expect(modules).toBeDefined(); | ||||
| }); | ||||
|  |  | |||
|  | @ -4,6 +4,9 @@ const fs = require("fs"); | |||
| const path = require("path"); | ||||
| 
 | ||||
| module.exports = { | ||||
| 	findBundle() { | ||||
| 		return ["dir_module_js.bundle0.js", "bundle0.js"]; | ||||
| 	}, | ||||
| 	afterExecute(options) { | ||||
| 		const outputPath = options.output.path; | ||||
| 		const files = fs.readdirSync(outputPath); | ||||
|  |  | |||
|  | @ -6,6 +6,9 @@ module.exports = { | |||
| 	output: { | ||||
| 		assetModuleFilename: "[name][ext]" | ||||
| 	}, | ||||
| 	optimization: { | ||||
| 		chunkIds: "named" | ||||
| 	}, | ||||
| 	module: { | ||||
| 		rules: [ | ||||
| 			{ | ||||
|  |  | |||
|  | @ -1,27 +1,40 @@ | |||
| it("should set fetchPriority", () => { | ||||
| 	import(/* webpackFetchPriority: "high" */ "./a"); | ||||
| function abortable(fn) { | ||||
| 	return new Promise((resolve) => { | ||||
| 		const timeoutId = setTimeout(() => { | ||||
| 			console.log("HERE") | ||||
| 			fn = undefined; | ||||
| 			resolve('Promise resolved after delay'); | ||||
| 			clearTimeout(timeoutId); | ||||
| 		}, 1000); | ||||
| 
 | ||||
| 		return fn(); | ||||
| 	}); | ||||
| } | ||||
| 
 | ||||
| it("should set fetchPriority", async () => { | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./a")); | ||||
| 	expect(document.head._children).toHaveLength(4); | ||||
| 	const script1 = document.head._children[2]; | ||||
| 	expect(script1._attributes.fetchpriority).toBe("high"); | ||||
| 
 | ||||
| 	import(/* webpackFetchPriority: "low" */ "./b"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./b")); | ||||
| 	expect(document.head._children).toHaveLength(5); | ||||
| 	const script2 = document.head._children[4]; | ||||
| 	expect(script2._attributes.fetchpriority).toBe("low"); | ||||
| 
 | ||||
| 	import(/* webpackFetchPriority: "low" */ "./c"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./c")); | ||||
| 	expect(document.head._children).toHaveLength(6); | ||||
| 	const script3 = document.head._children[5]; | ||||
| 	expect(script3._attributes.fetchpriority).toBe("low"); | ||||
| 
 | ||||
| 	import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c"); | ||||
| 	abortable(() => import(/* webpackPrefetch: 20, webpackFetchPriority: "auto" */ "./c")); | ||||
| 
 | ||||
| 	import("./d") | ||||
| 	abortable(() => import("./d")) | ||||
| 	expect(document.head._children).toHaveLength(7); | ||||
| 	const script4 = document.head._children[6]; | ||||
| 	expect(script4._attributes.fetchpriority).toBeUndefined(); | ||||
| 
 | ||||
| 	import(/* webpackPrefetch: -20 */ "./d3"); | ||||
| 	abortable(() => import(/* webpackPrefetch: -20 */ "./d3")); | ||||
| 	expect(document.head._children).toHaveLength(8); | ||||
| 	const script5 = document.head._children[7]; | ||||
| 	expect(script5._attributes.fetchpriority).toBeUndefined(); | ||||
|  | @ -29,12 +42,12 @@ it("should set fetchPriority", () => { | |||
| 	const condition = true; | ||||
| 
 | ||||
| 	if (!condition) { | ||||
| 		import(/* webpackFetchPriority: "high", webpackChunkName: "one" */ "./e"); | ||||
| 		abortable( () => import(/* webpackFetchPriority: "high", webpackChunkName: "one" */ "./e")); | ||||
| 		expect(document.head._children).toHaveLength(9); | ||||
| 		const script6 = document.head._children[8]; | ||||
| 		expect(script6._attributes.fetchpriority).toBe("high"); | ||||
| 	} else { | ||||
| 		import(/* webpackFetchPriority: "low", webpackChunkName: "two" */ "./e"); | ||||
| 		abortable(() => import(/* webpackFetchPriority: "low", webpackChunkName: "two" */ "./e")); | ||||
| 		expect(document.head._children).toHaveLength(9); | ||||
| 		const script6 = document.head._children[8]; | ||||
| 		expect(script6._attributes.fetchpriority).toBe("low"); | ||||
|  |  | |||
|  | @ -1,13 +1,26 @@ | |||
| function abortable(fn) { | ||||
| 	return new Promise((resolve) => { | ||||
| 		const timeoutId = setTimeout(() => { | ||||
| 			console.log("HERE") | ||||
| 			fn = undefined; | ||||
| 			resolve('Promise resolved after delay'); | ||||
| 			clearTimeout(timeoutId); | ||||
| 		}, 1000); | ||||
| 
 | ||||
| 		return fn(); | ||||
| 	}); | ||||
| } | ||||
| 
 | ||||
| it("should set fetchPriority", () => { | ||||
| 	// Single Chunk
 | ||||
| 	import(/* webpackFetchPriority: "high" */ "./a"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./a")); | ||||
| 	expect(document.head._children).toHaveLength(1); | ||||
| 	const script1 = document.head._children[0]; | ||||
| 	expect(script1._attributes.fetchpriority).toBe("high"); | ||||
| 
 | ||||
| 	// Multiple Chunks
 | ||||
| 	import(/* webpackFetchPriority: "high" */ "./b"); | ||||
| 	import(/* webpackFetchPriority: "high" */ "./b2"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./b")); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./b2")); | ||||
| 	expect(document.head._children).toHaveLength(4); | ||||
| 	const script2 = document.head._children[1]; | ||||
| 	const script3 = document.head._children[2]; | ||||
|  | @ -17,19 +30,19 @@ it("should set fetchPriority", () => { | |||
| 	expect(script4._attributes.fetchpriority).toBe("high"); | ||||
| 
 | ||||
| 	// Single Chunk, low
 | ||||
| 	import(/* webpackFetchPriority: "low" */ "./c"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./c")); | ||||
| 	expect(document.head._children).toHaveLength(5); | ||||
| 	const script5 = document.head._children[4]; | ||||
| 	expect(script5._attributes.fetchpriority).toBe("low"); | ||||
| 
 | ||||
| 	// Single Chunk, auto
 | ||||
| 	import(/* webpackFetchPriority: "auto" */ "./d"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "auto" */ "./d")); | ||||
| 	expect(document.head._children).toHaveLength(6); | ||||
| 	const script6 = document.head._children[5]; | ||||
| 	expect(script6._attributes.fetchpriority).toBe("auto"); | ||||
| 
 | ||||
| 	// No fetch priority
 | ||||
| 	import("./e"); | ||||
| 	abortable(() => import("./e")); | ||||
| 	expect(document.head._children).toHaveLength(7); | ||||
| 	const script7 = document.head._children[6]; | ||||
| 	expect(script7._attributes.fetchpriority).toBeUndefined(); | ||||
|  | @ -44,49 +57,49 @@ it("should set fetchPriority", () => { | |||
| 	const script8 = document.head._children[7]; | ||||
| 	expect(script8._attributes.fetchpriority).toBeUndefined(); | ||||
| 
 | ||||
| 	import(/* webpackFetchPriority: "auto" */ "./g"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "auto" */ "./g")); | ||||
| 	expect(document.head._children).toHaveLength(9); | ||||
| 	const script9 = document.head._children[8]; | ||||
| 	expect(script9._attributes.fetchpriority).toBe("auto"); | ||||
| 
 | ||||
| 	import(/* webpackFetchPriority: "unknown" */ "./h.js"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "unknown" */ "./h.js")); | ||||
| 	expect(document.head._children).toHaveLength(10); | ||||
| 	const script10 = document.head._children[9]; | ||||
| 	expect(script10._attributes.fetchpriority).toBeUndefined(); | ||||
| 
 | ||||
| 	import(/* webpackFetchPriority: "high" */ "./i"); | ||||
| 	import(/* webpackFetchPriority: "low" */ "./i"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./i")); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./i")); | ||||
| 	expect(document.head._children).toHaveLength(11); | ||||
| 	const script11 = document.head._children[10]; | ||||
| 	expect(script11._attributes.fetchpriority).toBe("high"); | ||||
| 
 | ||||
| 	import(/* webpackFetchPriority: "low" */ "./j"); | ||||
| 	import(/* webpackFetchPriority: "high" */ "./j"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./j")); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./j")); | ||||
| 	expect(document.head._children).toHaveLength(12); | ||||
| 	const script12 = document.head._children[11]; | ||||
| 
 | ||||
| 	expect(script12._attributes.fetchpriority).toBe("low"); | ||||
| 	import(/* webpackFetchPriority: "low" */ "./k"); | ||||
| 	import("./e"); | ||||
| 	import(/* webpackFetchPriority: "high" */ "./k"); | ||||
| 	expect(document.head._children).toHaveLength(13); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./k")); | ||||
| 	abortable(() => import("./e")); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./k")); | ||||
| 	abortable(() => expect(document.head._children).toHaveLength(13)); | ||||
| 	const script13 = document.head._children[12]; | ||||
| 	expect(script13._attributes.fetchpriority).toBe("low"); | ||||
| 
 | ||||
| 	__non_webpack_require__("./125.js"); | ||||
| 	import(/* webpackFetchPriority: "high" */ "./style.css"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "high" */ "./style.css")); | ||||
| 	expect(document.head._children).toHaveLength(14); | ||||
| 	const link1 = document.head._children[13]; | ||||
| 	expect(link1._attributes.fetchpriority).toBe("high"); | ||||
| 
 | ||||
| 	__non_webpack_require__("./499.js"); | ||||
| 	import("./style-1.css"); | ||||
| 	abortable(() => import("./style-1.css")); | ||||
| 	expect(document.head._children).toHaveLength(15); | ||||
| 	const link2 = document.head._children[14]; | ||||
| 	expect(link2._attributes.fetchpriority).toBeUndefined(); | ||||
| 
 | ||||
| 	__non_webpack_require__("./616.js"); | ||||
| 	import(/* webpackFetchPriority: "low" */ "./style-2.css"); | ||||
| 	abortable(() => import(/* webpackFetchPriority: "low" */ "./style-2.css")); | ||||
| 	expect(document.head._children).toHaveLength(16); | ||||
| 	const link3 = document.head._children[15]; | ||||
| 	expect(link3._attributes.fetchpriority).toBe("low"); | ||||
|  |  | |||
|  | @ -17,7 +17,7 @@ module.exports = { | |||
| 		] | ||||
| 	}, | ||||
| 	plugins: [ | ||||
| 		new webpack.ProgressPlugin(), | ||||
| 		new webpack.ProgressPlugin(() => {}), | ||||
| 		{ | ||||
| 			apply(compiler) { | ||||
| 				compiler.hooks.done.tapPromise("CacheTest", async () => { | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ module.exports = { | |||
| 		] | ||||
| 	}, | ||||
| 	plugins: [ | ||||
| 		new webpack.ProgressPlugin(), | ||||
| 		new webpack.ProgressPlugin(() => {}), | ||||
| 		{ | ||||
| 			apply(compiler) { | ||||
| 				compiler.hooks.done.tapPromise("CacheTest", async () => { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue