diff --git a/lib/Compiler.js b/lib/Compiler.js index 6c1bb66ba34..e8a03b70661 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -215,7 +215,7 @@ module.exports = class Compiler extends Tapable { } static Watching(compiler, watchOptions, handler) { - return Watching(compiler, watchOptions, handler); + return new Watching(compiler, watchOptions, handler); } watch(watchOptions, handler) { diff --git a/test/Compiler.test.js b/test/Compiler.test.js index 5ee04b3c92d..99439e1c0bb 100644 --- a/test/Compiler.test.js +++ b/test/Compiler.test.js @@ -7,6 +7,7 @@ const sinon = require("sinon"); const webpack = require("../"); const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter"); +const Compiler = require("../lib/Compiler"); describe("Compiler", () => { function compile(entry, options, callback) { @@ -164,6 +165,29 @@ describe("Compiler", () => { done(); }); }); + describe("constructor", () => { + let compiler; + beforeEach(() => { + compiler = webpack({ + entry: "./c", + context: path.join(__dirname, "fixtures"), + output: { + path: "/", + pathinfo: true, + } + }); + }); + describe("parser", () => { + describe("apply", () => { + it("invokes sets a 'compilation' plugin", (done) => { + compiler.plugin = sinon.spy(); + compiler.parser.apply(); + compiler.plugin.callCount.should.be.exactly(1); + done(); + }); + }); + }); + }); describe("methods", () => { let compiler; beforeEach(() => { @@ -236,6 +260,31 @@ describe("Compiler", () => { done(); }); }); + describe("createChildCompiler", () => { + it("defaults cache.children if none exists yet", (done) => { + const mockPlugin = sinon.spy(); + class fakePlugin { + apply() { + mockPlugin(); + } + } + compiler.cache = {}; + compiler.createChildCompiler({}, "compiler9000", 0, {}, [new fakePlugin()]); + mockPlugin.callCount.should.be.exactly(1); + compiler.cache.children.should.match({}); + done(); + }); + it("defaults cache.children[compilerName] if none exists yet", (done) => { + compiler.cache = { + children: {}, + }; + compiler.createChildCompiler({}, "compiler9000", 0, {}, null); + compiler.cache.children.should.match({ + compiler9000: [], + }); + done(); + }); + }); }); describe("Watching", () => { let compiler; @@ -249,6 +298,14 @@ describe("Compiler", () => { } }); }); + describe("static method", () => { + it("should have an accessible static method, Watching", (done) => { + const actual = Compiler.Watching(compiler, 1000, err => err); + actual.running.should.be.exactly(true); + actual.constructor.name.should.be.exactly("Watching"); + done(); + }); + }); describe("constructor", () => { it("constructs Watching.watchOptions correctly when passed a number, string, or object for watchOptions", (done) => { const Watching1 = compiler.watch(1000, err => err); diff --git a/test/NodeWatchFileSystem.test.js b/test/NodeWatchFileSystem.test.js index c684445dd81..b442f2d9421 100644 --- a/test/NodeWatchFileSystem.test.js +++ b/test/NodeWatchFileSystem.test.js @@ -57,7 +57,7 @@ describe("NodeWatchFileSystem", function() { var fileDirect = path.join(fixtures, "watched-file.txt"); var fileSubdir = path.join(fixtures, "subdir", "watched-file.txt"); - this.timeout(10000); + this.timeout(20000); it("should register a file change (change delayed)", function(done) { var startTime = new Date().getTime();