2017-12-29 18:23:14 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/* globals describe it */
|
|
|
|
const path = require("path");
|
|
|
|
const should = require("should");
|
|
|
|
const MemoryFs = require("memory-fs");
|
|
|
|
const webpack = require("../");
|
|
|
|
|
|
|
|
const createMultiCompiler = () => {
|
2018-02-25 09:00:20 +08:00
|
|
|
const compiler = webpack([
|
|
|
|
{
|
|
|
|
context: path.join(__dirname, "fixtures"),
|
|
|
|
entry: "./a.js"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
context: path.join(__dirname, "fixtures"),
|
|
|
|
entry: "./b.js"
|
|
|
|
}
|
|
|
|
]);
|
2017-12-29 18:23:14 +08:00
|
|
|
compiler.outputFileSystem = new MemoryFs();
|
|
|
|
return compiler;
|
|
|
|
};
|
|
|
|
|
|
|
|
describe("MultiCompiler", function() {
|
|
|
|
it("should trigger 'run' for each child compiler", done => {
|
|
|
|
const compiler = createMultiCompiler();
|
|
|
|
let called = 0;
|
|
|
|
|
|
|
|
compiler.hooks.run.tap("MultiCompiler test", () => called++);
|
|
|
|
compiler.run(err => {
|
2018-02-25 09:00:20 +08:00
|
|
|
if (err) {
|
2017-12-29 18:23:14 +08:00
|
|
|
throw err;
|
|
|
|
} else {
|
|
|
|
should(called).be.equal(2);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should trigger 'watchRun' for each child compiler", done => {
|
|
|
|
const compiler = createMultiCompiler();
|
|
|
|
let called = 0;
|
|
|
|
|
|
|
|
compiler.hooks.watchRun.tap("MultiCompiler test", () => called++);
|
|
|
|
const watcher = compiler.watch(1000, err => {
|
2018-02-25 09:00:20 +08:00
|
|
|
if (err) {
|
2017-12-29 18:23:14 +08:00
|
|
|
throw err;
|
|
|
|
} else {
|
|
|
|
watcher.close();
|
|
|
|
should(called).be.equal(2);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|