diff --git a/tests/packaging-suite/handler.js b/tests/packaging-suite/handler.js new file mode 100644 index 000000000..8d524e278 --- /dev/null +++ b/tests/packaging-suite/handler.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/packaging.tests.js b/tests/packaging-suite/packaging.tests.js index d6fdf1631..4d5e75801 100644 --- a/tests/packaging-suite/packaging.tests.js +++ b/tests/packaging-suite/packaging.tests.js @@ -17,7 +17,8 @@ describe('Integration test - Packaging', () => { it('packages the default aws template correctly in the zip', () => { const templateName = 'aws-nodejs'; - execSync(`${serverlessExec} create --template ${templateName}`, { cwd }); + fs.copyFileSync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')) + fs.copyFileSync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')) execSync(`${serverlessExec} package`, { cwd }); return testUtils.listZipFiles(path.join(cwd, '.serverless/aws-nodejs.zip')) .then(zipfiles => { @@ -27,7 +28,8 @@ describe('Integration test - Packaging', () => { it('packages the default aws template with an npm dep correctly in the zip', () => { const templateName = 'aws-nodejs'; - execSync(`${serverlessExec} create --template ${templateName}`, { cwd }); + fs.copyFileSync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')) + fs.copyFileSync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')) execSync('npm init --yes', { cwd }); execSync('npm i lodash', { cwd }); execSync(`${serverlessExec} package`, { cwd }); @@ -43,7 +45,8 @@ describe('Integration test - Packaging', () => { it('doesn\'t package a dev dependency in the zip', () => { const templateName = 'aws-nodejs'; - execSync(`${serverlessExec} create --template ${templateName}`, { cwd }); + fs.copyFileSync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')) + fs.copyFileSync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')) execSync('npm init --yes', { cwd }); execSync('npm i --save-dev lodash', { cwd }); execSync(`${serverlessExec} package`, { cwd }); @@ -59,7 +62,8 @@ describe('Integration test - Packaging', () => { it('ignores package json files per ignore directive in the zip', () => { const templateName = 'aws-nodejs'; - execSync(`${serverlessExec} create --template ${templateName}`, { cwd }); + fs.copyFileSync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')) + fs.copyFileSync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')) execSync('npm init --yes', { cwd }); execSync('echo \'package: {exclude: ["package*.json"]}\' >> serverless.yml', { cwd }); execSync('npm i lodash', { cwd }); @@ -84,7 +88,8 @@ describe('Integration test - Packaging', () => { it('creates the correct default function resource in cfn template', () => { const templateName = 'aws-nodejs'; - execSync(`${serverlessExec} create --template ${templateName}`, { cwd }); + fs.copyFileSync(path.join(__dirname, 'serverless.yml'), path.join(cwd, 'serverless.yml')) + fs.copyFileSync(path.join(__dirname, 'handler.js'), path.join(cwd, 'handler.js')) execSync(`${serverlessExec} package`, { cwd }); const cfnTemplate = JSON.parse(fs.readFileSync(path.join( cwd, '.serverless/cloudformation-template-update-stack.json'))); diff --git a/tests/packaging-suite/serverless.yml b/tests/packaging-suite/serverless.yml new file mode 100644 index 000000000..700a3a5bd --- /dev/null +++ b/tests/packaging-suite/serverless.yml @@ -0,0 +1,10 @@ +service: aws-nodejs + +provider: + name: aws + runtime: nodejs10.x + + +functions: + hello: + handler: handler.hello