Skip to content

Commit 9d1c4e9

Browse files
authored
Merge pull request #767 from apancutt/master
2 parents 5cdefda + 4d15b03 commit 9d1c4e9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/validate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ module.exports = {
131131
);
132132
}
133133
try {
134-
this.webpackConfig = require(webpackConfigFilePath);
134+
const webpackConfig = require(webpackConfigFilePath);
135+
this.webpackConfig = webpackConfig.default || webpackConfig;
135136
} catch (err) {
136137
this.serverless.cli.log(`Could not load webpack config '${webpackConfigFilePath}'`);
137138
return BbPromise.reject(err);

tests/validate.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,30 @@ describe('validate', () => {
271271
});
272272
});
273273

274+
it('should interop default when webpack config is exported as an ES6 module', () => {
275+
const testConfig = 'testconfig';
276+
const testServicePath = 'testpath';
277+
const requiredPath = path.join(testServicePath, testConfig);
278+
module.serverless.config.servicePath = testServicePath;
279+
module.serverless.service.custom.webpack = testConfig;
280+
serverless.utils.fileExistsSync = sinon.stub().returns(true);
281+
const loadedConfig = {
282+
default: {
283+
entry: 'testentry'
284+
}
285+
};
286+
mockery.registerMock(requiredPath, loadedConfig);
287+
return expect(module.validate())
288+
.to.fulfilled.then(() => {
289+
expect(serverless.utils.fileExistsSync).to.have.been.calledWith(requiredPath);
290+
expect(module.webpackConfig).to.eql(loadedConfig.default);
291+
return null;
292+
})
293+
.finally(() => {
294+
mockery.deregisterMock(requiredPath);
295+
});
296+
});
297+
274298
it('should catch errors while loading a async webpack config from file if `custom.webpack` is a string', () => {
275299
const testConfig = 'testconfig';
276300
const testServicePath = 'testpath';

0 commit comments

Comments
 (0)