Skip to content

Commit

Permalink
- Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KTruong008 authored and Kyle Truong committed Jul 7, 2017
1 parent bfd5ed9 commit 4378c92
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Compiler.js
Expand Up @@ -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) {
Expand Down
57 changes: 57 additions & 0 deletions test/Compiler.test.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/NodeWatchFileSystem.test.js
Expand Up @@ -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();
Expand Down

0 comments on commit 4378c92

Please sign in to comment.