diff --git a/lib/SerializerFileSystem.js b/lib/SerializerFileSystem.js index 7a9f3f6ed..6088c58c4 100644 --- a/lib/SerializerFileSystem.js +++ b/lib/SerializerFileSystem.js @@ -357,7 +357,6 @@ class SerializerFileSystem { return BbPromise.try(function() { - // Validate: Check project path is set if (!_this._S.hasProject()) throw new SError('Region could not be loaded because no project path has been set on Serverless instance'); @@ -425,9 +424,9 @@ class SerializerFileSystem { notRoot = true; while (notRoot) { - parentDir = path.join(parentDir, '..'); - notRoot = SUtils.fileExistsSync(path.join(parentDir, 's-project.json')); - if (SUtils.fileExistsSync(path.join(parentDir, 's-templates.json'))) { + parentDir = path.dirname(parentDir); + notRoot = !SUtils.fileExistsSync(path.join(parentDir, 's-project.json')); + if (notRoot && SUtils.fileExistsSync(path.join(parentDir, 's-templates.json'))) { parents.push(new _this._S.classes.Templates( _this._S, SUtils.readFileSync(path.join(parentDir, 's-templates.json')), diff --git a/lib/actions/CodePackageLambda.js b/lib/actions/CodePackageLambda.js index 3bff41287..73a660d7c 100644 --- a/lib/actions/CodePackageLambda.js +++ b/lib/actions/CodePackageLambda.js @@ -144,9 +144,14 @@ module.exports = function(SPlugin, serverlessPath) { let excludePatterns = this.function.custom.excludePatterns || [], // Extract the root of the lambda package from the handler property - handlerFullPath = _this.function.getRootPath(_this.function.handler.split('/')[_this.function.handler.split('/').length - 1]), - packageRoot = handlerFullPath.replace(_this.function.handler, ''); + handlerFullPath = _this.function.getRootPath(_this.function.handler.split('/')[_this.function.handler.split('/').length - 1]); + // Check handler is correct + if (handlerFullPath.indexOf(_this.function.handler) == -1) { + throw new SError('This function\'s handler is invalid and not in the file system: ' + _this.function.handler); + } + + let packageRoot = handlerFullPath.replace(_this.function.handler, ''); wrench.copyDirSyncRecursive( packageRoot, diff --git a/lib/actions/FunctionDeploy.js b/lib/actions/FunctionDeploy.js index 6faef112f..b58aa81ff 100644 --- a/lib/actions/FunctionDeploy.js +++ b/lib/actions/FunctionDeploy.js @@ -133,8 +133,8 @@ module.exports = function(SPlugin, serverlessPath) { } } - // throw error for CI - throw new SError('Lambda Deployment Failed.'); + // Throw error for CI + throw new SError('Function Deployment Failed'); } // Display Successful Function Deployments diff --git a/lib/utils/index.js b/lib/utils/index.js index 1d9ec0590..1eaed34b0 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -327,7 +327,7 @@ module.exports = { } if (!templates[template]) { - SCli.log('WARNING: the following template is requested but not defined: ' + template); + SCli.log('WARNING: the following template is requested but not defined: ' + template + (data.name ? ' in ' + data.name : '')); } // Replace diff --git a/tests/all.js b/tests/all.js index 48aa5bcdc..052900604 100644 --- a/tests/all.js +++ b/tests/all.js @@ -8,30 +8,28 @@ describe('All Tests', function() { after(function() {}); require('./tests/classes/Project'); - // require('./tests/classes/Component'); - // require('./tests/classes/Function'); - // require('./tests/classes/Endpoint'); - // require('./tests/classes/Stage'); - // require('./tests/classes/Region'); - // require('./tests/actions/TestPluginCustom'); - // require('./tests/actions/TestDefaultActionHook'); - // require('./tests/actions/StageCreate'); - // require('./tests/actions/RegionCreate'); - // require('./tests/actions/ComponentCreate'); - // require('./tests/actions/FunctionCreate'); - // require('./tests/actions/EnvList'); - // require('./tests/actions/EnvGet'); - // require('./tests/actions/EnvSetUnset'); + require('./tests/classes/Function'); + require('./tests/classes/Endpoint'); + require('./tests/classes/Stage'); + require('./tests/classes/Region'); + require('./tests/actions/TestPluginCustom'); + require('./tests/actions/TestDefaultActionHook'); + require('./tests/actions/StageCreate'); + require('./tests/actions/RegionCreate'); + require('./tests/actions/FunctionCreate'); + require('./tests/actions/EnvList'); + require('./tests/actions/EnvGet'); + require('./tests/actions/EnvSetUnset'); require('./tests/actions/ResourcesDeploy'); - // require('./tests/actions/FunctionRun'); - // require('./tests/actions/FunctionLogs'); - // require('./tests/actions/FunctionDeploy'); - // require('./tests/actions/EndpointDeploy'); - // require('./tests/actions/EventDeploy'); - // require('./tests/actions/ProjectInit'); + require('./tests/actions/FunctionRun'); + require('./tests/actions/FunctionLogs'); + require('./tests/actions/FunctionDeploy'); + require('./tests/actions/EndpointDeploy'); + require('./tests/actions/EventDeploy'); + require('./tests/actions/ProjectInit'); // require('./tests/actions/ProjectInstall'); // BROKEN. + require('./tests/actions/ResourcesDiff'); + require('./tests/actions/PluginCreate'); + require('./tests/actions/FunctionRollback'); // require('./tests/actions/ProjectLifeCycle.js'); - // require('./tests/actions/ResourcesDiff'); - // require('./tests/actions/PluginCreate'); - // require('./tests/actions/FunctionRollback'); }); \ No newline at end of file diff --git a/tests/test-prj/functions/group1/group2/function4/s-function.json b/tests/test-prj/functions/group1/group2/function4/s-function.json index 501d55cb7..4ad135a74 100644 --- a/tests/test-prj/functions/group1/group2/function4/s-function.json +++ b/tests/test-prj/functions/group1/group2/function4/s-function.json @@ -6,7 +6,7 @@ "envVars": [], "excludePatterns": [] }, - "handler": "group1/function4/handler.handler", + "handler": "group2/function4/handler.handler", "timeout": 6, "memorySize": 1024, "authorizer": { diff --git a/tests/test-prj/functions/s-resources-cf.json b/tests/test-prj/functions/s-resources-cf.json deleted file mode 100644 index 612c9002c..000000000 --- a/tests/test-prj/functions/s-resources-cf.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "LambdaIamPolicyStatements": [ - { - "Effect": "Allow", - "Action": "s3:ListBucket", - "Resource": "arn:aws:s3:::fake_bucket1" - } - ], - "Resources": {} -} \ No newline at end of file diff --git a/tests/tests/actions/FunctionCreate.js b/tests/tests/actions/FunctionCreate.js index 1a88e5368..055bcb61c 100644 --- a/tests/tests/actions/FunctionCreate.js +++ b/tests/tests/actions/FunctionCreate.js @@ -56,14 +56,14 @@ describe('Test action: Function Create', function() { this.timeout(0); let evt = { options: { - path: 'nodejscomponent/temp' + path: 'functions/temp' } }; serverless.actions.functionCreate(evt) .then(function(evt) { validateEvent(evt); - let functionJson = utils.readFileSync(serverless.getProject().getRootPath('nodejscomponent', 'temp', 's-function.json')); + let functionJson = utils.readFileSync(serverless.getProject().getRootPath('functions', 'temp', 's-function.json')); assert.equal(functionJson.name, 'temp'); done(); }) diff --git a/tests/tests/actions/FunctionDeploy.js b/tests/tests/actions/FunctionDeploy.js index 78e863633..c9f8fcb6b 100644 --- a/tests/tests/actions/FunctionDeploy.js +++ b/tests/tests/actions/FunctionDeploy.js @@ -71,7 +71,7 @@ describe('Test Action: Function Deploy', function() { before(function(done) { this.timeout(0); - testUtils.createTestProject(config, ['nodejscomponent']) + testUtils.createTestProject(config, ['functions']) .then(projectPath => { process.chdir(projectPath); @@ -97,31 +97,31 @@ describe('Test Action: Function Deploy', function() { * Tests */ - describe('Function Deploy: Specify One Path', function() { - it('should deploy functions', function(done) { + // describe('Function Deploy: Specify One Path', function() { + // it('should deploy functions', function(done) { + // + // this.timeout(0); + // + // let options = { + // stage: config.stage, + // region: config.region, + // names: [ + // 'function1' + // ] + // }; + // + // serverless.actions.functionDeploy(options) + // .then(function(evt) { + // validateEvent(evt); + // done(); + // }) + // .catch(e => { + // done(e); + // }); + // }); + // }); - this.timeout(0); - - let options = { - stage: config.stage, - region: config.region, - names: [ - 'function1' - ] - }; - - serverless.actions.functionDeploy(options) - .then(function(evt) { - validateEvent(evt); - done(); - }) - .catch(e => { - done(e); - }); - }); - }); - - describe('Function Deploy: Nested W/ Custom Name', function() { + describe('Function Deploy: Nested W/ Custom Name & Limited Parent Dir', function() { it('should deploy functions', function(done) { this.timeout(0); diff --git a/tests/tests/actions/FunctionRollback.js b/tests/tests/actions/FunctionRollback.js index 4be3c7ed3..4f293b41d 100644 --- a/tests/tests/actions/FunctionRollback.js +++ b/tests/tests/actions/FunctionRollback.js @@ -27,7 +27,7 @@ describe('Test Action: Function Rollback', function() { this.timeout(0); before(function() { - return testUtils.createTestProject(config, ['nodejscomponent']) + return testUtils.createTestProject(config, ['functions']) .then(projectPath => { process.chdir(projectPath); diff --git a/tests/tests/actions/FunctionRun.js b/tests/tests/actions/FunctionRun.js index b19cb992b..f20b9e02b 100644 --- a/tests/tests/actions/FunctionRun.js +++ b/tests/tests/actions/FunctionRun.js @@ -29,7 +29,7 @@ describe('Test Action: Function Run', function() { before(function(done) { this.timeout(0); - testUtils.createTestProject(config, ['nodejscomponent']) + testUtils.createTestProject(config, ['functions']) .then(projectPath => { this.timeout(0); @@ -94,5 +94,4 @@ describe('Test Action: Function Run', function() { }); }); }); - }); diff --git a/tests/tests/actions/ModuleCreate.js b/tests/tests/actions/ModuleCreate.js deleted file mode 100644 index e938099af..000000000 --- a/tests/tests/actions/ModuleCreate.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict'; - -/** - * Test: Module Create Action - * - Creates a new project in your system's temp directory - * - Creates a new Module inside test project - */ - -let Serverless = require('../../../lib/Serverless.js'), - path = require('path'), - utils = require('../../../lib/utils/index'), - assert = require('chai').assert, - testUtils = require('../../test_utils'), - config = require('../../config'); - -let serverless; - -/** - * Validate Event - * - Validate an event object's properties - */ - -let validateEvent = function(evt) { - assert.equal(true, typeof evt.options.component != 'undefined'); - assert.equal(true, typeof evt.options.module != 'undefined'); - assert.equal(true, typeof evt.options.function != 'undefined'); - assert.equal(true, typeof evt.options.runtime != 'undefined'); -}; - -describe('Test action: Module Create', function() { - - before(function(done) { - this.timeout(0); - testUtils.createTestProject(config) - .then(projPath => { - - process.chdir(projPath); - - serverless = new Serverless( projPath, { - interactive: false - }); - - return serverless.init().then(function() { - done(); - }); - }); - }); - - after(function(done) { - done(); - }); - - describe('Module Create positive tests', function() { - - it('create a new module with defaults', function(done) { - - this.timeout(0); - - let evt = { - options: { - component: 'nodejscomponent', - module: 'newmodule', - function: 'newfunction' - } - }; - - serverless.actions.moduleCreate(evt) - .then(function(evt) { - let functionJson = utils.readFileSync(serverless.getProject().getRootPath( 'nodejscomponent', 'newmodule', 'newfunction', 's-function.json')); - assert.equal(true, typeof functionJson.name != 'undefined'); - assert.equal(true, functionJson.endpoints.length); - - validateEvent(evt); - done(); - }) - .catch(e => { - done(e); - }); - }); - }); -}); diff --git a/tests/tests/actions/TestDefaultActionHook.js b/tests/tests/actions/TestDefaultActionHook.js index 95aa55e95..2467f657e 100644 --- a/tests/tests/actions/TestDefaultActionHook.js +++ b/tests/tests/actions/TestDefaultActionHook.js @@ -41,7 +41,7 @@ class CustomPlugin extends SPlugin { registerHooks() { this.S.addHook(this._defaultActionPreHook.bind(this), { - action: 'componentCreate', + action: 'functionCreate', event: 'pre' }); @@ -68,7 +68,6 @@ class CustomPlugin extends SPlugin { */ let validateResult = function(result) { - assert.equal(true, typeof result.options.runtime != 'undefined'); assert.equal(true, typeof result.data.hook != 'undefined'); }; @@ -101,11 +100,11 @@ describe('Test Default Action With Pre Hook', function() { this.timeout(0); let evt = { options: { - name: 'testcomponent' + path: 'testFunction' } }; - serverless.actions.componentCreate(evt) + serverless.actions.functionCreate(evt) .then(function(result) { validateResult(result); done(); diff --git a/tests/tests/classes/Endpoint.js b/tests/tests/classes/Endpoint.js index 5e77d5c46..642ab626d 100644 --- a/tests/tests/classes/Endpoint.js +++ b/tests/tests/classes/Endpoint.js @@ -69,7 +69,7 @@ describe('Test Serverless Endpoint Class', function() { it('getTemplates', function() { assert.equal(instance.getTemplates()._class, 'Templates'); - assert.equal(instance.getTemplates()._parents.length, 1); + assert.equal(instance.getTemplates()._parents.length, 2); }); it('Set instance data', function() { diff --git a/tests/tests/classes/Function.js b/tests/tests/classes/Function.js index 7d2a5cf91..7a68661a7 100644 --- a/tests/tests/classes/Function.js +++ b/tests/tests/classes/Function.js @@ -82,7 +82,7 @@ describe('Test Serverless Function Class', function() { it('getTemplates', function() { assert.equal(instance.getTemplates()._class, 'Templates'); - assert.equal(instance.getTemplates()._parents.length, 1); + assert.equal(instance.getTemplates()._parents.length, 2); }); it('Set instance data', function() {