From 0a1c19b02aff8d36764882cf8697cb7edb7f9fb5 Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Mon, 30 May 2016 12:08:32 +0200 Subject: [PATCH] Add extractFunctions function for compile step --- lib/plugins/awsDeploy/lib/compile.js | 25 +++++++++++- lib/plugins/awsDeploy/package.json | 6 ++- lib/plugins/awsDeploy/tests/all.js | 3 ++ lib/plugins/awsDeploy/tests/compile.js | 55 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 lib/plugins/awsDeploy/tests/all.js create mode 100644 lib/plugins/awsDeploy/tests/compile.js diff --git a/lib/plugins/awsDeploy/lib/compile.js b/lib/plugins/awsDeploy/lib/compile.js index ab0c01417..63c8c9202 100644 --- a/lib/plugins/awsDeploy/lib/compile.js +++ b/lib/plugins/awsDeploy/lib/compile.js @@ -1 +1,24 @@ -// \ No newline at end of file +'use strict'; + +const path = require('path'); +const BbPromise = require('bluebird'); +const forEach = require('lodash').forEach; + +module.exports = { + extractFunctions: function () { + const rawFunctionObjects = this.serverless.service.functions; + + forEach(rawFunctionObjects, (value, key) => { + // check if it's the function and not the name_template property + if (key !== 'name_template') { + const functionObject = { + [key]: value, + }; + + this.functionObjects.push(functionObject); + } + }); + + return BbPromise.resolve(); + }, +}; diff --git a/lib/plugins/awsDeploy/package.json b/lib/plugins/awsDeploy/package.json index 4af105d24..de99d07d3 100644 --- a/lib/plugins/awsDeploy/package.json +++ b/lib/plugins/awsDeploy/package.json @@ -4,10 +4,14 @@ "description": "", "license": "MIT", "scripts": { - "test": "node_modules/.bin/mocha ./tests/deploy.js" + "test": "node_modules/.bin/mocha ./tests/all.js" }, "devDependencies": { "chai": "^3.5.0", "mocha": "^2.4.5" + }, + "dependencies": { + "bluebird": "^3.4.0", + "lodash": "^4.13.1" } } diff --git a/lib/plugins/awsDeploy/tests/all.js b/lib/plugins/awsDeploy/tests/all.js new file mode 100644 index 000000000..7f62ac274 --- /dev/null +++ b/lib/plugins/awsDeploy/tests/all.js @@ -0,0 +1,3 @@ +'use strict'; + +require('./compile'); diff --git a/lib/plugins/awsDeploy/tests/compile.js b/lib/plugins/awsDeploy/tests/compile.js new file mode 100644 index 000000000..9ea17c128 --- /dev/null +++ b/lib/plugins/awsDeploy/tests/compile.js @@ -0,0 +1,55 @@ +'use strict'; + +const expect = require('chai').expect; +const compile = require('../lib/compile'); +const Serverless = require('../../../Serverless'); + +describe('compile', () => { + let serverless; + let awsDeployMock; + + beforeEach(() => { + serverless = new Serverless(); + awsDeployMock = { + serverless, + functionObjects: [], + }; + }); + + const rawFunctionObjectsMock = { + name_template: 'name-template-name', + first: { + name_template: 'name-template-name', + handler: 'first.function.handler', + provider: { + aws_lambda: { + timeout: 6, + memorySize: 1024, + runtime: 'nodejs4.3', + }, + }, + }, + second: { + name_template: 'name-template-name', + handler: 'second.function.handler', + provider: { + aws_lambda: { + timeout: 6, + memorySize: 1024, + runtime: 'nodejs4.3', + }, + }, + }, + }; + + describe('#extractFunctions()', () => { + it('should extract functions from the rawFunctions object', () => { + serverless.service.functions = rawFunctionObjectsMock; + + return compile.extractFunctions.apply(awsDeployMock).then(() => { + expect(awsDeployMock.functionObjects[0].first).to.equal(rawFunctionObjectsMock.first); + expect(awsDeployMock.functionObjects[1].second).to.equal(rawFunctionObjectsMock.second); + }); + }); + }); +});