Skip to content

Commit

Permalink
fix(karma-webpack): disable karma watch; use webpack watch only (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
daKmoR authored and matthieu-foucault committed Jan 1, 2019
1 parent 288a8c2 commit 1696bfd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = (config) => {

files: [
// all files ending in ".test.js"
'test/**/*.test.js',
// !!! use watched: false as we use webpacks watch
{ pattern: 'test/**/*.test.js', watched: false }
],

preprocessors: {
Expand Down
7 changes: 3 additions & 4 deletions lib/KarmaWebpackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class KarmaWebpackController {
constructor() {
this.isActive = false;
this.bundlesContent = {};
this.__debounce = false;
this.hasBeenBuiltAtLeastOnce = false;
this.webpackOptions = defaultWebpackOptions;
}

Expand All @@ -117,7 +117,7 @@ class KarmaWebpackController {
}

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

async _bundle() {
this.isActive = true;
this.__debounce = true;
this.compiler = webpack(this.webpackOptions);
return new Promise((resolve) => {
if (this.webpackOptions.watch === true) {
Expand Down Expand Up @@ -159,8 +158,8 @@ class KarmaWebpackController {
console.warn(info.warnings);
}

this.__debounce = setTimeout(() => (this.__debounce = false), 100);
this.isActive = false;
this.hasBeenBuiltAtLeastOnce = true;

console.log(stats.toString(this.webpackOptions.stats));
resolve();
Expand Down
4 changes: 3 additions & 1 deletion lib/karma-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function configToWebpackEntries(config) {
const { preprocessors } = config;

let files = [];
config.files.forEach((fileEntry) => {
config.files.forEach((fileEntry, i) => {
// forcefully disable karma watch as we use webpack watch only
config.files[i].watched = false;
files = [...files, ...glob.sync(fileEntry.pattern)];
});

Expand Down

0 comments on commit 1696bfd

Please sign in to comment.