Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve CI stability #13729

Merged
merged 8 commits into from Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/hmr/lazyCompilationBackend.js
Expand Up @@ -20,7 +20,7 @@ module.exports = (compiler, client, callback) => {
const activeModules = new Map();
const prefix = "/lazy-compilation-using-";

const server = http.createServer((req, res) => {
const requestListener = (req, res) => {
const keys = req.url.slice(prefix.length).split("@");
req.socket.on("close", () => {
setTimeout(() => {
Expand Down Expand Up @@ -51,7 +51,8 @@ module.exports = (compiler, client, callback) => {
}
}
if (moduleActivated && compiler.watching) compiler.watching.invalidate();
});
};
const server = http.createServer(requestListener);
let isClosing = false;
/** @type {Set<import("net").Socket>} */
const sockets = new Set();
Expand All @@ -78,6 +79,8 @@ module.exports = (compiler, client, callback) => {
callback(null, {
dispose(callback) {
isClosing = true;
// Removing the listener is a workaround for a memory leak in node.js
server.off("request", requestListener);
server.close(err => {
callback(err);
});
Expand Down
95 changes: 58 additions & 37 deletions test/Compiler.test.js
Expand Up @@ -64,10 +64,23 @@ describe("Compiler", () => {
throw stats.errors[0];
}
stats.logs = logs;
callback(stats, files, compilation);
c.close(err => {
if (err) return callback(err);
callback(stats, files, compilation);
});
});
}

let compiler;
afterEach(callback => {
if (compiler) {
compiler.close(callback);
compiler = undefined;
} else {
callback();
}
});

it("should compile a single file to deep output", done => {
compile(
"./c",
Expand Down Expand Up @@ -202,6 +215,14 @@ describe("Compiler", () => {
}
});
});
afterEach(callback => {
if (compiler) {
compiler.close(callback);
compiler = undefined;
} else {
callback();
}
});
describe("purgeInputFileSystem", () => {
it("invokes purge() if inputFileSystem.purge", done => {
const mockPurge = jest.fn();
Expand Down Expand Up @@ -264,7 +285,7 @@ describe("Compiler", () => {
});
});
it("should not emit on errors", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./missing",
Expand Down Expand Up @@ -296,9 +317,10 @@ describe("Compiler", () => {
resolve(stats);
}
});
return c;
});
};
const compiler = await createCompiler({
compiler = await createCompiler({
context: __dirname,
mode: "production",
entry: "./missing-file",
Expand All @@ -309,7 +331,6 @@ describe("Compiler", () => {
bail: true
});
done();
return compiler;
} catch (err) {
expect(err.toString()).toMatch(
"ModuleNotFoundError: Module not found: Error: Can't resolve './missing-file'"
Expand All @@ -319,7 +340,7 @@ describe("Compiler", () => {
});
it("should not emit compilation errors in async (watch)", async done => {
try {
const createCompiler = options => {
const createStats = options => {
return new Promise((resolve, reject) => {
const c = webpack(options);
c.outputFileSystem = createFsFromVolume(new Volume());
Expand All @@ -331,7 +352,7 @@ describe("Compiler", () => {
});
});
};
const compiler = await createCompiler({
const stats = await createStats({
context: __dirname,
mode: "production",
entry: "./missing-file",
Expand All @@ -340,15 +361,15 @@ describe("Compiler", () => {
filename: "bundle.js"
}
});
expect(compiler).toBeInstanceOf(Stats);
expect(stats).toBeInstanceOf(Stats);
done();
} catch (err) {
done(err);
}
});

it("should not emit on errors (watch)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./missing",
Expand All @@ -367,7 +388,7 @@ describe("Compiler", () => {
});
});
it("should not be running twice at a time (run)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -385,7 +406,7 @@ describe("Compiler", () => {
});
});
it("should not be running twice at a time (watch)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -403,7 +424,7 @@ describe("Compiler", () => {
});
});
it("should not be running twice at a time (run - watch)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -421,7 +442,7 @@ describe("Compiler", () => {
});
});
it("should not be running twice at a time (watch - run)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -439,7 +460,7 @@ describe("Compiler", () => {
});
});
it("should not be running twice at a time (instance cb)", done => {
const compiler = webpack(
compiler = webpack(
{
context: __dirname,
mode: "production",
Expand All @@ -457,7 +478,7 @@ describe("Compiler", () => {
});
});
it("should run again correctly after first compilation", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -478,7 +499,7 @@ describe("Compiler", () => {
});
});
it("should watch again correctly after first compilation", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -491,14 +512,14 @@ describe("Compiler", () => {
compiler.run((err, stats) => {
if (err) return done(err);

compiler.watch({}, (err, stats) => {
const watching = compiler.watch({}, (err, stats) => {
if (err) return done(err);
done();
watching.close(done);
});
});
});
it("should run again correctly after first closed watch", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -519,7 +540,7 @@ describe("Compiler", () => {
});
});
it("should set compiler.watching correctly", function (done) {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -531,12 +552,12 @@ describe("Compiler", () => {
compiler.outputFileSystem = createFsFromVolume(new Volume());
const watching = compiler.watch({}, (err, stats) => {
if (err) return done(err);
done();
watching.close(done);
});
expect(compiler.watching).toBe(watching);
});
it("should watch again correctly after first closed watch", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -557,7 +578,7 @@ describe("Compiler", () => {
});
});
it("should run again correctly inside afterDone hook", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -581,7 +602,7 @@ describe("Compiler", () => {
});
});
it("should call afterDone hook after other callbacks (run)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -606,7 +627,7 @@ describe("Compiler", () => {
});
it("should call afterDone hook after other callbacks (instance cb)", done => {
const instanceCb = jest.fn();
const compiler = webpack(
compiler = webpack(
{
context: __dirname,
mode: "production",
Expand All @@ -631,7 +652,7 @@ describe("Compiler", () => {
});
});
it("should call afterDone hook after other callbacks (watch)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -652,18 +673,18 @@ describe("Compiler", () => {
expect(doneHookCb).toHaveBeenCalled();
expect(watchCb).toHaveBeenCalled();
expect(invalidateCb).toHaveBeenCalled();
done();
watching.close(done);
});
const watch = compiler.watch({}, (err, stats) => {
const watching = compiler.watch({}, (err, stats) => {
if (err) return done(err);
watchCb();
});
process.nextTick(() => {
watch.invalidate(invalidateCb);
watching.invalidate(invalidateCb);
});
});
it("should call afterDone hook after other callbacks (watch close)", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand Down Expand Up @@ -695,7 +716,7 @@ describe("Compiler", () => {
});
});
it("should flag watchMode as true in watch", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "production",
entry: "./c",
Expand All @@ -717,7 +738,7 @@ describe("Compiler", () => {
});
});
it("should use cache on second run call", done => {
const compiler = webpack({
compiler = webpack({
context: __dirname,
mode: "development",
devtool: false,
Expand All @@ -740,7 +761,7 @@ describe("Compiler", () => {
});
it("should call the failed-hook on error", done => {
const failedSpy = jest.fn();
const compiler = webpack({
compiler = webpack({
bail: true,
context: __dirname,
mode: "production",
Expand Down Expand Up @@ -803,7 +824,7 @@ describe("Compiler", () => {
}
}
it("should log to the console (verbose)", done => {
const compiler = webpack({
compiler = webpack({
context: path.join(__dirname, "fixtures"),
entry: "./a",
output: {
Expand Down Expand Up @@ -833,7 +854,7 @@ describe("Compiler", () => {
});
});
it("should log to the console (debug mode)", done => {
const compiler = webpack({
compiler = webpack({
context: path.join(__dirname, "fixtures"),
entry: "./a",
output: {
Expand Down Expand Up @@ -865,7 +886,7 @@ describe("Compiler", () => {
});
});
it("should log to the console (none)", done => {
const compiler = webpack({
compiler = webpack({
context: path.join(__dirname, "fixtures"),
entry: "./a",
output: {
Expand All @@ -884,7 +905,7 @@ describe("Compiler", () => {
});
});
it("should log to the console with colors (verbose)", done => {
const compiler = webpack({
compiler = webpack({
context: path.join(__dirname, "fixtures"),
entry: "./a",
output: {
Expand Down Expand Up @@ -915,7 +936,7 @@ describe("Compiler", () => {
});
});
it("should log to the console with colors (debug mode)", done => {
const compiler = webpack({
compiler = webpack({
context: path.join(__dirname, "fixtures"),
entry: "./a",
output: {
Expand Down