Add extractFunctions function for compile step

This commit is contained in:
Philipp Muens 2016-05-30 12:08:32 +02:00
parent 8ee36c42f5
commit 0a1c19b02a
4 changed files with 87 additions and 2 deletions

View File

@ -1 +1,24 @@
//
'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();
},
};

View File

@ -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"
}
}

View File

@ -0,0 +1,3 @@
'use strict';
require('./compile');

View File

@ -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);
});
});
});
});