Skip to content

Commit

Permalink
Merge pull request #767 from apancutt/master
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r authored Apr 7, 2021
2 parents 5cdefda + 4d15b03 commit 9d1c4e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ module.exports = {
);
}
try {
this.webpackConfig = require(webpackConfigFilePath);
const webpackConfig = require(webpackConfigFilePath);
this.webpackConfig = webpackConfig.default || webpackConfig;
} catch (err) {
this.serverless.cli.log(`Could not load webpack config '${webpackConfigFilePath}'`);
return BbPromise.reject(err);
Expand Down
24 changes: 24 additions & 0 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ describe('validate', () => {
});
});

it('should interop default when webpack config is exported as an ES6 module', () => {
const testConfig = 'testconfig';
const testServicePath = 'testpath';
const requiredPath = path.join(testServicePath, testConfig);
module.serverless.config.servicePath = testServicePath;
module.serverless.service.custom.webpack = testConfig;
serverless.utils.fileExistsSync = sinon.stub().returns(true);
const loadedConfig = {
default: {
entry: 'testentry'
}
};
mockery.registerMock(requiredPath, loadedConfig);
return expect(module.validate())
.to.fulfilled.then(() => {
expect(serverless.utils.fileExistsSync).to.have.been.calledWith(requiredPath);
expect(module.webpackConfig).to.eql(loadedConfig.default);
return null;
})
.finally(() => {
mockery.deregisterMock(requiredPath);
});
});

it('should catch errors while loading a async webpack config from file if `custom.webpack` is a string', () => {
const testConfig = 'testconfig';
const testServicePath = 'testpath';
Expand Down

0 comments on commit 9d1c4e9

Please sign in to comment.