mirror of https://github.com/webpack/webpack.git
				
				
				
			add test case
This commit is contained in:
		
							parent
							
								
									403057c76c
								
							
						
					
					
						commit
						2ec870f139
					
				|  | @ -1,7 +1,42 @@ | ||||||
| const { describeCases } = require("./ConfigTestCases.template"); | const { describeCases, logErrors } = require("./ConfigTestCases.template"); | ||||||
| 
 | 
 | ||||||
| describeCases({ | describeCases({ | ||||||
| 	name: "ConfigCacheTestCases", | 	name: "ConfigCacheTestCases", | ||||||
|  | 	infrastructureLogErrors: { | ||||||
|  | 		allowList: [ | ||||||
|  | 			{ | ||||||
|  | 				//  Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/configCases/wasm/missing-wasm-experiment/wasm.wasm
 | ||||||
|  | 				category: "wasm", | ||||||
|  | 				test: "missing-wasm-experiment" | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				//  Pack got invalid because of write to: RealContentHashPlugin|analyse|index.html
 | ||||||
|  | 				category: "process-assets", | ||||||
|  | 				test: "html-plugin" | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				//  Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/cases/parsing/context/templates/dump-file.txt
 | ||||||
|  | 				category: "parsing", | ||||||
|  | 				test: "context" | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				// Pack got invalid because of write to: Compilation/modules|/home/runner/work/webpack/webpack/test/configCases/loaders/options/loader-1.js??ruleSet[1].rules[9]!/home/runner/work/webpack/webpack/test/configCases/loaders/options/error1.js
 | ||||||
|  | 				category: "loaders", | ||||||
|  | 				test: "options" | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				// Pack got invalid because of write to: TerserWebpackPlugin|bundle0.js
 | ||||||
|  | 				category: "assets", | ||||||
|  | 				test: "delete-asset" | ||||||
|  | 			}, | ||||||
|  | 			{ | ||||||
|  | 				// Pack got invalid because of write to: webpack.HttpUriPlugin|https://raw.githubusercontent.com//webpack//webpack//main/CODE_OF_CONDUCT.md
 | ||||||
|  | 				category: "asset-modules", | ||||||
|  | 				test: "http-url" | ||||||
|  | 			} | ||||||
|  | 		], | ||||||
|  | 		filter: [logErrors.PERSISTENCE_CACHE_INVALIDATE_ERROR] | ||||||
|  | 	}, | ||||||
| 	cache: { | 	cache: { | ||||||
| 		type: "filesystem", | 		type: "filesystem", | ||||||
| 		buildDependencies: { | 		buildDependencies: { | ||||||
|  |  | ||||||
|  | @ -18,6 +18,17 @@ const { parseResource } = require("../lib/util/identifier"); | ||||||
| const captureStdio = require("./helpers/captureStdio"); | const captureStdio = require("./helpers/captureStdio"); | ||||||
| const asModule = require("./helpers/asModule"); | const asModule = require("./helpers/asModule"); | ||||||
| 
 | 
 | ||||||
|  | const PERSISTENCE_CACHE_INVALIDATE_ERROR = (log, config) => { | ||||||
|  | 	if (config.run < 2) return; | ||||||
|  | 	const match = | ||||||
|  | 		/^\[webpack\.cache\.PackFileCacheStrategy\] Pack got invalid because of write to:(.+)$/.exec( | ||||||
|  | 			log | ||||||
|  | 		); | ||||||
|  | 	if (match) { | ||||||
|  | 		return `Pack got invalid because of write to: ${match[1].trim()}`; | ||||||
|  | 	} | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| const casesPath = path.join(__dirname, "configCases"); | const casesPath = path.join(__dirname, "configCases"); | ||||||
| const categories = fs.readdirSync(casesPath).map(cat => { | const categories = fs.readdirSync(casesPath).map(cat => { | ||||||
| 	return { | 	return { | ||||||
|  | @ -29,7 +40,53 @@ const categories = fs.readdirSync(casesPath).map(cat => { | ||||||
| 	}; | 	}; | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | const createLogger = appendTarget => { | ||||||
|  | 	return { | ||||||
|  | 		log: l => appendTarget.push(l), | ||||||
|  | 		debug: l => appendTarget.push(l), | ||||||
|  | 		trace: l => appendTarget.push(l), | ||||||
|  | 		info: l => appendTarget.push(l), | ||||||
|  | 		warn: console.warn.bind(console), | ||||||
|  | 		error: console.error.bind(console), | ||||||
|  | 		logTime: () => {}, | ||||||
|  | 		group: () => {}, | ||||||
|  | 		groupCollapsed: () => {}, | ||||||
|  | 		groupEnd: () => {}, | ||||||
|  | 		profile: () => {}, | ||||||
|  | 		profileEnd: () => {}, | ||||||
|  | 		clear: () => {}, | ||||||
|  | 		status: () => {} | ||||||
|  | 	}; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | const returnLogError = (logs, errorsFilter, config) => { | ||||||
|  | 	for (const log of logs) { | ||||||
|  | 		for (const filter of errorsFilter) { | ||||||
|  | 			const result = filter(log, config); | ||||||
|  | 			if (result) { | ||||||
|  | 				return new Error(result); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| const describeCases = config => { | const describeCases = config => { | ||||||
|  | 	let allowErrorsMap; | ||||||
|  | 	if (config.infrastructureLogErrors) { | ||||||
|  | 		allowErrorsMap = new Map(); | ||||||
|  | 		if (config.infrastructureLogErrors.allowList) { | ||||||
|  | 			for (const { category, test } of config.infrastructureLogErrors | ||||||
|  | 				.allowList) { | ||||||
|  | 				let byCategory = allowErrorsMap.get(category); | ||||||
|  | 				if (!byCategory) { | ||||||
|  | 					byCategory = new Set(); | ||||||
|  | 					allowErrorsMap.set(category, byCategory); | ||||||
|  | 				} | ||||||
|  | 				byCategory.add(test); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	describe(config.name, () => { | 	describe(config.name, () => { | ||||||
| 		let stderr; | 		let stderr; | ||||||
| 		beforeEach(() => { | 		beforeEach(() => { | ||||||
|  | @ -44,6 +101,11 @@ const describeCases = config => { | ||||||
| 			// eslint-disable-next-line no-loop-func
 | 			// eslint-disable-next-line no-loop-func
 | ||||||
| 			describe(category.name, () => { | 			describe(category.name, () => { | ||||||
| 				for (const testName of category.tests) { | 				for (const testName of category.tests) { | ||||||
|  | 					const inAllowErrorsList = () => { | ||||||
|  | 						const byCategory = allowErrorsMap.get(category.name); | ||||||
|  | 						if (!byCategory) return false; | ||||||
|  | 						return byCategory.has(testName); | ||||||
|  | 					}; | ||||||
| 					// eslint-disable-next-line no-loop-func
 | 					// eslint-disable-next-line no-loop-func
 | ||||||
| 					describe(testName, function () { | 					describe(testName, function () { | ||||||
| 						const testDirectory = path.join(casesPath, category.name, testName); | 						const testDirectory = path.join(casesPath, category.name, testName); | ||||||
|  | @ -54,6 +116,7 @@ const describeCases = config => { | ||||||
| 							}); | 							}); | ||||||
| 							return; | 							return; | ||||||
| 						} | 						} | ||||||
|  | 						const infraStructureLog = []; | ||||||
| 						const outBaseDir = path.join(__dirname, "js"); | 						const outBaseDir = path.join(__dirname, "js"); | ||||||
| 						const testSubPath = path.join(config.name, category.name, testName); | 						const testSubPath = path.join(config.name, category.name, testName); | ||||||
| 						const outputDirectory = path.join(outBaseDir, testSubPath); | 						const outputDirectory = path.join(outBaseDir, testSubPath); | ||||||
|  | @ -97,6 +160,10 @@ const describeCases = config => { | ||||||
| 										name: `config-${idx}`, | 										name: `config-${idx}`, | ||||||
| 										...config.cache | 										...config.cache | ||||||
| 									}; | 									}; | ||||||
|  | 									options.infrastructureLogging = { | ||||||
|  | 										debug: true, | ||||||
|  | 										console: createLogger(infraStructureLog) | ||||||
|  | 									}; | ||||||
| 								} | 								} | ||||||
| 								if (!options.snapshot) options.snapshot = {}; | 								if (!options.snapshot) options.snapshot = {}; | ||||||
| 								if (!options.snapshot.managedPaths) { | 								if (!options.snapshot.managedPaths) { | ||||||
|  | @ -168,6 +235,7 @@ const describeCases = config => { | ||||||
| 							it(`${testName} should pre-compile to fill disk cache (1st)`, done => { | 							it(`${testName} should pre-compile to fill disk cache (1st)`, done => { | ||||||
| 								rimraf.sync(outputDirectory); | 								rimraf.sync(outputDirectory); | ||||||
| 								fs.mkdirSync(outputDirectory, { recursive: true }); | 								fs.mkdirSync(outputDirectory, { recursive: true }); | ||||||
|  | 								infraStructureLog.length = 0; | ||||||
| 								const deprecationTracker = deprecationTracking.start(); | 								const deprecationTracker = deprecationTracking.start(); | ||||||
| 								require("..")(options, err => { | 								require("..")(options, err => { | ||||||
| 									deprecationTracker(); | 									deprecationTracker(); | ||||||
|  | @ -180,6 +248,21 @@ const describeCases = config => { | ||||||
| 											) | 											) | ||||||
| 										); | 										); | ||||||
| 									} | 									} | ||||||
|  | 									if (config.infrastructureLogErrors) { | ||||||
|  | 										if (!inAllowErrorsList()) { | ||||||
|  | 											const error = returnLogError( | ||||||
|  | 												infraStructureLog, | ||||||
|  | 												Array.isArray(config.infrastructureLogErrors.filter) | ||||||
|  | 													? config.infrastructureLogErrors.filter | ||||||
|  | 													: [config.infrastructureLogErrors.filter], | ||||||
|  | 												{ | ||||||
|  | 													run: 1, | ||||||
|  | 													options | ||||||
|  | 												} | ||||||
|  | 											); | ||||||
|  | 											if (error) return done(error); | ||||||
|  | 										} | ||||||
|  | 									} | ||||||
| 									if (err) return handleFatalError(err, done); | 									if (err) return handleFatalError(err, done); | ||||||
| 									done(); | 									done(); | ||||||
| 								}); | 								}); | ||||||
|  | @ -187,6 +270,7 @@ const describeCases = config => { | ||||||
| 							it(`${testName} should pre-compile to fill disk cache (2nd)`, done => { | 							it(`${testName} should pre-compile to fill disk cache (2nd)`, done => { | ||||||
| 								rimraf.sync(outputDirectory); | 								rimraf.sync(outputDirectory); | ||||||
| 								fs.mkdirSync(outputDirectory, { recursive: true }); | 								fs.mkdirSync(outputDirectory, { recursive: true }); | ||||||
|  | 								infraStructureLog.length = 0; | ||||||
| 								const deprecationTracker = deprecationTracking.start(); | 								const deprecationTracker = deprecationTracking.start(); | ||||||
| 								require("..")(options, (err, stats) => { | 								require("..")(options, (err, stats) => { | ||||||
| 									deprecationTracker(); | 									deprecationTracker(); | ||||||
|  | @ -228,6 +312,21 @@ const describeCases = config => { | ||||||
| 											); | 											); | ||||||
| 										} | 										} | ||||||
| 									} | 									} | ||||||
|  | 									if (config.infrastructureLogErrors) { | ||||||
|  | 										if (!inAllowErrorsList()) { | ||||||
|  | 											const error = returnLogError( | ||||||
|  | 												infraStructureLog, | ||||||
|  | 												Array.isArray(config.infrastructureLogErrors.filter) | ||||||
|  | 													? config.infrastructureLogErrors.filter | ||||||
|  | 													: [config.infrastructureLogErrors.filter], | ||||||
|  | 												{ | ||||||
|  | 													run: 2, | ||||||
|  | 													options | ||||||
|  | 												} | ||||||
|  | 											); | ||||||
|  | 											if (error) return done(error); | ||||||
|  | 										} | ||||||
|  | 									} | ||||||
| 									done(); | 									done(); | ||||||
| 								}); | 								}); | ||||||
| 							}, 40000); | 							}, 40000); | ||||||
|  | @ -235,6 +334,7 @@ const describeCases = config => { | ||||||
| 						it(`${testName} should compile`, done => { | 						it(`${testName} should compile`, done => { | ||||||
| 							rimraf.sync(outputDirectory); | 							rimraf.sync(outputDirectory); | ||||||
| 							fs.mkdirSync(outputDirectory, { recursive: true }); | 							fs.mkdirSync(outputDirectory, { recursive: true }); | ||||||
|  | 							infraStructureLog.length = 0; | ||||||
| 							const deprecationTracker = deprecationTracking.start(); | 							const deprecationTracker = deprecationTracking.start(); | ||||||
| 							const onCompiled = (err, stats) => { | 							const onCompiled = (err, stats) => { | ||||||
| 								const deprecations = deprecationTracker(); | 								const deprecations = deprecationTracker(); | ||||||
|  | @ -298,6 +398,21 @@ const describeCases = config => { | ||||||
| 								) { | 								) { | ||||||
| 									return; | 									return; | ||||||
| 								} | 								} | ||||||
|  | 								if (config.infrastructureLogErrors) { | ||||||
|  | 									if (!inAllowErrorsList()) { | ||||||
|  | 										const error = returnLogError( | ||||||
|  | 											infraStructureLog, | ||||||
|  | 											Array.isArray(config.infrastructureLogErrors.filter) | ||||||
|  | 												? config.infrastructureLogErrors.filter | ||||||
|  | 												: [config.infrastructureLogErrors.filter], | ||||||
|  | 											{ | ||||||
|  | 												run: 3, | ||||||
|  | 												options | ||||||
|  | 											} | ||||||
|  | 										); | ||||||
|  | 										if (error) return done(error); | ||||||
|  | 									} | ||||||
|  | 								} | ||||||
| 
 | 
 | ||||||
| 								let filesCount = 0; | 								let filesCount = 0; | ||||||
| 
 | 
 | ||||||
|  | @ -623,3 +738,6 @@ const describeCases = config => { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| exports.describeCases = describeCases; | exports.describeCases = describeCases; | ||||||
|  | exports.logErrors = { | ||||||
|  | 	PERSISTENCE_CACHE_INVALIDATE_ERROR | ||||||
|  | }; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue