From 907ed729f40c8658437f77c8e42212ac9d916625 Mon Sep 17 00:00:00 2001 From: Joshua Wiens Date: Thu, 19 Jan 2017 00:24:30 -0600 Subject: [PATCH] fix(readFile): handle path doesn't exist error (#208) --- src/karma-webpack.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/karma-webpack.js b/src/karma-webpack.js index 35610a3..758189e 100644 --- a/src/karma-webpack.js +++ b/src/karma-webpack.js @@ -30,7 +30,7 @@ function Plugin( // Webpack 2.1.0-beta.7+ will throw in error if both entry and plugins are not specified in options // https://github.com/webpack/webpack/commit/b3bc5427969e15fd3663d9a1c57dbd1eb2c94805 if (!webpackOptions.entry) { - webpackOptions.entry = function(){ + webpackOptions.entry = function() { return {} } }; @@ -206,7 +206,16 @@ Plugin.prototype.readFile = function(file, callback) { } } if (!this.waiting) { - doRead() + try { + doRead() + } catch (e) { + // If this is an error from `readFileSync` method, wait for the next tick. Credit #69 @mewdriller + if (e.message.substring(0, 20) === "Path doesn't exist '") { // eslint-disable-line quotes + this.waiting = [process.nextTick.bind(process, this.readFile.bind(this, file, callback))] + } else { + throw e + } + } } else { // Retry to read once a build is finished // do it on process.nextTick to catch changes while building