mirror of https://github.com/webpack/webpack.git
avoid importing large package on top-level in test suite
This commit is contained in:
parent
cdf73dacf5
commit
e14197ddd9
|
|
@ -5,8 +5,6 @@ const fs = require("graceful-fs");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
const { URL, pathToFileURL, fileURLToPath } = require("url");
|
const { URL, pathToFileURL, fileURLToPath } = require("url");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
const webpack = require("..");
|
|
||||||
const TerserPlugin = require("terser-webpack-plugin");
|
|
||||||
const checkArrayExpectation = require("./checkArrayExpectation");
|
const checkArrayExpectation = require("./checkArrayExpectation");
|
||||||
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
const deprecationTracking = require("./helpers/deprecationTracking");
|
const deprecationTracking = require("./helpers/deprecationTracking");
|
||||||
|
|
@ -73,7 +71,7 @@ const describeCases = config => {
|
||||||
options.optimization.minimize = false;
|
options.optimization.minimize = false;
|
||||||
if (options.optimization.minimizer === undefined) {
|
if (options.optimization.minimizer === undefined) {
|
||||||
options.optimization.minimizer = [
|
options.optimization.minimizer = [
|
||||||
new TerserPlugin({
|
new (require("terser-webpack-plugin"))({
|
||||||
parallel: false
|
parallel: false
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
@ -162,7 +160,7 @@ const describeCases = config => {
|
||||||
rimraf.sync(outputDirectory);
|
rimraf.sync(outputDirectory);
|
||||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||||
const deprecationTracker = deprecationTracking.start();
|
const deprecationTracker = deprecationTracking.start();
|
||||||
webpack(options, err => {
|
require("..")(options, err => {
|
||||||
deprecationTracker();
|
deprecationTracker();
|
||||||
if (err) return handleFatalError(err, done);
|
if (err) return handleFatalError(err, done);
|
||||||
done();
|
done();
|
||||||
|
|
@ -172,7 +170,7 @@ const describeCases = config => {
|
||||||
rimraf.sync(outputDirectory);
|
rimraf.sync(outputDirectory);
|
||||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||||
const deprecationTracker = deprecationTracking.start();
|
const deprecationTracker = deprecationTracking.start();
|
||||||
webpack(options, (err, stats) => {
|
require("..")(options, (err, stats) => {
|
||||||
deprecationTracker();
|
deprecationTracker();
|
||||||
if (err) return handleFatalError(err, done);
|
if (err) return handleFatalError(err, done);
|
||||||
const { modules, children, errorsCount } = stats.toJson({
|
const { modules, children, errorsCount } = stats.toJson({
|
||||||
|
|
@ -211,7 +209,7 @@ const describeCases = config => {
|
||||||
rimraf.sync(outputDirectory);
|
rimraf.sync(outputDirectory);
|
||||||
fs.mkdirSync(outputDirectory, { recursive: true });
|
fs.mkdirSync(outputDirectory, { recursive: true });
|
||||||
const deprecationTracker = deprecationTracking.start();
|
const deprecationTracker = deprecationTracking.start();
|
||||||
webpack(options, (err, stats) => {
|
require("..")(options, (err, stats) => {
|
||||||
const deprecations = deprecationTracker();
|
const deprecations = deprecationTracker();
|
||||||
if (err) return handleFatalError(err, done);
|
if (err) return handleFatalError(err, done);
|
||||||
const statOptions = {
|
const statOptions = {
|
||||||
|
|
|
||||||
|
|
@ -5,38 +5,13 @@ const fs = require("graceful-fs");
|
||||||
const vm = require("vm");
|
const vm = require("vm");
|
||||||
const { pathToFileURL, URL } = require("url");
|
const { pathToFileURL, URL } = require("url");
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
const webpack = require("..");
|
|
||||||
const TerserPlugin = require("terser-webpack-plugin");
|
|
||||||
const checkArrayExpectation = require("./checkArrayExpectation");
|
const checkArrayExpectation = require("./checkArrayExpectation");
|
||||||
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
const deprecationTracking = require("./helpers/deprecationTracking");
|
const deprecationTracking = require("./helpers/deprecationTracking");
|
||||||
const captureStdio = require("./helpers/captureStdio");
|
const captureStdio = require("./helpers/captureStdio");
|
||||||
const asModule = require("./helpers/asModule");
|
const asModule = require("./helpers/asModule");
|
||||||
|
|
||||||
const terserForTesting = new TerserPlugin({
|
const webpack = require("..");
|
||||||
parallel: false
|
|
||||||
});
|
|
||||||
|
|
||||||
const DEFAULT_OPTIMIZATIONS = {
|
|
||||||
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]
|
|
||||||
};
|
|
||||||
|
|
||||||
const NO_EMIT_ON_ERRORS_OPTIMIZATIONS = {
|
|
||||||
emitOnErrors: true,
|
|
||||||
minimizer: [terserForTesting]
|
|
||||||
};
|
|
||||||
|
|
||||||
const casesPath = path.join(__dirname, "cases");
|
const casesPath = path.join(__dirname, "cases");
|
||||||
let categories = fs.readdirSync(casesPath);
|
let categories = fs.readdirSync(casesPath);
|
||||||
|
|
@ -100,6 +75,10 @@ const describeCases = config => {
|
||||||
if (fs.existsSync(testConfigPath)) {
|
if (fs.existsSync(testConfigPath)) {
|
||||||
testConfig = require(testConfigPath);
|
testConfig = require(testConfigPath);
|
||||||
}
|
}
|
||||||
|
const TerserPlugin = require("terser-webpack-plugin");
|
||||||
|
const terserForTesting = new TerserPlugin({
|
||||||
|
parallel: false
|
||||||
|
});
|
||||||
const options = {
|
const options = {
|
||||||
context: casesPath,
|
context: casesPath,
|
||||||
entry: "./" + category.name + "/" + testName + "/",
|
entry: "./" + category.name + "/" + testName + "/",
|
||||||
|
|
@ -108,11 +87,24 @@ const describeCases = config => {
|
||||||
mode: config.mode || "none",
|
mode: config.mode || "none",
|
||||||
optimization: config.mode
|
optimization: config.mode
|
||||||
? {
|
? {
|
||||||
...NO_EMIT_ON_ERRORS_OPTIMIZATIONS,
|
emitOnErrors: true,
|
||||||
|
minimizer: [terserForTesting],
|
||||||
...config.optimization
|
...config.optimization
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
...DEFAULT_OPTIMIZATIONS,
|
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
|
...config.optimization
|
||||||
},
|
},
|
||||||
performance: {
|
performance: {
|
||||||
|
|
@ -197,6 +189,10 @@ const describeCases = config => {
|
||||||
...(config.module ? { outputModule: true } : {})
|
...(config.module ? { outputModule: true } : {})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const cleanups = [];
|
||||||
|
afterAll(() => {
|
||||||
|
for (const fn of cleanups) fn();
|
||||||
|
});
|
||||||
beforeAll(done => {
|
beforeAll(done => {
|
||||||
rimraf(cacheDirectory, done);
|
rimraf(cacheDirectory, done);
|
||||||
});
|
});
|
||||||
|
|
@ -340,6 +336,7 @@ const describeCases = config => {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
cleanups.push(() => (esmContext.it = undefined));
|
||||||
function _require(module, esmMode) {
|
function _require(module, esmMode) {
|
||||||
if (module.substr(0, 2) === "./") {
|
if (module.substr(0, 2) === "./") {
|
||||||
const p = path.join(outputDirectory, module);
|
const p = path.join(outputDirectory, module);
|
||||||
|
|
@ -364,6 +361,7 @@ const describeCases = config => {
|
||||||
return await asModule(result, module.context);
|
return await asModule(result, module.context);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
cleanups.push(() => (esmContext.it = undefined));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
e.message += `\nwhile parsing ${p}`;
|
e.message += `\nwhile parsing ${p}`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue