| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 20:51:52 +08:00
										 |  |  | require("./helpers/warmup-webpack"); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const fs = require("graceful-fs"); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | const vm = require("vm"); | 
					
						
							| 
									
										
										
										
											2021-06-24 16:05:37 +08:00
										 |  |  | const { pathToFileURL, URL } = require("url"); | 
					
						
							| 
									
										
										
										
											2018-10-18 04:15:46 +08:00
										 |  |  | const rimraf = require("rimraf"); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | const checkArrayExpectation = require("./checkArrayExpectation"); | 
					
						
							| 
									
										
										
										
											2018-08-02 19:05:48 +08:00
										 |  |  | const createLazyTestEnv = require("./helpers/createLazyTestEnv"); | 
					
						
							| 
									
										
										
										
											2020-07-15 17:14:28 +08:00
										 |  |  | const deprecationTracking = require("./helpers/deprecationTracking"); | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | const captureStdio = require("./helpers/captureStdio"); | 
					
						
							| 
									
										
										
										
											2021-06-24 22:44:14 +08:00
										 |  |  | const asModule = require("./helpers/asModule"); | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | const filterInfraStructureErrors = require("./helpers/infrastructureLogErrors"); | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | const casesPath = path.join(__dirname, "cases"); | 
					
						
							|  |  |  | let categories = fs.readdirSync(casesPath); | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | categories = categories.map(cat => ({ | 
					
						
							|  |  |  | 	name: cat, | 
					
						
							|  |  |  | 	tests: fs | 
					
						
							|  |  |  | 		.readdirSync(path.join(casesPath, cat)) | 
					
						
							| 
									
										
										
										
											2024-07-31 16:02:41 +08:00
										 |  |  | 		.filter(folder => !folder.includes("_")) | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | })); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +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), | 
					
						
							|  |  |  | 	warn: console.warn.bind(console), | 
					
						
							|  |  |  | 	error: console.error.bind(console), | 
					
						
							|  |  |  | 	logTime: () => {}, | 
					
						
							|  |  |  | 	group: () => {}, | 
					
						
							|  |  |  | 	groupCollapsed: () => {}, | 
					
						
							|  |  |  | 	groupEnd: () => {}, | 
					
						
							|  |  |  | 	profile: () => {}, | 
					
						
							|  |  |  | 	profileEnd: () => {}, | 
					
						
							|  |  |  | 	clear: () => {}, | 
					
						
							|  |  |  | 	status: () => {} | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | const describeCases = config => { | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 	describe(config.name, () => { | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 		let stderr; | 
					
						
							|  |  |  | 		beforeEach(() => { | 
					
						
							|  |  |  | 			stderr = captureStdio(process.stderr, true); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		afterEach(() => { | 
					
						
							|  |  |  | 			stderr.restore(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		for (const category of categories) { | 
					
						
							|  |  |  | 			// eslint-disable-next-line no-loop-func
 | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 			describe(category.name, function () { | 
					
						
							| 
									
										
										
										
											2018-05-18 22:34:01 +08:00
										 |  |  | 				jest.setTimeout(20000); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 				for (const testName of category.tests.filter(test => { | 
					
						
							|  |  |  | 					const testDirectory = path.join(casesPath, category.name, test); | 
					
						
							|  |  |  | 					const filterPath = path.join(testDirectory, "test.filter.js"); | 
					
						
							|  |  |  | 					if (fs.existsSync(filterPath) && !require(filterPath)(config)) { | 
					
						
							|  |  |  | 						// eslint-disable-next-line jest/no-disabled-tests
 | 
					
						
							|  |  |  | 						describe.skip(test, () => { | 
					
						
							|  |  |  | 							it("filtered", () => {}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						return false; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				})) { | 
					
						
							|  |  |  | 					const infraStructureLog = []; | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 					// eslint-disable-next-line no-loop-func
 | 
					
						
							|  |  |  | 					describe(testName, () => { | 
					
						
							|  |  |  | 						const testDirectory = path.join(casesPath, category.name, testName); | 
					
						
							|  |  |  | 						const outputDirectory = path.join( | 
					
						
							|  |  |  | 							__dirname, | 
					
						
							|  |  |  | 							"js", | 
					
						
							|  |  |  | 							config.name, | 
					
						
							|  |  |  | 							category.name, | 
					
						
							|  |  |  | 							testName | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						const cacheDirectory = path.join( | 
					
						
							|  |  |  | 							__dirname, | 
					
						
							|  |  |  | 							"js/.cache", | 
					
						
							|  |  |  | 							config.name, | 
					
						
							|  |  |  | 							category.name, | 
					
						
							|  |  |  | 							testName | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						let testConfig = {}; | 
					
						
							|  |  |  | 						const testConfigPath = path.join(testDirectory, "test.config.js"); | 
					
						
							|  |  |  | 						if (fs.existsSync(testConfigPath)) { | 
					
						
							|  |  |  | 							testConfig = require(testConfigPath); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						const TerserPlugin = require("terser-webpack-plugin"); | 
					
						
							|  |  |  | 						const terserForTesting = new TerserPlugin({ | 
					
						
							|  |  |  | 							parallel: false | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						let options = { | 
					
						
							|  |  |  | 							context: casesPath, | 
					
						
							|  |  |  | 							entry: `./${category.name}/${testName}/`, | 
					
						
							|  |  |  | 							target: config.target || "async-node", | 
					
						
							|  |  |  | 							devtool: config.devtool, | 
					
						
							|  |  |  | 							mode: config.mode || "none", | 
					
						
							|  |  |  | 							optimization: config.mode | 
					
						
							|  |  |  | 								? { | 
					
						
							|  |  |  | 										emitOnErrors: true, | 
					
						
							|  |  |  | 										minimizer: [terserForTesting], | 
					
						
							|  |  |  | 										...config.optimization | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								: { | 
					
						
							|  |  |  | 										removeAvailableModules: true, | 
					
						
							|  |  |  | 										removeEmptyChunks: true, | 
					
						
							|  |  |  | 										mergeDuplicateChunks: true, | 
					
						
							|  |  |  | 										flagIncludedChunks: true, | 
					
						
							|  |  |  | 										sideEffects: true, | 
					
						
							|  |  |  | 										providedExports: true, | 
					
						
							|  |  |  | 										usedExports: true, | 
					
						
							|  |  |  | 										mangleExports: true, | 
					
						
							|  |  |  | 										emitOnErrors: true, | 
					
						
							|  |  |  | 										concatenateModules: false, | 
					
						
							|  |  |  | 										moduleIds: "size", | 
					
						
							|  |  |  | 										chunkIds: "size", | 
					
						
							|  |  |  | 										minimizer: [terserForTesting], | 
					
						
							|  |  |  | 										...config.optimization | 
					
						
							|  |  |  | 									}, | 
					
						
							|  |  |  | 							performance: { | 
					
						
							|  |  |  | 								hints: false | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							node: { | 
					
						
							|  |  |  | 								__dirname: "mock", | 
					
						
							|  |  |  | 								__filename: "mock" | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							cache: config.cache && { | 
					
						
							|  |  |  | 								cacheDirectory, | 
					
						
							|  |  |  | 								...config.cache | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							output: { | 
					
						
							|  |  |  | 								pathinfo: "verbose", | 
					
						
							|  |  |  | 								path: outputDirectory, | 
					
						
							|  |  |  | 								filename: config.module ? "bundle.mjs" : "bundle.js" | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							resolve: { | 
					
						
							|  |  |  | 								modules: ["web_modules", "node_modules"], | 
					
						
							|  |  |  | 								mainFields: [ | 
					
						
							|  |  |  | 									"webpack", | 
					
						
							|  |  |  | 									"browser", | 
					
						
							|  |  |  | 									"web", | 
					
						
							|  |  |  | 									"browserify", | 
					
						
							|  |  |  | 									["jam", "main"], | 
					
						
							|  |  |  | 									"main" | 
					
						
							|  |  |  | 								], | 
					
						
							|  |  |  | 								aliasFields: ["browser"], | 
					
						
							|  |  |  | 								extensions: [".webpack.js", ".web.js", ".js", ".json"] | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							resolveLoader: { | 
					
						
							|  |  |  | 								modules: [ | 
					
						
							|  |  |  | 									"web_loaders", | 
					
						
							|  |  |  | 									"web_modules", | 
					
						
							|  |  |  | 									"node_loaders", | 
					
						
							|  |  |  | 									"node_modules" | 
					
						
							|  |  |  | 								], | 
					
						
							|  |  |  | 								mainFields: ["webpackLoader", "webLoader", "loader", "main"], | 
					
						
							|  |  |  | 								extensions: [ | 
					
						
							|  |  |  | 									".webpack-loader.js", | 
					
						
							|  |  |  | 									".web-loader.js", | 
					
						
							|  |  |  | 									".loader.js", | 
					
						
							|  |  |  | 									".js" | 
					
						
							|  |  |  | 								] | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							module: { | 
					
						
							|  |  |  | 								rules: [ | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										test: /\.coffee$/, | 
					
						
							|  |  |  | 										loader: "coffee-loader" | 
					
						
							|  |  |  | 									}, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										test: /\.pug/, | 
					
						
							|  |  |  | 										loader: "pug-loader" | 
					
						
							|  |  |  | 									}, | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										test: /\.wat$/i, | 
					
						
							|  |  |  | 										loader: "wast-loader", | 
					
						
							|  |  |  | 										type: "webassembly/async" | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								] | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							plugins: (config.plugins || []).concat(function () { | 
					
						
							|  |  |  | 								this.hooks.compilation.tap("TestCasesTest", compilation => { | 
					
						
							|  |  |  | 									for (const hook of [ | 
					
						
							|  |  |  | 										"optimize", | 
					
						
							|  |  |  | 										"optimizeModules", | 
					
						
							|  |  |  | 										"optimizeChunks", | 
					
						
							|  |  |  | 										"afterOptimizeTree", | 
					
						
							|  |  |  | 										"afterOptimizeAssets" | 
					
						
							|  |  |  | 									]) { | 
					
						
							|  |  |  | 										compilation.hooks[hook].tap("TestCasesTest", () => | 
					
						
							|  |  |  | 											compilation.checkConstraints() | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								}); | 
					
						
							|  |  |  | 							}), | 
					
						
							|  |  |  | 							experiments: { | 
					
						
							|  |  |  | 								asyncWebAssembly: true, | 
					
						
							|  |  |  | 								topLevelAwait: true, | 
					
						
							|  |  |  | 								backCompat: false, | 
					
						
							|  |  |  | 								...(config.module ? { outputModule: true } : {}) | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							infrastructureLogging: config.cache && { | 
					
						
							|  |  |  | 								debug: true, | 
					
						
							|  |  |  | 								console: createLogger(infraStructureLog) | 
					
						
							| 
									
										
										
										
											2021-06-29 18:06:45 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 						}; | 
					
						
							|  |  |  | 						const cleanups = []; | 
					
						
							|  |  |  | 						afterAll(() => { | 
					
						
							|  |  |  | 							options = undefined; | 
					
						
							|  |  |  | 							testConfig = undefined; | 
					
						
							|  |  |  | 							for (const fn of cleanups) fn(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						beforeAll(done => { | 
					
						
							|  |  |  | 							rimraf(cacheDirectory, done); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 						if (config.cache) { | 
					
						
							|  |  |  | 							it( | 
					
						
							|  |  |  | 								`${testName} should pre-compile to fill disk cache (1st)`, | 
					
						
							|  |  |  | 								done => { | 
					
						
							|  |  |  | 									const oldPath = options.output.path; | 
					
						
							|  |  |  | 									options.output.path = path.join( | 
					
						
							|  |  |  | 										options.output.path, | 
					
						
							|  |  |  | 										"cache1" | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									infraStructureLog.length = 0; | 
					
						
							|  |  |  | 									const deprecationTracker = deprecationTracking.start(); | 
					
						
							|  |  |  | 									const webpack = require(".."); | 
					
						
							|  |  |  | 									webpack(options, err => { | 
					
						
							|  |  |  | 										deprecationTracker(); | 
					
						
							|  |  |  | 										options.output.path = oldPath; | 
					
						
							|  |  |  | 										if (err) return done(err); | 
					
						
							|  |  |  | 										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, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 												done | 
					
						
							|  |  |  | 											) | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											return; | 
					
						
							| 
									
										
										
										
											2024-07-31 05:43:19 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 										done(); | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 								}, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 								testConfig.timeout || 60000 | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 							it( | 
					
						
							|  |  |  | 								`${testName} should pre-compile to fill disk cache (2nd)`, | 
					
						
							|  |  |  | 								done => { | 
					
						
							|  |  |  | 									const oldPath = options.output.path; | 
					
						
							|  |  |  | 									options.output.path = path.join( | 
					
						
							|  |  |  | 										options.output.path, | 
					
						
							|  |  |  | 										"cache2" | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									infraStructureLog.length = 0; | 
					
						
							|  |  |  | 									const deprecationTracker = deprecationTracking.start(); | 
					
						
							|  |  |  | 									const webpack = require(".."); | 
					
						
							|  |  |  | 									webpack(options, err => { | 
					
						
							|  |  |  | 										deprecationTracker(); | 
					
						
							|  |  |  | 										options.output.path = oldPath; | 
					
						
							|  |  |  | 										if (err) return done(err); | 
					
						
							|  |  |  | 										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, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 												done | 
					
						
							|  |  |  | 											) | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											return; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 										done(); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 								}, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 								testConfig.cachedTimeout || testConfig.timeout || 10000 | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						it( | 
					
						
							|  |  |  | 							`${testName} should compile`, | 
					
						
							|  |  |  | 							done => { | 
					
						
							|  |  |  | 								infraStructureLog.length = 0; | 
					
						
							|  |  |  | 								const webpack = require(".."); | 
					
						
							|  |  |  | 								const compiler = webpack(options); | 
					
						
							|  |  |  | 								const run = () => { | 
					
						
							|  |  |  | 									const deprecationTracker = deprecationTracking.start(); | 
					
						
							|  |  |  | 									compiler.run((err, stats) => { | 
					
						
							|  |  |  | 										const deprecations = deprecationTracker(); | 
					
						
							|  |  |  | 										if (err) return done(err); | 
					
						
							|  |  |  | 										const infrastructureLogErrors = filterInfraStructureErrors( | 
					
						
							|  |  |  | 											infraStructureLog, | 
					
						
							|  |  |  | 											{ | 
					
						
							|  |  |  | 												run: 3, | 
					
						
							|  |  |  | 												options | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 											} | 
					
						
							| 
									
										
										
										
											2021-06-29 18:06:45 +08:00
										 |  |  | 										); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 										if ( | 
					
						
							|  |  |  | 											infrastructureLogErrors.length && | 
					
						
							|  |  |  | 											checkArrayExpectation( | 
					
						
							|  |  |  | 												testDirectory, | 
					
						
							|  |  |  | 												{ infrastructureLogs: infrastructureLogErrors }, | 
					
						
							|  |  |  | 												"infrastructureLog", | 
					
						
							|  |  |  | 												"infrastructure-log", | 
					
						
							|  |  |  | 												"InfrastructureLog", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 												options, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 												done | 
					
						
							|  |  |  | 											) | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											return; | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 										compiler.close(err => { | 
					
						
							| 
									
										
										
										
											2021-06-29 18:06:45 +08:00
										 |  |  | 											if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 											const statOptions = { | 
					
						
							|  |  |  | 												preset: "verbose", | 
					
						
							|  |  |  | 												colors: false, | 
					
						
							|  |  |  | 												modules: true, | 
					
						
							|  |  |  | 												reasonsSpace: 1000 | 
					
						
							|  |  |  | 											}; | 
					
						
							|  |  |  | 											fs.mkdirSync(outputDirectory, { recursive: true }); | 
					
						
							|  |  |  | 											fs.writeFileSync( | 
					
						
							|  |  |  | 												path.join(outputDirectory, "stats.txt"), | 
					
						
							|  |  |  | 												stats.toString(statOptions), | 
					
						
							|  |  |  | 												"utf-8" | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 											const jsonStats = stats.toJson({ | 
					
						
							|  |  |  | 												errorDetails: true, | 
					
						
							|  |  |  | 												modules: false, | 
					
						
							|  |  |  | 												assets: false, | 
					
						
							|  |  |  | 												chunks: false | 
					
						
							|  |  |  | 											}); | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 											if ( | 
					
						
							|  |  |  | 												checkArrayExpectation( | 
					
						
							|  |  |  | 													testDirectory, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 													jsonStats, | 
					
						
							|  |  |  | 													"error", | 
					
						
							|  |  |  | 													"Error", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 													options, | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 													done | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 											) { | 
					
						
							|  |  |  | 												return; | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 											} | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 											if ( | 
					
						
							|  |  |  | 												checkArrayExpectation( | 
					
						
							|  |  |  | 													testDirectory, | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 													jsonStats, | 
					
						
							|  |  |  | 													"warning", | 
					
						
							|  |  |  | 													"Warning", | 
					
						
							| 
									
										
										
										
											2024-11-01 21:55:49 +08:00
										 |  |  | 													options, | 
					
						
							| 
									
										
										
										
											2022-02-15 02:31:59 +08:00
										 |  |  | 													done | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 											) { | 
					
						
							|  |  |  | 												return; | 
					
						
							| 
									
										
										
										
											2022-02-11 14:24:35 +08:00
										 |  |  | 											} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 											const infrastructureLogging = stderr.toString(); | 
					
						
							|  |  |  | 											if (infrastructureLogging) { | 
					
						
							|  |  |  | 												done( | 
					
						
							|  |  |  | 													new Error( | 
					
						
							|  |  |  | 														`Errors/Warnings during build:\n${ | 
					
						
							|  |  |  | 															infrastructureLogging | 
					
						
							|  |  |  | 														}`
 | 
					
						
							| 
									
										
										
										
											2018-12-20 23:29:35 +08:00
										 |  |  | 													) | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 												); | 
					
						
							|  |  |  | 											} | 
					
						
							| 
									
										
										
										
											2021-01-08 21:50:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 											expect(deprecations).toEqual(config.deprecations || []); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 											Promise.resolve().then(done); | 
					
						
							| 
									
										
										
										
											2018-10-25 17:18:45 +08:00
										 |  |  | 										}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 									}); | 
					
						
							|  |  |  | 								}; | 
					
						
							|  |  |  | 								if (config.cache) { | 
					
						
							|  |  |  | 									// pre-compile to fill memory cache
 | 
					
						
							|  |  |  | 									const deprecationTracker = deprecationTracking.start(); | 
					
						
							|  |  |  | 									compiler.run(err => { | 
					
						
							|  |  |  | 										deprecationTracker(); | 
					
						
							|  |  |  | 										if (err) return done(err); | 
					
						
							| 
									
										
										
										
											2018-12-20 23:29:35 +08:00
										 |  |  | 										run(); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 									}); | 
					
						
							|  |  |  | 								} else { | 
					
						
							|  |  |  | 									run(); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							testConfig.cachedTimeout || | 
					
						
							|  |  |  | 								testConfig.timeout || | 
					
						
							|  |  |  | 								(config.cache ? 20000 : 60000) | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2018-08-02 19:05:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 						it(`${testName} should load the compiled tests`, done => { | 
					
						
							|  |  |  | 							const esmContext = vm.createContext({ | 
					
						
							|  |  |  | 								it: _it, | 
					
						
							|  |  |  | 								expect, | 
					
						
							|  |  |  | 								process, | 
					
						
							|  |  |  | 								global, | 
					
						
							|  |  |  | 								URL, | 
					
						
							|  |  |  | 								Buffer, | 
					
						
							|  |  |  | 								setTimeout, | 
					
						
							|  |  |  | 								setImmediate, | 
					
						
							|  |  |  | 								nsObj: function (m) { | 
					
						
							|  |  |  | 									Object.defineProperty(m, Symbol.toStringTag, { | 
					
						
							|  |  |  | 										value: "Module" | 
					
						
							|  |  |  | 									}); | 
					
						
							|  |  |  | 									return m; | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 							cleanups.push(() => (esmContext.it = undefined)); | 
					
						
							|  |  |  | 							function _require(module, esmMode) { | 
					
						
							|  |  |  | 								if (module.startsWith("./")) { | 
					
						
							|  |  |  | 									const p = path.join(outputDirectory, module); | 
					
						
							|  |  |  | 									const content = fs.readFileSync(p, "utf-8"); | 
					
						
							|  |  |  | 									if (p.endsWith(".mjs")) { | 
					
						
							|  |  |  | 										let esm; | 
					
						
							|  |  |  | 										try { | 
					
						
							|  |  |  | 											esm = new vm.SourceTextModule(content, { | 
					
						
							|  |  |  | 												identifier: p, | 
					
						
							|  |  |  | 												context: esmContext, | 
					
						
							|  |  |  | 												initializeImportMeta: (meta, module) => { | 
					
						
							|  |  |  | 													meta.url = pathToFileURL(p).href; | 
					
						
							|  |  |  | 												}, | 
					
						
							|  |  |  | 												importModuleDynamically: async (specifier, module) => { | 
					
						
							|  |  |  | 													const result = await _require(specifier, "evaluated"); | 
					
						
							|  |  |  | 													return await asModule(result, module.context); | 
					
						
							|  |  |  | 												} | 
					
						
							|  |  |  | 											}); | 
					
						
							|  |  |  | 											cleanups.push(() => (esmContext.it = undefined)); | 
					
						
							|  |  |  | 										} catch (err) { | 
					
						
							|  |  |  | 											console.log(err); | 
					
						
							|  |  |  | 											err.message += `\nwhile parsing ${p}`; | 
					
						
							|  |  |  | 											throw err; | 
					
						
							| 
									
										
										
										
											2024-07-31 04:21:27 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 										if (esmMode === "unlinked") return esm; | 
					
						
							|  |  |  | 										return (async () => { | 
					
						
							|  |  |  | 											await esm.link( | 
					
						
							|  |  |  | 												async (specifier, module) => | 
					
						
							|  |  |  | 													await asModule( | 
					
						
							|  |  |  | 														await _require(specifier, "unlinked"), | 
					
						
							|  |  |  | 														module.context, | 
					
						
							|  |  |  | 														true | 
					
						
							|  |  |  | 													) | 
					
						
							|  |  |  | 											); | 
					
						
							|  |  |  | 											// node.js 10 needs instantiate
 | 
					
						
							|  |  |  | 											if (esm.instantiate) esm.instantiate(); | 
					
						
							|  |  |  | 											await esm.evaluate(); | 
					
						
							|  |  |  | 											if (esmMode === "evaluated") return esm; | 
					
						
							|  |  |  | 											const ns = esm.namespace; | 
					
						
							|  |  |  | 											return ns.default && ns.default instanceof Promise | 
					
						
							|  |  |  | 												? ns.default | 
					
						
							|  |  |  | 												: ns; | 
					
						
							|  |  |  | 										})(); | 
					
						
							| 
									
										
										
										
											2018-12-20 23:29:35 +08:00
										 |  |  | 									} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 									const fn = vm.runInThisContext( | 
					
						
							|  |  |  | 										"(function(require, module, exports, __dirname, __filename, it, expect) {" + | 
					
						
							|  |  |  | 											"global.expect = expect;" + | 
					
						
							|  |  |  | 											`function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }${ | 
					
						
							|  |  |  | 												content | 
					
						
							|  |  |  | 											}\n})`,
 | 
					
						
							|  |  |  | 										p | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									const m = { | 
					
						
							|  |  |  | 										exports: {}, | 
					
						
							|  |  |  | 										webpackTestSuiteModule: true | 
					
						
							|  |  |  | 									}; | 
					
						
							|  |  |  | 									fn.call( | 
					
						
							|  |  |  | 										m.exports, | 
					
						
							|  |  |  | 										_require, | 
					
						
							|  |  |  | 										m, | 
					
						
							|  |  |  | 										m.exports, | 
					
						
							|  |  |  | 										outputDirectory, | 
					
						
							|  |  |  | 										p, | 
					
						
							|  |  |  | 										_it, | 
					
						
							|  |  |  | 										expect | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 									return m.exports; | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 								return require(module); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							_require.webpackTestSuiteRequire = true; | 
					
						
							|  |  |  | 							Promise.resolve() | 
					
						
							|  |  |  | 								.then(() => _require(`./${options.output.filename}`)) | 
					
						
							|  |  |  | 								.then(() => { | 
					
						
							|  |  |  | 									if (getNumberOfTests() === 0) | 
					
						
							|  |  |  | 										return done(new Error("No tests exported by test case")); | 
					
						
							|  |  |  | 									done(); | 
					
						
							|  |  |  | 								}, done); | 
					
						
							|  |  |  | 						}, 10000); | 
					
						
							| 
									
										
										
										
											2018-12-20 23:29:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 						const { it: _it, getNumberOfTests } = createLazyTestEnv( | 
					
						
							|  |  |  | 							testConfig.timeout || 10000 | 
					
						
							|  |  |  | 						); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-25 08:16:11 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | // eslint-disable-next-line jest/no-export
 | 
					
						
							|  |  |  | module.exports.describeCases = describeCases; |