2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								"use strict";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const path = require("path");
							 | 
						
					
						
							
								
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const fs = require("graceful-fs");
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-04 23:48:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const rimraf = require("rimraf");
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-31 23:29:21 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const captureStdio = require("./helpers/captureStdio");
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-27 03:19:39 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-01 14:18:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								let webpack;
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-27 03:19:39 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
										
											2019-07-18 23:13:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * Escapes regular expression metacharacters
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @param {string} str String to quote
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * @returns {string} Escaped string
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const quotemeta = str => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const base = path.join(__dirname, "statsCases");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const outputBase = path.join(__dirname, "js", "stats");
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const tests = fs
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									.readdirSync(base)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									.filter(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										testName =>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											fs.existsSync(path.join(base, testName, "index.js")) ||
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											fs.existsSync(path.join(base, testName, "webpack.config.js"))
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-02 23:44:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									.filter(testName => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										const testDirectory = path.join(base, testName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										const filterPath = path.join(testDirectory, "test.filter.js");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										if (fs.existsSync(filterPath) && !require(filterPath)()) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											describe.skip(testName, () => it("filtered"));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											return false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-27 03:19:39 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-19 21:40:40 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								describe("StatsTestCases", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-01 14:18:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									let stderr;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									beforeEach(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										stderr = captureStdio(process.stderr, true);
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-05 18:15:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										webpack = require("..");
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-01 14:18:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									afterEach(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										stderr.restore();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									tests.forEach(testName => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										it("should print correct stats for " + testName, done => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-10-30 05:57:34 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											jest.setTimeout(30000);
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-04 23:48:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											const outputDirectory = path.join(outputBase, testName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											rimraf.sync(outputDirectory);
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-13 23:29:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											fs.mkdirSync(outputDirectory, { recursive: true });
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											let options = {
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												mode: "development",
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-16 22:10:25 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												entry: "./index",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												output: {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													filename: "bundle.js"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-27 03:19:39 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											};
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											if (fs.existsSync(path.join(base, testName, "webpack.config.js"))) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-11 04:52:22 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												options = require(path.join(base, testName, "webpack.config.js"));
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-27 03:19:39 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											let testConfig = {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											try {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												// try to load a test file
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												testConfig = Object.assign(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													testConfig,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													require(path.join(base, testName, "test.config.js"))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											} catch (e) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												// ignored
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											(Array.isArray(options) ? options : [options]).forEach(options => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												if (!options.context) options.context = path.join(base, testName);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												if (!options.output) options.output = options.output || {};
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-04 23:48:47 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (!options.output.path) options.output.path = outputDirectory;
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (!options.plugins) options.plugins = [];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												if (!options.optimization) options.optimization = {};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												if (options.optimization.minimize === undefined)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													options.optimization.minimize = false;
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 20:17:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											const c = webpack(options);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											const compilers = c.compilers ? c.compilers : [c];
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											compilers.forEach(c => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												const ifs = c.inputFileSystem;
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 20:17:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												c.inputFileSystem = Object.create(ifs);
							 | 
						
					
						
							
								
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												c.inputFileSystem.readFile = function () {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													const args = Array.prototype.slice.call(arguments);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													const callback = args.pop();
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													ifs.readFile.apply(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														ifs,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														args.concat([
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															(err, result) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																if (err) return callback(err);
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-16 23:29:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
																if (!/\.(js|json|txt)$/.test(args[0]))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																	return callback(null, result);
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
																callback(null, result.toString("utf-8").replace(/\r/g, ""));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													);
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 20:17:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												};
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												c.hooks.compilation.tap("StatsTestCasesTest", compilation => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													[
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														"optimize",
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-31 04:30:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														"optimizeModules",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														"optimizeChunks",
							 | 
						
					
						
							
								
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														"afterOptimizeTree",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														"afterOptimizeAssets",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														"beforeHash"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													].forEach(hook => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														compilation.hooks[hook].tap("TestCasesTest", () =>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															compilation.checkConstraints()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												});
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 20:17:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
											c.run((err, stats) => {
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (err) return done(err);
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-08 16:13:41 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												for (const compilation of []
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													.concat(stats.stats || stats)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													.map(s => s.compilation)) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													compilation.logging.delete("webpack.Compilation.ModuleProfile");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (/error$/.test(testName)) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													expect(stats.hasErrors()).toBe(true);
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												} else if (stats.hasErrors()) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-16 22:38:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													return done(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														new Error(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															stats.toString({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																all: false,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																errors: true,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																errorStack: true,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
																errorDetails: true
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													);
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-10 03:34:28 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												} else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													fs.writeFileSync(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														path.join(outputBase, testName, "stats.txt"),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														stats.toString({
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															preset: "verbose",
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															context: path.join(base, testName),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
															colors: false
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														}),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														"utf-8"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													);
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-03 17:01:29 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												let toStringOptions = {
							 | 
						
					
						
							
								
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													context: path.join(base, testName),
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-09 18:42:43 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													colors: false
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												};
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												let hasColorSetting = false;
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (typeof c.options.stats !== "undefined") {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													toStringOptions = c.options.stats;
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													if (toStringOptions === null || typeof toStringOptions !== "object")
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														toStringOptions = { preset: toStringOptions };
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													if (!toStringOptions.context)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														toStringOptions.context = path.join(base, testName);
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													hasColorSetting = typeof toStringOptions.colors !== "undefined";
							 | 
						
					
						
							
								
									
										
										
										
											2015-08-03 17:01:29 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-17 17:27:46 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (Array.isArray(c.options) && !toStringOptions.children) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													toStringOptions.children = c.options.map(o => o.stats);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-15 20:52:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												// mock timestamps
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-04 04:01:25 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												for (const { compilation: s } of [].concat(stats.stats || stats)) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-15 20:52:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													expect(s.startTime).toBeGreaterThan(0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													expect(s.endTime).toBeGreaterThan(0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													s.endTime = new Date("04/20/1970, 12:42:42 PM").getTime();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
													s.startTime = s.endTime - 1234;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-18 23:11:11 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												let actual = stats.toString(toStringOptions);
							 | 
						
					
						
							
								
									
										
										
										
											2018-01-24 23:00:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												expect(typeof actual).toBe("string");
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (!hasColorSetting) {
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-01 14:18:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													actual = stderr.toString() + actual;
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-14 21:08:04 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													actual = actual
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														.replace(/\u001b\[[0-9;]*m/g, "")
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-24 16:51:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														.replace(/[.0-9]+(\s?ms)/g, "X$1");
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-14 21:08:04 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												} else {
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-01 14:18:45 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													actual = stderr.toStringRaw() + actual;
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-14 21:08:04 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													actual = actual
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, "<CLR=$1,BOLD>")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														.replace(/\u001b\[1m/g, "<CLR=BOLD>")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														.replace(/\u001b\[39m\u001b\[22m/g, "</CLR>")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
														.replace(/\u001b\[([0-9;]*)m/g, "<CLR=$1>")
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-24 16:51:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
														.replace(/[.0-9]+(<\/CLR>)?(\s?ms)/g, "X$1$2");
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-14 21:08:04 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												}
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-06 18:36:32 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												const testPath = path.join(base, testName);
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-14 21:08:04 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												actual = actual
							 | 
						
					
						
							
								
									
										
										
										
											2015-09-03 20:42:00 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
													.replace(/\r\n?/g, "\n")
							 | 
						
					
						
							
								
									
										
										
										
											2020-09-04 04:09:43 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													.replace(/webpack [^ )]+(\)?) compiled/g, "webpack x.x.x$1 compiled")
							 | 
						
					
						
							
								
									
										
										
										
											2019-07-24 16:51:04 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													.replace(new RegExp(quotemeta(testPath), "g"), "Xdir/" + testName)
							 | 
						
					
						
							
								
									
										
										
											
												add logging API
Plugins:
Compiler.getInfrastructureLogger(name)
Compilation.getLogger(name)
Loader:
this.getLogger([name])
API equal to console API with these methods:
error, warn, info, log, debug,
time, timeLog, timeEnd,
group, groupCollapsed, groupEnd,
profile, profileEnd,
clear
											
										 
										
											2019-07-18 23:13:40 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													.replace(/(\w)\\(\w)/g, "$1/$2")
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-04 05:13:14 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
													.replace(/, additional resolving: X ms/g, "");
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-01 22:06:18 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												expect(actual).toMatchSnapshot();
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-11 22:25:03 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
												if (testConfig.validate) testConfig.validate(stats, stderr.toString());
							 | 
						
					
						
							
								
									
										
										
										
											2015-04-27 03:19:39 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												done();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
											});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									});
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 |