Skip to content

Commit

Permalink
fix: check for undefined options when validating
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejpeters authored and Shereef committed May 2, 2023
1 parent 964f0b3 commit 4ab6e60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/validate.js
Expand Up @@ -12,6 +12,11 @@ const path = require('path');
function validateClient(serverless, options) {
const validationErrors = [];

if (!is.object(options)) {
validationErrors.push('Options must be an object defined under `custom.client`');
throw validationErrors;
}

// path to website files must exist
const distributionFolder = options.distributionFolder || path.join('client/dist');
const clientPath = path.join(serverless.config.servicePath, distributionFolder);
Expand Down
10 changes: 10 additions & 0 deletions lib/validate.test.js
Expand Up @@ -28,6 +28,16 @@ describe('validate', () => {
expect(() => validate(sls, { bucketName: 'my-bucket' })).not.to.throw();
});

it('throws if options are undefined', () => {
const sls = {
config: { servicePath: 'foo' },
utils: { dirExistsSync: () => true }
};
expect(() => validate(sls, undefined))
.to.throw()
.contains('Options must be an object defined under `custom.client`');
});

it('throws if serverless.utils.dirExistsSync returns false', () => {
const sls = {
config: { servicePath: 'foo' },
Expand Down

0 comments on commit 4ab6e60

Please sign in to comment.