| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 20:51:52 +08:00
										 |  |  | require("./helpers/warmup-webpack"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-16 22:04:11 +08:00
										 |  |  | /** @typedef {Record<string, EXPECTED_ANY>} Env */ | 
					
						
							|  |  |  | /** @typedef {{ testPath: string } TestOptions */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | const path = require("path"); | 
					
						
							|  |  |  | const fs = require("graceful-fs"); | 
					
						
							|  |  |  | const rimraf = require("rimraf"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const { parseResource } = require("../lib/util/identifier"); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | const checkArrayExpectation = require("./checkArrayExpectation"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const captureStdio = require("./helpers/captureStdio"); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | const createLazyTestEnv = require("./helpers/createLazyTestEnv"); | 
					
						
							|  |  |  | const deprecationTracking = require("./helpers/deprecationTracking"); | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors"); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | const prepareOptions = require("./helpers/prepareOptions"); | 
					
						
							| 
									
										
										
										
											2025-06-20 22:08:04 +08:00
										 |  |  | const { TestRunner } = require("./runner"); | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | const casesPath = path.join(__dirname, "configCases"); | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const categories = fs.readdirSync(casesPath).map((cat) => ({ | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 	name: cat, | 
					
						
							|  |  |  | 	tests: fs | 
					
						
							|  |  |  | 		.readdirSync(path.join(casesPath, cat)) | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		.filter((folder) => !folder.startsWith("_")) | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 		.sort() | 
					
						
							|  |  |  | })); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const createLogger = (appendTarget) => ({ | 
					
						
							|  |  |  | 	log: (l) => appendTarget.push(l), | 
					
						
							|  |  |  | 	debug: (l) => appendTarget.push(l), | 
					
						
							|  |  |  | 	trace: (l) => appendTarget.push(l), | 
					
						
							|  |  |  | 	info: (l) => appendTarget.push(l), | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | 	warn: console.warn.bind(console), | 
					
						
							|  |  |  | 	error: console.error.bind(console), | 
					
						
							|  |  |  | 	logTime: () => {}, | 
					
						
							|  |  |  | 	group: () => {}, | 
					
						
							|  |  |  | 	groupCollapsed: () => {}, | 
					
						
							|  |  |  | 	groupEnd: () => {}, | 
					
						
							|  |  |  | 	profile: () => {}, | 
					
						
							|  |  |  | 	profileEnd: () => {}, | 
					
						
							|  |  |  | 	clear: () => {}, | 
					
						
							|  |  |  | 	status: () => {} | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | const describeCases = (config) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 	describe(config.name, () => { | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 		let stderr; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 		beforeEach(() => { | 
					
						
							|  |  |  | 			stderr = captureStdio(process.stderr, true); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 		afterEach(() => { | 
					
						
							|  |  |  | 			stderr.restore(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 		jest.setTimeout(20000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (const category of categories) { | 
					
						
							| 
									
										
										
										
											2024-07-31 13:38:50 +08:00
										 |  |  | 			// eslint-disable-next-line no-loop-func
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 			describe(category.name, () => { | 
					
						
							|  |  |  | 				for (const testName of category.tests) { | 
					
						
							| 
									
										
										
										
											2024-07-31 13:38:50 +08:00
										 |  |  | 					// eslint-disable-next-line no-loop-func
 | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 					describe(testName, () => { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 						const testDirectory = path.join(casesPath, category.name, testName); | 
					
						
							|  |  |  | 						const filterPath = path.join(testDirectory, "test.filter.js"); | 
					
						
							| 
									
										
										
										
											2024-05-08 17:43:56 +08:00
										 |  |  | 						if (fs.existsSync(filterPath) && !require(filterPath)(config)) { | 
					
						
							| 
									
										
										
										
											2024-06-11 20:32:02 +08:00
										 |  |  | 							// eslint-disable-next-line jest/no-disabled-tests
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 							describe.skip(testName, () => { | 
					
						
							|  |  |  | 								it("filtered", () => {}); | 
					
						
							|  |  |  | 							}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 							return; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 						const infraStructureLog = []; | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 						const outBaseDir = path.join(__dirname, "js"); | 
					
						
							|  |  |  | 						const testSubPath = path.join(config.name, category.name, testName); | 
					
						
							|  |  |  | 						const outputDirectory = path.join(outBaseDir, testSubPath); | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 						const cacheDirectory = path.join(outBaseDir, ".cache", testSubPath); | 
					
						
							| 
									
										
										
										
											2024-07-31 09:56:53 +08:00
										 |  |  | 						let options; | 
					
						
							|  |  |  | 						let optionsArr; | 
					
						
							|  |  |  | 						let testConfig; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 						beforeAll(() => { | 
					
						
							|  |  |  | 							options = prepareOptions( | 
					
						
							|  |  |  | 								require(path.join(testDirectory, "webpack.config.js")), | 
					
						
							|  |  |  | 								{ testPath: outputDirectory } | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 							optionsArr = [...(Array.isArray(options) ? options : [options])]; | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 							for (const [idx, options] of optionsArr.entries()) { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								if (!options.context) options.context = testDirectory; | 
					
						
							|  |  |  | 								if (!options.mode) options.mode = "production"; | 
					
						
							|  |  |  | 								if (!options.optimization) options.optimization = {}; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								if (options.optimization.minimize === undefined) { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 									options.optimization.minimize = false; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2021-01-19 02:21:12 +08:00
										 |  |  | 								if (options.optimization.minimizer === undefined) { | 
					
						
							|  |  |  | 									options.optimization.minimizer = [ | 
					
						
							| 
									
										
										
										
											2021-07-08 00:46:29 +08:00
										 |  |  | 										new (require("terser-webpack-plugin"))({ | 
					
						
							| 
									
										
										
										
											2021-01-19 02:21:12 +08:00
										 |  |  | 											parallel: false | 
					
						
							|  |  |  | 										}) | 
					
						
							|  |  |  | 									]; | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								if (!options.entry) options.entry = "./index.js"; | 
					
						
							|  |  |  | 								if (!options.target) options.target = "async-node"; | 
					
						
							|  |  |  | 								if (!options.output) options.output = {}; | 
					
						
							|  |  |  | 								if (!options.output.path) options.output.path = outputDirectory; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								if (typeof options.output.pathinfo === "undefined") { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 									options.output.pathinfo = true; | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 								if (!options.output.filename) { | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 									options.output.filename = `bundle${idx}${ | 
					
						
							|  |  |  | 										options.experiments && options.experiments.outputModule | 
					
						
							| 
									
										
										
										
											2021-06-23 19:58:40 +08:00
										 |  |  | 											? ".mjs" | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 											: ".js" | 
					
						
							|  |  |  | 									}`;
 | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2024-05-08 00:38:06 +08:00
										 |  |  | 								if (config.cache) { | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 									options.cache = { | 
					
						
							|  |  |  | 										cacheDirectory, | 
					
						
							| 
									
										
										
										
											2024-04-13 02:33:48 +08:00
										 |  |  | 										name: | 
					
						
							|  |  |  | 											options.cache && options.cache !== true | 
					
						
							|  |  |  | 												? options.cache.name | 
					
						
							|  |  |  | 												: `config-${idx}`, | 
					
						
							| 
									
										
										
										
											2024-05-08 00:38:06 +08:00
										 |  |  | 										...config.cache | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 									}; | 
					
						
							| 
									
										
										
										
											2024-04-13 02:33:48 +08:00
										 |  |  | 								} | 
					
						
							|  |  |  | 								if (config.cache) { | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 									options.infrastructureLogging = { | 
					
						
							|  |  |  | 										debug: true, | 
					
						
							|  |  |  | 										console: createLogger(infraStructureLog) | 
					
						
							|  |  |  | 									}; | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2021-11-15 21:18:58 +08:00
										 |  |  | 								if (!options.snapshot) options.snapshot = {}; | 
					
						
							|  |  |  | 								if (!options.snapshot.managedPaths) { | 
					
						
							|  |  |  | 									options.snapshot.managedPaths = [ | 
					
						
							|  |  |  | 										path.resolve(__dirname, "../node_modules") | 
					
						
							|  |  |  | 									]; | 
					
						
							| 
									
										
										
										
											2020-08-26 06:36:16 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 							testConfig = { | 
					
						
							| 
									
										
										
										
											2025-04-22 19:09:25 +08:00
										 |  |  | 								findBundle(i, options) { | 
					
						
							| 
									
										
										
										
											2020-08-19 03:14:43 +08:00
										 |  |  | 									const ext = path.extname( | 
					
						
							|  |  |  | 										parseResource(options.output.filename).path | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 									if ( | 
					
						
							|  |  |  | 										fs.existsSync( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 											path.join(options.output.path, `bundle${i}${ext}`) | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 										) | 
					
						
							|  |  |  | 									) { | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 										return `./bundle${i}${ext}`; | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 								}, | 
					
						
							|  |  |  | 								timeout: 30000 | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 							try { | 
					
						
							|  |  |  | 								// try to load a test file
 | 
					
						
							|  |  |  | 								testConfig = Object.assign( | 
					
						
							|  |  |  | 									testConfig, | 
					
						
							|  |  |  | 									require(path.join(testDirectory, "test.config.js")) | 
					
						
							|  |  |  | 								); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 							} catch (_err) { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								// ignored
 | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							if (testConfig.timeout) setDefaultTimeout(testConfig.timeout); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						// eslint-disable-next-line jest/no-duplicate-hooks
 | 
					
						
							|  |  |  | 						beforeAll(() => { | 
					
						
							|  |  |  | 							rimraf.sync(cacheDirectory); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-08 17:26:27 +08:00
										 |  |  | 						afterAll(() => { | 
					
						
							|  |  |  | 							// cleanup
 | 
					
						
							|  |  |  | 							options = undefined; | 
					
						
							|  |  |  | 							optionsArr = undefined; | 
					
						
							|  |  |  | 							testConfig = undefined; | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 						const handleFatalError = (err, done) => { | 
					
						
							|  |  |  | 							const fakeStats = { | 
					
						
							|  |  |  | 								errors: [ | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										message: err.message, | 
					
						
							|  |  |  | 										stack: err.stack | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								] | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 							if ( | 
					
						
							|  |  |  | 								checkArrayExpectation( | 
					
						
							|  |  |  | 									testDirectory, | 
					
						
							|  |  |  | 									fakeStats, | 
					
						
							|  |  |  | 									"error", | 
					
						
							|  |  |  | 									"Error", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 									options, | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 									done | 
					
						
							|  |  |  | 								) | 
					
						
							|  |  |  | 							) { | 
					
						
							|  |  |  | 								return; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							// Wait for uncaught errors to occur
 | 
					
						
							|  |  |  | 							setTimeout(done, 200); | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 						if (config.cache) { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							it(`${testName} should pre-compile to fill disk cache (1st)`, (done) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								rimraf.sync(outputDirectory); | 
					
						
							|  |  |  | 								fs.mkdirSync(outputDirectory, { recursive: true }); | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 								infraStructureLog.length = 0; | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								const deprecationTracker = deprecationTracking.start(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-20 18:55:18 +08:00
										 |  |  | 								const compiler = require("..")(options); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 								compiler.run((err) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 									deprecationTracker(); | 
					
						
							| 
									
										
										
										
											2024-06-20 18:55:18 +08:00
										 |  |  | 									if (err) return handleFatalError(err, done); | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 									const infrastructureLogging = stderr.toString(); | 
					
						
							|  |  |  | 									if (infrastructureLogging) { | 
					
						
							|  |  |  | 										return done( | 
					
						
							|  |  |  | 											new Error( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 												`Errors/Warnings during build:\n${ | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 													infrastructureLogging | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 												}`
 | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 											) | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 									const infrastructureLogErrors = filterInfraStructureErrors( | 
					
						
							|  |  |  | 										infraStructureLog, | 
					
						
							|  |  |  | 										{ | 
					
						
							|  |  |  | 											run: 1, | 
					
						
							|  |  |  | 											options | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									if ( | 
					
						
							|  |  |  | 										infrastructureLogErrors.length && | 
					
						
							|  |  |  | 										checkArrayExpectation( | 
					
						
							|  |  |  | 											testDirectory, | 
					
						
							|  |  |  | 											{ infrastructureLogs: infrastructureLogErrors }, | 
					
						
							|  |  |  | 											"infrastructureLog", | 
					
						
							|  |  |  | 											"infrastructure-log", | 
					
						
							|  |  |  | 											"InfrastructureLog", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 											options, | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 											done | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 									) { | 
					
						
							|  |  |  | 										return; | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 									compiler.close((closeErr) => { | 
					
						
							| 
									
										
										
										
											2024-06-21 00:05:40 +08:00
										 |  |  | 										if (closeErr) return handleFatalError(closeErr, done); | 
					
						
							| 
									
										
										
										
											2024-06-20 18:55:18 +08:00
										 |  |  | 										done(); | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								}); | 
					
						
							|  |  |  | 							}, 60000); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 							it(`${testName} should pre-compile to fill disk cache (2nd)`, (done) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								rimraf.sync(outputDirectory); | 
					
						
							|  |  |  | 								fs.mkdirSync(outputDirectory, { recursive: true }); | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 								infraStructureLog.length = 0; | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								const deprecationTracker = deprecationTracking.start(); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-20 18:55:18 +08:00
										 |  |  | 								const compiler = require("..")(options); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-20 18:55:18 +08:00
										 |  |  | 								compiler.run((err, stats) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 									deprecationTracker(); | 
					
						
							|  |  |  | 									if (err) return handleFatalError(err, done); | 
					
						
							| 
									
										
										
										
											2021-02-23 22:36:45 +08:00
										 |  |  | 									const { modules, children, errorsCount } = stats.toJson({ | 
					
						
							|  |  |  | 										all: false, | 
					
						
							|  |  |  | 										modules: true, | 
					
						
							|  |  |  | 										errorsCount: true | 
					
						
							|  |  |  | 									}); | 
					
						
							|  |  |  | 									if (errorsCount === 0) { | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 										const infrastructureLogging = stderr.toString(); | 
					
						
							|  |  |  | 										if (infrastructureLogging) { | 
					
						
							|  |  |  | 											return done( | 
					
						
							|  |  |  | 												new Error( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 													`Errors/Warnings during build:\n${ | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 														infrastructureLogging | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 													}`
 | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 												) | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2021-02-23 22:36:45 +08:00
										 |  |  | 										const allModules = children | 
					
						
							|  |  |  | 											? children.reduce( | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 													(all, { modules }) => [...all, ...modules], | 
					
						
							| 
									
										
										
										
											2021-02-23 22:36:45 +08:00
										 |  |  | 													modules || [] | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 												) | 
					
						
							| 
									
										
										
										
											2021-02-23 22:36:45 +08:00
										 |  |  | 											: modules; | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											allModules.some( | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 												(m) => m.type !== "cached modules" && !m.cached | 
					
						
							| 
									
										
										
										
											2021-02-23 22:36:45 +08:00
										 |  |  | 											) | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											return done( | 
					
						
							|  |  |  | 												new Error( | 
					
						
							|  |  |  | 													`Some modules were not cached:\n${stats.toString({ | 
					
						
							|  |  |  | 														all: false, | 
					
						
							|  |  |  | 														modules: true, | 
					
						
							|  |  |  | 														modulesSpace: 100 | 
					
						
							|  |  |  | 													})}`
 | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 									} | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 									const infrastructureLogErrors = filterInfraStructureErrors( | 
					
						
							|  |  |  | 										infraStructureLog, | 
					
						
							|  |  |  | 										{ | 
					
						
							|  |  |  | 											run: 2, | 
					
						
							|  |  |  | 											options | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									if ( | 
					
						
							|  |  |  | 										infrastructureLogErrors.length && | 
					
						
							|  |  |  | 										checkArrayExpectation( | 
					
						
							|  |  |  | 											testDirectory, | 
					
						
							|  |  |  | 											{ infrastructureLogs: infrastructureLogErrors }, | 
					
						
							|  |  |  | 											"infrastructureLog", | 
					
						
							|  |  |  | 											"infrastructure-log", | 
					
						
							|  |  |  | 											"InfrastructureLog", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 											options, | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 											done | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 									) { | 
					
						
							|  |  |  | 										return; | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 									compiler.close((closeErr) => { | 
					
						
							| 
									
										
										
										
											2024-06-21 00:05:40 +08:00
										 |  |  | 										if (closeErr) return handleFatalError(closeErr, done); | 
					
						
							| 
									
										
										
										
											2024-06-20 18:55:18 +08:00
										 |  |  | 										done(); | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								}); | 
					
						
							| 
									
										
										
										
											2021-06-26 00:11:43 +08:00
										 |  |  | 							}, 40000); | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 						it(`${testName} should compile`, (done) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 							rimraf.sync(outputDirectory); | 
					
						
							|  |  |  | 							fs.mkdirSync(outputDirectory, { recursive: true }); | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 							infraStructureLog.length = 0; | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 							const deprecationTracker = deprecationTracking.start(); | 
					
						
							| 
									
										
										
										
											2021-07-22 15:32:55 +08:00
										 |  |  | 							const onCompiled = (err, stats) => { | 
					
						
							| 
									
										
										
										
											2020-06-02 18:25:28 +08:00
										 |  |  | 								const deprecations = deprecationTracker(); | 
					
						
							|  |  |  | 								if (err) return handleFatalError(err, done); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								const statOptions = { | 
					
						
							|  |  |  | 									preset: "verbose", | 
					
						
							|  |  |  | 									colors: false | 
					
						
							|  |  |  | 								}; | 
					
						
							|  |  |  | 								fs.mkdirSync(outputDirectory, { recursive: true }); | 
					
						
							|  |  |  | 								fs.writeFileSync( | 
					
						
							|  |  |  | 									path.join(outputDirectory, "stats.txt"), | 
					
						
							|  |  |  | 									stats.toString(statOptions), | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 									"utf8" | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								); | 
					
						
							|  |  |  | 								const jsonStats = stats.toJson({ | 
					
						
							|  |  |  | 									errorDetails: true | 
					
						
							|  |  |  | 								}); | 
					
						
							|  |  |  | 								fs.writeFileSync( | 
					
						
							|  |  |  | 									path.join(outputDirectory, "stats.json"), | 
					
						
							|  |  |  | 									JSON.stringify(jsonStats, null, 2), | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 									"utf8" | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								); | 
					
						
							|  |  |  | 								if ( | 
					
						
							|  |  |  | 									checkArrayExpectation( | 
					
						
							|  |  |  | 										testDirectory, | 
					
						
							|  |  |  | 										jsonStats, | 
					
						
							|  |  |  | 										"error", | 
					
						
							|  |  |  | 										"Error", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 										options, | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 										done | 
					
						
							|  |  |  | 									) | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									return; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								if ( | 
					
						
							|  |  |  | 									checkArrayExpectation( | 
					
						
							|  |  |  | 										testDirectory, | 
					
						
							|  |  |  | 										jsonStats, | 
					
						
							|  |  |  | 										"warning", | 
					
						
							|  |  |  | 										"Warning", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 										options, | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 										done | 
					
						
							|  |  |  | 									) | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									return; | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 								const infrastructureLogging = stderr.toString(); | 
					
						
							|  |  |  | 								if (infrastructureLogging) { | 
					
						
							| 
									
										
										
										
											2021-07-12 23:02:33 +08:00
										 |  |  | 									return done( | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 										new Error( | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 											`Errors/Warnings during build:\n${infrastructureLogging}` | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 										) | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 								if ( | 
					
						
							|  |  |  | 									checkArrayExpectation( | 
					
						
							|  |  |  | 										testDirectory, | 
					
						
							|  |  |  | 										{ deprecations }, | 
					
						
							|  |  |  | 										"deprecation", | 
					
						
							|  |  |  | 										"Deprecation", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 										options, | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 										done | 
					
						
							|  |  |  | 									) | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									return; | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 								const infrastructureLogErrors = filterInfraStructureErrors( | 
					
						
							|  |  |  | 									infraStructureLog, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										run: 3, | 
					
						
							|  |  |  | 										options | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 								if ( | 
					
						
							|  |  |  | 									infrastructureLogErrors.length && | 
					
						
							|  |  |  | 									checkArrayExpectation( | 
					
						
							|  |  |  | 										testDirectory, | 
					
						
							|  |  |  | 										{ infrastructureLogs: infrastructureLogErrors }, | 
					
						
							|  |  |  | 										"infrastructureLog", | 
					
						
							|  |  |  | 										"infrastructure-log", | 
					
						
							|  |  |  | 										"InfrastructureLog", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 										options, | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 										done | 
					
						
							|  |  |  | 									) | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									return; | 
					
						
							| 
									
										
										
										
											2022-02-10 17:41:48 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 								let filesCount = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 								if (testConfig.noTests) return process.nextTick(done); | 
					
						
							|  |  |  | 								if (testConfig.beforeExecute) testConfig.beforeExecute(); | 
					
						
							|  |  |  | 								const results = []; | 
					
						
							|  |  |  | 								for (let i = 0; i < optionsArr.length; i++) { | 
					
						
							| 
									
										
										
										
											2021-11-25 20:21:40 +08:00
										 |  |  | 									const options = optionsArr[i]; | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 									const bundlePath = testConfig.findBundle(i, optionsArr[i]); | 
					
						
							|  |  |  | 									if (bundlePath) { | 
					
						
							|  |  |  | 										filesCount++; | 
					
						
							| 
									
										
										
										
											2025-06-20 22:08:04 +08:00
										 |  |  | 										const runner = new TestRunner({ | 
					
						
							|  |  |  | 											target: options.target, | 
					
						
							|  |  |  | 											outputDirectory, | 
					
						
							|  |  |  | 											testMeta: { | 
					
						
							|  |  |  | 												category: category.name, | 
					
						
							|  |  |  | 												name: testName, | 
					
						
							|  |  |  | 												round: i | 
					
						
							|  |  |  | 											}, | 
					
						
							|  |  |  | 											testConfig, | 
					
						
							|  |  |  | 											webpackOptions: options | 
					
						
							|  |  |  | 										}); | 
					
						
							|  |  |  | 										runner.mergeModuleScope({ | 
					
						
							| 
									
										
										
										
											2021-11-25 20:21:40 +08:00
										 |  |  | 											it: _it, | 
					
						
							|  |  |  | 											beforeEach: _beforeEach, | 
					
						
							|  |  |  | 											afterEach: _afterEach, | 
					
						
							|  |  |  | 											__STATS__: jsonStats, | 
					
						
							| 
									
										
										
										
											2025-06-20 22:08:04 +08:00
										 |  |  | 											__STATS_I__: i | 
					
						
							|  |  |  | 										}); | 
					
						
							| 
									
										
										
										
											2021-11-25 20:21:40 +08:00
										 |  |  | 										if (testConfig.moduleScope) { | 
					
						
							| 
									
										
										
										
											2025-06-20 22:08:04 +08:00
										 |  |  | 											testConfig.moduleScope(runner._moduleScope, options); | 
					
						
							| 
									
										
										
										
											2021-11-25 20:21:40 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2021-06-21 23:57:10 +08:00
										 |  |  | 										if (Array.isArray(bundlePath)) { | 
					
						
							|  |  |  | 											for (const bundlePathItem of bundlePath) { | 
					
						
							|  |  |  | 												results.push( | 
					
						
							| 
									
										
										
										
											2025-06-20 22:08:04 +08:00
										 |  |  | 													runner.require(outputDirectory, `./${bundlePathItem}`) | 
					
						
							| 
									
										
										
										
											2021-06-21 23:57:10 +08:00
										 |  |  | 												); | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 										} else { | 
					
						
							| 
									
										
										
										
											2025-06-20 22:08:04 +08:00
										 |  |  | 											results.push(runner.require(outputDirectory, bundlePath)); | 
					
						
							| 
									
										
										
										
											2021-06-21 23:57:10 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								// give a free pass to compilation that generated an error
 | 
					
						
							|  |  |  | 								if ( | 
					
						
							|  |  |  | 									!jsonStats.errors.length && | 
					
						
							|  |  |  | 									filesCount !== optionsArr.length | 
					
						
							|  |  |  | 								) { | 
					
						
							|  |  |  | 									return done( | 
					
						
							|  |  |  | 										new Error( | 
					
						
							|  |  |  | 											"Should have found at least one bundle file per webpack config" | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 								Promise.all(results) | 
					
						
							|  |  |  | 									.then(() => { | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 										if (testConfig.afterExecute) { | 
					
						
							| 
									
										
										
										
											2025-03-05 02:05:18 +08:00
										 |  |  | 											testConfig.afterExecute(options); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2021-07-07 16:00:07 +08:00
										 |  |  | 										for (const key of Object.keys(global)) { | 
					
						
							|  |  |  | 											if (key.includes("webpack")) delete global[key]; | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 										if (getNumberOfTests() < filesCount) { | 
					
						
							|  |  |  | 											return done(new Error("No tests exported by test case")); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 										done(); | 
					
						
							|  |  |  | 									}) | 
					
						
							|  |  |  | 									.catch(done); | 
					
						
							| 
									
										
										
										
											2021-07-22 15:32:55 +08:00
										 |  |  | 							}; | 
					
						
							|  |  |  | 							if (config.cache) { | 
					
						
							| 
									
										
										
										
											2021-07-22 17:11:18 +08:00
										 |  |  | 								try { | 
					
						
							|  |  |  | 									const compiler = require("..")(options); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 									compiler.run((err) => { | 
					
						
							| 
									
										
										
										
											2021-07-22 17:11:18 +08:00
										 |  |  | 										if (err) return handleFatalError(err, done); | 
					
						
							|  |  |  | 										compiler.run((error, stats) => { | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 											compiler.close((err) => { | 
					
						
							| 
									
										
										
										
											2021-07-22 17:11:18 +08:00
										 |  |  | 												if (err) return handleFatalError(err, done); | 
					
						
							|  |  |  | 												onCompiled(error, stats); | 
					
						
							|  |  |  | 											}); | 
					
						
							| 
									
										
										
										
											2021-07-22 15:32:55 +08:00
										 |  |  | 										}); | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2024-07-31 15:37:05 +08:00
										 |  |  | 								} catch (err) { | 
					
						
							|  |  |  | 									handleFatalError(err, done); | 
					
						
							| 
									
										
										
										
											2021-07-22 17:11:18 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2021-07-22 15:32:55 +08:00
										 |  |  | 							} else { | 
					
						
							|  |  |  | 								require("..")(options, onCompiled); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2021-07-12 18:07:32 +08:00
										 |  |  | 						}, 30000); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						const { | 
					
						
							|  |  |  | 							it: _it, | 
					
						
							|  |  |  | 							beforeEach: _beforeEach, | 
					
						
							|  |  |  | 							afterEach: _afterEach, | 
					
						
							|  |  |  | 							setDefaultTimeout, | 
					
						
							|  |  |  | 							getNumberOfTests | 
					
						
							| 
									
										
										
										
											2021-06-21 18:06:41 +08:00
										 |  |  | 						} = createLazyTestEnv(10000); | 
					
						
							| 
									
										
										
										
											2020-06-02 17:55:59 +08:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | // eslint-disable-next-line jest/no-export
 | 
					
						
							|  |  |  | module.exports.describeCases = describeCases; |