Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ module.exports = {
throw new this.serverless.classes
.Error('The webpack plugin could not find the configuration file at: ' + webpackConfigFilePath);
}
this.webpackConfig = require(webpackConfigFilePath);
try {
this.webpackConfig = require(webpackConfigFilePath);
} catch (err) {
this.serverless.cli.log(`Could not load webpack config '${webpackConfigFilePath}'`);
return BbPromise.reject(err);
}
}

// Default context
Expand Down
10 changes: 10 additions & 0 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ describe('validate', () => {
return null;
});
});

it('should fail when importing a broken configuration file', () => {
const testConfig = 'invalid.webpack.config.js';
const testServicePath = 'testpath';
module.serverless.config.servicePath = testServicePath;
module.serverless.service.custom.webpack = testConfig;
serverless.utils.fileExistsSync = sinon.stub().returns(true);
return expect(module.validate()).to.be.rejected
.then(() => expect(serverless.cli.log).to.have.been.calledWith(sinon.match(/^Could not load webpack config/)));
});
});

describe('lib', () => {
Expand Down