diff --git a/tests/packaging-suite/handler2.js b/tests/packaging-suite/handler2.js new file mode 100644 index 000000000..8d524e278 --- /dev/null +++ b/tests/packaging-suite/handler2.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports.hello = async (event) => { + return { + statusCode: 200, + body: JSON.stringify({ + message: 'Go Serverless v1.0! Your function executed successfully!', + input: event, + }, null, 2), + }; + + // Use this code if you don't use the http event with the LAMBDA-PROXY integration + // return { message: 'Go Serverless v1.0! Your function executed successfully!', event }; +}; diff --git a/tests/packaging-suite/individually.yml b/tests/packaging-suite/individually.yml new file mode 100644 index 000000000..df2d79d23 --- /dev/null +++ b/tests/packaging-suite/individually.yml @@ -0,0 +1,24 @@ +service: aws-nodejs + +provider: + name: aws + runtime: nodejs10.x + +package: + individually: true + +functions: + hello: + handler: handler.hello + package: + include: + - handler.js + exclude: + - handler2.js + hello2: + handler: handler2.hello + package: + include: + - handler2.js + exclude: + - handler.js diff --git a/tests/packaging-suite/packaging.tests.js b/tests/packaging-suite/packaging.tests.js index 13428ff30..e321533e5 100644 --- a/tests/packaging-suite/packaging.tests.js +++ b/tests/packaging-suite/packaging.tests.js @@ -73,14 +73,7 @@ describe('Integration test - Packaging', () => { expect(nonNodeModulesFiles).toEqual(['handler.js']); }); }); -}); -describe('Integration test - Packaging', () => { - let cwd; - beforeEach(() => { - cwd = testUtils.getTmpDirPath(); - fse.mkdirsSync(cwd); - }); it('package artifact directive works', () => { fs.copyFileSync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')) fs.copyFileSync(path.join(__dirname, 'artifact.zip'), path.join(cwd, 'artifact.zip')) @@ -157,4 +150,47 @@ describe('Integration test - Packaging', () => { expect(zipfiles).toEqual(['handler.js']); }); }); + + it('handles package individually with include/excludes correctly', () => { + fs.copyFileSync(path.join(__dirname, 'individually.yml'), path.join(cwd, 'serverless.yml')) + fs.copyFileSync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')) + fs.copyFileSync(path.join(__dirname, 'handler2.js'), path.join(cwd, 'handler2.js')) + execSync(`${serverlessExec} package`, { cwd }); + const cfnTemplate = JSON.parse(fs.readFileSync(path.join( + cwd, '.serverless/cloudformation-template-update-stack.json'))); + expect(cfnTemplate.Resources.HelloLambdaFunction.Properties.Code.S3Key) + .toMatch(/serverless\/aws-nodejs\/dev\/[^]*\/hello.zip/); + expect(cfnTemplate.Resources.Hello2LambdaFunction.Properties.Code.S3Key) + .toMatch(/serverless\/aws-nodejs\/dev\/[^]*\/hello2.zip/); + delete cfnTemplate.Resources.HelloLambdaFunction.Properties.Code.S3Key; + expect(cfnTemplate.Resources.HelloLambdaFunction).toEqual({ + Type: 'AWS::Lambda::Function', + Properties: { + Code: { + S3Bucket: { + Ref: 'ServerlessDeploymentBucket', + }, + }, + FunctionName: 'aws-nodejs-dev-hello', + Handler: 'handler.hello', + MemorySize: 1024, + Role: { + 'Fn::GetAtt': [ + 'IamRoleLambdaExecution', + 'Arn', + ], + }, + Runtime: 'nodejs10.x', + Timeout: 6, + }, + DependsOn: [ + 'HelloLogGroup', + 'IamRoleLambdaExecution', + ], + }); + return testUtils.listZipFiles(path.join(cwd, '.serverless/hello.zip')) + .then(zipfiles => expect(zipfiles).toEqual(['handler.js'])) + .then(() => testUtils.listZipFiles(path.join(cwd, '.serverless/hello2.zip'))) + .then(zipfiles => expect(zipfiles).toEqual(['handler2.js'])); + }); });