Skip to content

Commit 03f6495

Browse files
ibashjoshwiens
authored andcommitted
feat(webpack): add webpack blocker
- Prevents karma from running tests until build is finished
1 parent 67d8845 commit 03f6495

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

index.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var webpackDevMiddleware = require("webpack-dev-middleware");
55
var webpack = require("webpack");
66
var SingleEntryDependency = require("webpack/lib/dependencies/SingleEntryDependency");
77

8+
var blocked = []
9+
var isBlocked = false
10+
811
function Plugin(
912
webpackOptions, /* config.webpack */
1013
webpackServerOptions, /* config.webpackServer */
@@ -61,6 +64,10 @@ function Plugin(
6164
compiler.plugin("make", this.make.bind(this));
6265
}, this);
6366

67+
compiler.plugin("compile", function() {
68+
isBlocked = true
69+
})
70+
6471
compiler.plugin("done", function(stats) {
6572
var applyStats = Array.isArray(stats.stats) ? stats.stats : [stats];
6673
var assets = [];
@@ -84,6 +91,12 @@ function Plugin(
8491
cb();
8592
});
8693
}
94+
95+
isBlocked = false
96+
for (var i = 0; i < blocked.length; i++) {
97+
blocked[i]();
98+
}
99+
blocked = []
87100
}.bind(this));
88101
compiler.plugin("invalid", function() {
89102
if(!this.waiting) this.waiting = [];
@@ -188,7 +201,18 @@ function createPreprocesor( /* config.basePath */ basePath, webpackPlugin) {
188201
};
189202
}
190203

204+
function createWebpackBlocker() {
205+
return function (request, response, next) {
206+
if (isBlocked) {
207+
blocked.push(next)
208+
} else {
209+
next()
210+
}
211+
}
212+
}
213+
191214
module.exports = {
192215
"webpackPlugin": ["type", Plugin],
193-
"preprocessor:webpack": ["factory", createPreprocesor]
216+
"preprocessor:webpack": ["factory", createPreprocesor],
217+
"middleware:webpackBlocker": ["factory", createWebpackBlocker]
194218
};

0 commit comments

Comments
 (0)