Skip to content

Commit

Permalink
fix(compat): function level entry override (#1226)
Browse files Browse the repository at this point in the history
* better null check
* chore: cover regression in e2e test
  • Loading branch information
vicary authored Aug 27, 2022
1 parent 8e54d47 commit 64dc865
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
12 changes: 5 additions & 7 deletions lib/extendServerless.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const _ = require('lodash');

const extendFunctionProperties = serverless => {
if (_.isFunction(serverless.configSchemaHandler.defineFunctionProperties)) {
serverless.configSchemaHandler.defineFunctionProperties('aws', {
properties: {
entrypoint: { type: 'string' }
}
});
}
_.invoke(serverless, 'configSchemaHandler.defineFunctionProperties', 'aws', {
properties: {
entrypoint: { type: 'string' }
}
});
};

module.exports = {
Expand Down
19 changes: 13 additions & 6 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const _ = require('lodash');
const BbPromise = require('bluebird');
const semver = require('semver');
const Serverless = require('serverless');
const ServerlessWebpack = require('../index');

Expand All @@ -23,7 +24,9 @@ describe('ServerlessWebpack', () => {
};
serverless.pluginManager.spawn = jest.fn().mockReturnValue(BbPromise.resolve());
serverless.service.getFunction = jest.fn().mockReturnValue({ runtime: 'nodejs12.x' });
serverless.configSchemaHandler.defineFunctionProperties = jest.fn();
if (semver.gte(serverless.getVersion(), '2.10.0')) {
serverless.configSchemaHandler.defineFunctionProperties = jest.fn();
}
});

it('should expose a lib object', () => {
Expand All @@ -33,11 +36,15 @@ describe('ServerlessWebpack', () => {

it('should extend serverless', () => {
new ServerlessWebpack(serverless, {});
expect(serverless.configSchemaHandler.defineFunctionProperties).toHaveBeenCalledWith('aws', {
properties: {
entrypoint: { type: 'string' }
}
});
if (semver.gte(serverless.getVersion(), '2.10.0')) {
expect(serverless.configSchemaHandler.defineFunctionProperties).toHaveBeenCalledWith('aws', {
properties: {
entrypoint: { type: 'string' }
}
});
} else {
expect(serverless.configSchemaHandler.defineFunctionProperties).toBeUndefined();
}
});

describe('with a TS webpack configuration', () => {
Expand Down

0 comments on commit 64dc865

Please sign in to comment.