diff --git a/index.js b/index.js index 2a4ddd4d..77f6244c 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,10 @@ module.exports = function(source, map) { callback(null, js.code, js.map); }, err => { - this.addDependency(err.file); + const file = err.file || err.filename; + if (typeof file === 'string' && file !== this.resourcePath) { + this.addDependency(file); + } callback(err); }).catch(err => { // wrap error to provide correct diff --git a/test/loader.spec.js b/test/loader.spec.js index 6e9d4890..7e698a00 100644 --- a/test/loader.spec.js +++ b/test/loader.spec.js @@ -15,9 +15,15 @@ function d([str]) { describe('loader', () => { function testLoader(fileName, callback, query, version = 2) { return done => { - function cb() { + const addedDependencies = new Set(); + + function cb(...args) { + while (args.length < 4) { + args.push(undefined); + } + args.push(addedDependencies); try { - callback(...[].slice.call(arguments)); + callback(...args); } catch (err) { expect(callbackSpy).to.have.been.called; return done(err); @@ -32,10 +38,13 @@ describe('loader', () => { const callbackSpy = spy(cb); + const dependencySpy = spy(function(p) { addedDependencies.add(p); }); + loader.call( { cacheable: cacheableSpy, async: () => callbackSpy, + addDependency: dependencySpy, resourcePath: fileName, version, query @@ -45,6 +54,10 @@ describe('loader', () => { ); expect(cacheableSpy).to.have.been.called; + + for (const call of dependencySpy.getCalls()) { + expect(call.firstArg).to.be.a('string'); + } }; } @@ -246,23 +259,18 @@ describe('loader', () => { }); it('should not preprocess successfully', done => { - const { warn } = console; - const warnings = []; - - console.warn = msg => { - warnings.push(msg); - }; - testLoader( 'test/fixtures/style-valid.html', - (err, code, map) => { + (err, code, map, context, addedDependencies) => { expect(err).to.exist; - console.warn = warn; + expect(addedDependencies).to.include('/some/subresource.css'); }, { preprocess: { style: () => { - throw new Error('Error while preprocessing'); + const e = new Error('Error while preprocessing'); + e.filename = '/some/subresource.css'; + throw e; } } }