Skip to content

Commit 4378c92

Browse files
kylebuildsstuffKyle Truong
authored andcommitted
- Add more tests
1 parent bfd5ed9 commit 4378c92

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

lib/Compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ module.exports = class Compiler extends Tapable {
215215
}
216216

217217
static Watching(compiler, watchOptions, handler) {
218-
return Watching(compiler, watchOptions, handler);
218+
return new Watching(compiler, watchOptions, handler);
219219
}
220220

221221
watch(watchOptions, handler) {

test/Compiler.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const sinon = require("sinon");
77

88
const webpack = require("../");
99
const WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
10+
const Compiler = require("../lib/Compiler");
1011

1112
describe("Compiler", () => {
1213
function compile(entry, options, callback) {
@@ -164,6 +165,29 @@ describe("Compiler", () => {
164165
done();
165166
});
166167
});
168+
describe("constructor", () => {
169+
let compiler;
170+
beforeEach(() => {
171+
compiler = webpack({
172+
entry: "./c",
173+
context: path.join(__dirname, "fixtures"),
174+
output: {
175+
path: "/",
176+
pathinfo: true,
177+
}
178+
});
179+
});
180+
describe("parser", () => {
181+
describe("apply", () => {
182+
it("invokes sets a 'compilation' plugin", (done) => {
183+
compiler.plugin = sinon.spy();
184+
compiler.parser.apply();
185+
compiler.plugin.callCount.should.be.exactly(1);
186+
done();
187+
});
188+
});
189+
});
190+
});
167191
describe("methods", () => {
168192
let compiler;
169193
beforeEach(() => {
@@ -236,6 +260,31 @@ describe("Compiler", () => {
236260
done();
237261
});
238262
});
263+
describe("createChildCompiler", () => {
264+
it("defaults cache.children if none exists yet", (done) => {
265+
const mockPlugin = sinon.spy();
266+
class fakePlugin {
267+
apply() {
268+
mockPlugin();
269+
}
270+
}
271+
compiler.cache = {};
272+
compiler.createChildCompiler({}, "compiler9000", 0, {}, [new fakePlugin()]);
273+
mockPlugin.callCount.should.be.exactly(1);
274+
compiler.cache.children.should.match({});
275+
done();
276+
});
277+
it("defaults cache.children[compilerName] if none exists yet", (done) => {
278+
compiler.cache = {
279+
children: {},
280+
};
281+
compiler.createChildCompiler({}, "compiler9000", 0, {}, null);
282+
compiler.cache.children.should.match({
283+
compiler9000: [],
284+
});
285+
done();
286+
});
287+
});
239288
});
240289
describe("Watching", () => {
241290
let compiler;
@@ -249,6 +298,14 @@ describe("Compiler", () => {
249298
}
250299
});
251300
});
301+
describe("static method", () => {
302+
it("should have an accessible static method, Watching", (done) => {
303+
const actual = Compiler.Watching(compiler, 1000, err => err);
304+
actual.running.should.be.exactly(true);
305+
actual.constructor.name.should.be.exactly("Watching");
306+
done();
307+
});
308+
});
252309
describe("constructor", () => {
253310
it("constructs Watching.watchOptions correctly when passed a number, string, or object for watchOptions", (done) => {
254311
const Watching1 = compiler.watch(1000, err => err);

test/NodeWatchFileSystem.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("NodeWatchFileSystem", function() {
5757
var fileDirect = path.join(fixtures, "watched-file.txt");
5858
var fileSubdir = path.join(fixtures, "subdir", "watched-file.txt");
5959

60-
this.timeout(10000);
60+
this.timeout(20000);
6161

6262
it("should register a file change (change delayed)", function(done) {
6363
var startTime = new Date().getTime();

0 commit comments

Comments
 (0)