Skip to content

Commit

Permalink
Merge pull request #13750 from webpack/ci/memory-problems
Browse files Browse the repository at this point in the history
improve CI stablilty
  • Loading branch information
sokra committed Jul 8, 2021
2 parents 78e9a00 + 4e9bcd1 commit 1bb0db3
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 52 deletions.
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -131,10 +131,10 @@
],
"scripts": {
"setup": "node ./setup/setup.js",
"test": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest",
"test": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage",
"test:update-snapshots": "yarn jest -u",
"test:integration": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.test.js\"",
"test:basic": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\"",
"test:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"<rootDir>/test/*.test.js\"",
"test:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"<rootDir>/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\"",
"test:unit": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.unittest.js\"",
"travis:integration": "yarn cover:integration --ci $JEST",
"travis:basic": "yarn cover:basic --ci $JEST",
Expand Down Expand Up @@ -165,9 +165,9 @@
"benchmark": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand",
"cover": "yarn cover:all && yarn cover:report",
"cover:clean": "rimraf .nyc_output coverage",
"cover:all": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --coverage",
"cover:basic": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\" --coverage",
"cover:integration": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.test.js\" --coverage",
"cover:all": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --coverage",
"cover:basic": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"<rootDir>/te{st/TestCasesNormal,st/StatsTestCases,st/ConfigTestCases}.test.js\" --coverage",
"cover:integration": "node --expose-gc --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --logHeapUsage --testMatch \"<rootDir>/test/*.test.js\" --coverage",
"cover:unit": "node --max-old-space-size=4096 --experimental-vm-modules node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.unittest.js\" --coverage",
"cover:types": "node node_modules/tooling/type-coverage",
"cover:merge": "nyc merge .nyc_output coverage/coverage-nyc.json && rimraf .nyc_output",
Expand Down
11 changes: 11 additions & 0 deletions test/ConfigTestCases.template.js
Expand Up @@ -128,6 +128,12 @@ const describeCases = config => {
}
if (testConfig.timeout) setDefaultTimeout(testConfig.timeout);
});
afterAll(() => {
// cleanup
options = undefined;
optionsArr = undefined;
testConfig = undefined;
});
beforeAll(() => {
rimraf.sync(cacheDirectory);
});
Expand Down Expand Up @@ -306,6 +312,11 @@ const describeCases = config => {
esmMode,
parentModule
) => {
if (testConfig === undefined) {
throw new Error(
`_require(${module}) called after all tests have completed`
);
}
if (Array.isArray(module) || /^\.\.?\//.test(module)) {
let content;
let p;
Expand Down
9 changes: 6 additions & 3 deletions test/TestCases.template.js
Expand Up @@ -11,8 +11,6 @@ const deprecationTracking = require("./helpers/deprecationTracking");
const captureStdio = require("./helpers/captureStdio");
const asModule = require("./helpers/asModule");

const webpack = require("..");

const casesPath = path.join(__dirname, "cases");
let categories = fs.readdirSync(casesPath);
categories = categories.map(cat => {
Expand Down Expand Up @@ -79,7 +77,7 @@ const describeCases = config => {
const terserForTesting = new TerserPlugin({
parallel: false
});
const options = {
let options = {
context: casesPath,
entry: "./" + category.name + "/" + testName + "/",
target: config.target || "async-node",
Expand Down Expand Up @@ -191,6 +189,8 @@ const describeCases = config => {
};
const cleanups = [];
afterAll(() => {
options = undefined;
testConfig = undefined;
for (const fn of cleanups) fn();
});
beforeAll(done => {
Expand All @@ -206,6 +206,7 @@ const describeCases = config => {
"cache1"
);
const deprecationTracker = deprecationTracking.start();
const webpack = require("..");
webpack(options, err => {
deprecationTracker();
options.output.path = oldPath;
Expand All @@ -224,6 +225,7 @@ const describeCases = config => {
"cache2"
);
const deprecationTracker = deprecationTracking.start();
const webpack = require("..");
webpack(options, err => {
deprecationTracker();
options.output.path = oldPath;
Expand All @@ -237,6 +239,7 @@ const describeCases = config => {
it(
testName + " should compile",
done => {
const webpack = require("..");
const compiler = webpack(options);
const run = () => {
const deprecationTracker = deprecationTracking.start();
Expand Down
4 changes: 1 addition & 3 deletions test/configCases/asset-emitted/normal/index.js
@@ -1,3 +1 @@
import("./module");

it("should run", () => {});
it("should run", () => import("./module"));
18 changes: 13 additions & 5 deletions test/configCases/async-commons-chunk/existing-name/index.js
@@ -1,11 +1,17 @@
const chunkLoadingSpy = jest.spyOn(__webpack_require__, "e");

it("should not have duplicate chunks in blocks", function(done) {
it("should not have duplicate chunks in blocks", function (done) {
let i = 0;
const d = () => {
if (i++ >= 3) done();
};

// This split point should contain: a
require.ensure(
[],
function(require) {
function (require) {
expect(require("./a")).toBe("a");
d();
},
"a"
);
Expand All @@ -14,9 +20,10 @@ it("should not have duplicate chunks in blocks", function(done) {
// have it only contain b and make chunk a be an async dependency.
require.ensure(
[],
function(require) {
function (require) {
expect(require("./a")).toBe("a");
expect(require("./b")).toBe("b");
d();
},
"a+b"
);
Expand All @@ -25,10 +32,11 @@ it("should not have duplicate chunks in blocks", function(done) {
// have it only contain c and make chunks a and a+b be async dependencies.
require.ensure(
[],
function(require) {
function (require) {
expect(require("./a")).toBe("a");
expect(require("./b")).toBe("b");
expect(require("./c")).toBe("c");
d();
},
"a+b+c"
);
Expand All @@ -46,5 +54,5 @@ it("should not have duplicate chunks in blocks", function(done) {
["a+b" /* == b */],
["a+b+c" /* == c */]
]);
done();
d();
});
@@ -1,6 +1,4 @@
import "./a";
import(/* webpackChunkName: "async" */ "./async");
it("should compile", () => import(/* webpackChunkName: "async" */ "./async"));
import "./b";
import "./c";

it("should compile", () => {});
@@ -1,6 +1,4 @@
import "./c";
import(/* webpackChunkName: "async" */ "./async");
it("should compile", () => import(/* webpackChunkName: "async" */ "./async"));
import "./b";
import "./a";

it("should compile", () => {});
2 changes: 1 addition & 1 deletion test/configCases/entry/issue-12562/app.js
@@ -1 +1 @@
import("./test.js");
it("should load", () => import("./test.js"));
4 changes: 2 additions & 2 deletions test/configCases/parsing/requirejs/index.js
Expand Up @@ -9,12 +9,12 @@ it("should ignore require.config", function() {
it("should have a require.version", function() {
expect(require.version).toBeTypeOf("string");
});
it("should have a requirejs.onError function", function() {
it("should have a requirejs.onError function", function(done) {
function f(){}
expect(requirejs.onError).toBeTypeOf("undefined"); // has no default handler
var org = requirejs.onError;
requirejs.onError = f;
expect(requirejs.onError).toBe(f);
requirejs.onError = org;
require(["./file.js"], function() {});
require(["./file.js"], function() { done() });
});
20 changes: 13 additions & 7 deletions test/configCases/source-map/module-names/index.js
Expand Up @@ -5,21 +5,27 @@ function getSourceMap(filename) {
return map;
}

it("should include test.js in SourceMap", function() {
it("should include test.js in SourceMap", function () {
var allSources = new Set();
var map = getSourceMap("bundle0.js");
for(var source of map.sources) allSources.add(source);
for (var source of map.sources) allSources.add(source);
map = getSourceMap("chunk-a.js");
for(var source of map.sources) allSources.add(source);
for (var source of map.sources) allSources.add(source);
map = getSourceMap("chunk-b.js");
for(var source of map.sources) allSources.add(source);
for (var source of map.sources) allSources.add(source);
expect(allSources).toContain("module");
allSources.delete("module");
expect(allSources).toContain("fallback");
for(const source of allSources) {
for (const source of allSources) {
expect(source).toMatch(/^fallback\**$/);
}
});

require.ensure(["./test.js"], function(require) {}, "chunk-a");
require.ensure(["./test.js", "./test.js?1"], function(require) {}, "chunk-b");
if (Math.random() < 0) {
require.ensure(["./test.js"], function (require) {}, "chunk-a");
require.ensure(
["./test.js", "./test.js?1"],
function (require) {},
"chunk-b"
);
}
@@ -1,10 +1,10 @@
it("should run", function () {
Promise.all([
import(/* webpackChunkName: "a" */ "./a"),
import(/* webpackChunkName: "b" */ "./b")
]);

const files = require("fs").readdirSync(__dirname);
expect(files).toContain("a.bundle.js");
expect(files).toContain("b-b_js-c441f481.bundle.js");

return Promise.all([
import(/* webpackChunkName: "a" */ "./a"),
import(/* webpackChunkName: "b" */ "./b")
]);
});
10 changes: 5 additions & 5 deletions test/configCases/split-chunks/chunk-filename-delimiter/index.js
@@ -1,10 +1,10 @@
it("should run", function () {
Promise.all([
import(/* webpackChunkName: "a" */ "./a"),
import(/* webpackChunkName: "b" */ "./b")
]);

const files = require("fs").readdirSync(__dirname);
expect(files).toContain("a.bundle.js");
expect(files).toContain("b---b_js---c441f481.bundle.js");

return Promise.all([
import(/* webpackChunkName: "a" */ "./a"),
import(/* webpackChunkName: "b" */ "./b")
]);
});
6 changes: 2 additions & 4 deletions test/configCases/split-chunks/issue-11337/index.js
@@ -1,4 +1,2 @@
it("should compile and evaluate fine", () => {});

import("./a");
import("./b");
it("should compile and evaluate fine", () =>
Promise.all([import("./a"), import("./b")]));
6 changes: 2 additions & 4 deletions test/configCases/split-chunks/issue-11513/index.js
@@ -1,4 +1,2 @@
it("should handle mixed size types chunk in splitChunks", async () => {
import("./chunk1");
import("./chunk2");
});
it("should handle mixed size types chunk in splitChunks", () =>
Promise.all([import("./chunk1"), import("./chunk2")]));
Expand Up @@ -9,7 +9,10 @@ module.exports = {
},
target: "async-node",
output: {
filename: "[name].js"
filename: "[name].js",
library: {
type: "commonjs-module"
}
},
optimization: {
chunkIds: "named",
Expand Down

0 comments on commit 1bb0db3

Please sign in to comment.