Skip to content

Commit 1696bfd

Browse files
daKmoRmatthieu-foucault
authored andcommitted
fix(karma-webpack): disable karma watch; use webpack watch only (#386)
1 parent 288a8c2 commit 1696bfd

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module.exports = (config) => {
3737

3838
files: [
3939
// all files ending in ".test.js"
40-
'test/**/*.test.js',
40+
// !!! use watched: false as we use webpacks watch
41+
{ pattern: 'test/**/*.test.js', watched: false }
4142
],
4243

4344
preprocessors: {

lib/KarmaWebpackController.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class KarmaWebpackController {
108108
constructor() {
109109
this.isActive = false;
110110
this.bundlesContent = {};
111-
this.__debounce = false;
111+
this.hasBeenBuiltAtLeastOnce = false;
112112
this.webpackOptions = defaultWebpackOptions;
113113
}
114114

@@ -117,7 +117,7 @@ class KarmaWebpackController {
117117
}
118118

119119
async bundle() {
120-
if (this.isActive === false && this.__debounce === false) {
120+
if (this.isActive === false && this.hasBeenBuiltAtLeastOnce === false) {
121121
console.log('Webpack bundling...');
122122
this._activePromise = this._bundle();
123123
}
@@ -126,7 +126,6 @@ class KarmaWebpackController {
126126

127127
async _bundle() {
128128
this.isActive = true;
129-
this.__debounce = true;
130129
this.compiler = webpack(this.webpackOptions);
131130
return new Promise((resolve) => {
132131
if (this.webpackOptions.watch === true) {
@@ -159,8 +158,8 @@ class KarmaWebpackController {
159158
console.warn(info.warnings);
160159
}
161160

162-
this.__debounce = setTimeout(() => (this.__debounce = false), 100);
163161
this.isActive = false;
162+
this.hasBeenBuiltAtLeastOnce = true;
164163

165164
console.log(stats.toString(this.webpackOptions.stats));
166165
resolve();

lib/karma-webpack.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function configToWebpackEntries(config) {
4242
const { preprocessors } = config;
4343

4444
let files = [];
45-
config.files.forEach((fileEntry) => {
45+
config.files.forEach((fileEntry, i) => {
46+
// forcefully disable karma watch as we use webpack watch only
47+
config.files[i].watched = false;
4648
files = [...files, ...glob.sync(fileEntry.pattern)];
4749
});
4850

0 commit comments

Comments
 (0)