| 
									
										
										
										
											2017-01-18 18:33:28 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-15 20:51:52 +08:00
										 |  |  | require("./helpers/warmup-webpack"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 18:33:28 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const fs = require("graceful-fs"); | 
					
						
							| 
									
										
										
										
											2013-12-03 20:01:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-20 21:48:52 +08:00
										 |  |  | jest.setTimeout(60000); | 
					
						
							| 
									
										
										
										
											2025-07-03 17:06:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 18:33:28 +08:00
										 |  |  | describe("Examples", () => { | 
					
						
							| 
									
										
										
										
											2017-07-27 19:24:56 +08:00
										 |  |  | 	const basePath = path.join(__dirname, "..", "examples"); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	const examples = require("../examples/examples"); | 
					
						
							| 
									
										
										
										
											2013-12-03 20:01:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 	for (const examplePath of examples) { | 
					
						
							| 
									
										
										
										
											2017-12-21 15:51:07 +08:00
										 |  |  | 		const filterPath = path.join(examplePath, "test.filter.js"); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:20:45 +08:00
										 |  |  | 		const relativePath = path.relative(basePath, examplePath); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 		if (fs.existsSync(filterPath) && !require(filterPath)()) { | 
					
						
							| 
									
										
										
										
											2024-06-11 20:32:02 +08:00
										 |  |  | 			// eslint-disable-next-line jest/no-disabled-tests, jest/valid-describe-callback
 | 
					
						
							| 
									
										
										
										
											2024-03-12 18:24:13 +08:00
										 |  |  | 			describe.skip(relativePath, () => | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 				it("filtered", (done) => { | 
					
						
							| 
									
										
										
										
											2024-03-12 18:24:13 +08:00
										 |  |  | 					done(); | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2017-12-21 15:51:07 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 00:13:14 +08:00
										 |  |  | 		it(`should compile ${relativePath}`, (done) => { | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			let options = {}; | 
					
						
							|  |  |  | 			let webpackConfigPath = path.join(examplePath, "webpack.config.js"); | 
					
						
							|  |  |  | 			webpackConfigPath = | 
					
						
							|  |  |  | 				webpackConfigPath.slice(0, 1).toUpperCase() + | 
					
						
							|  |  |  | 				webpackConfigPath.slice(1); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			if (fs.existsSync(webpackConfigPath)) { | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 				options = require(webpackConfigPath); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			if (typeof options === "function") options = options(); | 
					
						
							| 
									
										
										
										
											2024-08-02 23:42:44 +08:00
										 |  |  | 			if (Array.isArray(options)) { | 
					
						
							|  |  |  | 				for (const [_, item] of options.entries()) { | 
					
						
							|  |  |  | 					processOptions(item); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				processOptions(options); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-08-09 18:42:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-22 20:42:33 +08:00
										 |  |  | 			/** | 
					
						
							|  |  |  | 			 * @param {import("../").Configuration} options options | 
					
						
							|  |  |  | 			 */ | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			function processOptions(options) { | 
					
						
							|  |  |  | 				options.context = examplePath; | 
					
						
							|  |  |  | 				options.output = options.output || {}; | 
					
						
							|  |  |  | 				options.output.pathinfo = true; | 
					
						
							|  |  |  | 				options.output.path = path.join(examplePath, "dist"); | 
					
						
							|  |  |  | 				options.output.publicPath = "dist/"; | 
					
						
							|  |  |  | 				if (!options.entry) options.entry = "./example.js"; | 
					
						
							|  |  |  | 				if (!options.plugins) options.plugins = []; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			const webpack = require(".."); | 
					
						
							| 
									
										
										
										
											2025-07-02 20:10:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 			webpack(options, (err, stats) => { | 
					
						
							|  |  |  | 				if (err) return done(err); | 
					
						
							|  |  |  | 				if (stats.hasErrors()) { | 
					
						
							|  |  |  | 					return done( | 
					
						
							|  |  |  | 						new Error( | 
					
						
							|  |  |  | 							stats.toString({ | 
					
						
							|  |  |  | 								all: false, | 
					
						
							|  |  |  | 								errors: true, | 
					
						
							|  |  |  | 								errorDetails: true, | 
					
						
							|  |  |  | 								errorStacks: true | 
					
						
							|  |  |  | 							}) | 
					
						
							|  |  |  | 						) | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2015-01-13 00:45:30 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2024-07-31 10:39:30 +08:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}, 90000); | 
					
						
							| 
									
										
										
										
											2024-08-02 02:36:27 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-09 18:42:43 +08:00
										 |  |  | }); |