Skip to content

Commit

Permalink
Merge pull request #7279 from cokencode/progress-plugin-bug-fix
Browse files Browse the repository at this point in the history
Fix a bug where ProgressPlugin is not working properly with MultiComp…
  • Loading branch information
sokra committed May 26, 2018
2 parents 4073814 + 9c0036b commit ae6c7a4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ProgressPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ProgressPlugin {
const states = new Array(compiler.compilers.length);
compiler.compilers.forEach((compiler, idx) => {
new ProgressPlugin((p, msg, ...args) => {
states[idx] = args;
states[idx] = [p, msg, ...args];
handler(
states
.map(state => (state && state[0]) || 0)
Expand Down
40 changes: 40 additions & 0 deletions test/ProgressPlugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";

const path = require("path");
const MemoryFs = require("memory-fs");
const webpack = require("../");

const createMultiCompiler = () => {
const compiler = webpack([
{
context: path.join(__dirname, "fixtures"),
entry: "./a.js"
},
{
context: path.join(__dirname, "fixtures"),
entry: "./b.js"
}
]);
compiler.outputFileSystem = new MemoryFs();
return compiler;
};

describe("ProgressPlugin", function() {
it("should not contain NaN as a percentage when it is applied to MultiCompiler", function(done) {
const compiler = createMultiCompiler();

let percentage = 0;
new webpack.ProgressPlugin((p, msg, ...args) => {
percentage += p;
}).apply(compiler);

compiler.run(err => {
if (err) {
throw err;
} else {
expect(percentage).not.toBe(NaN);
done();
}
});
});
});

0 comments on commit ae6c7a4

Please sign in to comment.