mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Add extractFunctions function for compile step
This commit is contained in:
parent
8ee36c42f5
commit
0a1c19b02a
@ -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();
|
||||
},
|
||||
};
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
3
lib/plugins/awsDeploy/tests/all.js
Normal file
3
lib/plugins/awsDeploy/tests/all.js
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
require('./compile');
|
||||
55
lib/plugins/awsDeploy/tests/compile.js
Normal file
55
lib/plugins/awsDeploy/tests/compile.js
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user