Skip to content

Commit 4ab6e60

Browse files
mikejpetersShereef
authored andcommitted
fix: check for undefined options when validating
1 parent 964f0b3 commit 4ab6e60

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/validate.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const path = require('path');
1212
function validateClient(serverless, options) {
1313
const validationErrors = [];
1414

15+
if (!is.object(options)) {
16+
validationErrors.push('Options must be an object defined under `custom.client`');
17+
throw validationErrors;
18+
}
19+
1520
// path to website files must exist
1621
const distributionFolder = options.distributionFolder || path.join('client/dist');
1722
const clientPath = path.join(serverless.config.servicePath, distributionFolder);

lib/validate.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ describe('validate', () => {
2828
expect(() => validate(sls, { bucketName: 'my-bucket' })).not.to.throw();
2929
});
3030

31+
it('throws if options are undefined', () => {
32+
const sls = {
33+
config: { servicePath: 'foo' },
34+
utils: { dirExistsSync: () => true }
35+
};
36+
expect(() => validate(sls, undefined))
37+
.to.throw()
38+
.contains('Options must be an object defined under `custom.client`');
39+
});
40+
3141
it('throws if serverless.utils.dirExistsSync returns false', () => {
3242
const sls = {
3343
config: { servicePath: 'foo' },

0 commit comments

Comments
 (0)