Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actually fixed readFile (windows) #225

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions src/karma-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function Plugin(
/* config.files */ files,
/* config.frameworks */ frameworks,
customFileHandlers,
emitter) {
emitter
) {
webpackOptions = _.clone(webpackOptions) || {}
webpackMiddlewareOptions = _.clone(webpackMiddlewareOptions || webpackServerOptions) || {}

Expand Down Expand Up @@ -183,7 +184,7 @@ Plugin.prototype.readFile = function(file, callback) {
var middleware = this.middleware
var optionsCount = this.optionsCount

function doRead() {
var doRead = function() {
if (optionsCount > 1) {
async.times(optionsCount, function(idx, callback) {
middleware.fileSystem.readFile('/_karma_webpack_/' + idx + '/' + file.replace(/\\/g, '/'), callback)
Expand All @@ -202,20 +203,27 @@ Plugin.prototype.readFile = function(file, callback) {
callback(null, Buffer.concat(contents))
})
} else {
middleware.fileSystem.readFile('/_karma_webpack_/' + file.replace(/\\/g, '/'), callback)
}
}
if (!this.waiting) {
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
try {
var fileContents = middleware.fileSystem.readFileSync('/_karma_webpack_/' + file.replace(/\\/g, '/'))

callback(undefined, fileContents)
} catch (e) {
// If this is an error from `readFileSync` method, wait for the next tick.
// Credit #69 @mewdriller
if (e.code === 'ENOENT') {
// eslint-disable-line quotes
this.waiting = [process.nextTick.bind(process, this.readFile.bind(this, file, callback))]

// throw otherwise
} else {
callback(e)
}
}
}
}.bind(this)

if (!this.waiting) {
doRead()
} else {
// Retry to read once a build is finished
// do it on process.nextTick to catch changes while building
Expand Down