Skip to content

Commit 466581f

Browse files
vinteojoshwiens
authored andcommitted
fix: pass on error to callback for better error messages (#262)
1 parent 9e35089 commit 466581f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/karma-webpack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Plugin.prototype.make = function(compilation, callback) {
175175

176176
var dep = new SingleEntryDependency(entry)
177177

178-
compilation.addEntry('', dep, path.relative(this.basePath, file).replace(/\\/g, '/'), function() {
178+
compilation.addEntry('', dep, path.relative(this.basePath, file).replace(/\\/g, '/'), function(err) {
179179
// If the module fails because of an File not found error, remove the test file
180180
if (dep.module && dep.module.error &&
181181
dep.module.error.error &&
@@ -185,7 +185,7 @@ Plugin.prototype.make = function(compilation, callback) {
185185
})
186186
this.middleware.invalidate()
187187
}
188-
callback()
188+
callback(err)
189189
}.bind(this))
190190
}.bind(this), callback)
191191
}

test/unit/plugin.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {assert} from 'chai'
2+
import {webpackPlugin} from '../../src/karma-webpack'
3+
4+
describe('Plugin', function() {
5+
describe('#make()', function() {
6+
it('should pass through error from compilation', function(done) {
7+
var emitterMock = {
8+
on() {}
9+
}
10+
var compilationMock = {
11+
addEntry(name, dep, file, cb) {
12+
cb(new Error('test error'))
13+
}
14+
}
15+
var Plugin = new webpackPlugin[1]({}, {}, {}, '', [], [], [], emitterMock)
16+
17+
Plugin.addFile('test.js')
18+
Plugin.make(compilationMock, function(err) {
19+
assert.equal(err.message, 'test error')
20+
done()
21+
})
22+
})
23+
})
24+
})

0 commit comments

Comments
 (0)