mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
package individually test
This commit is contained in:
parent
50c6fd35d8
commit
bc9dc0895b
14
tests/packaging-suite/handler2.js
Normal file
14
tests/packaging-suite/handler2.js
Normal file
@ -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 };
|
||||
};
|
||||
24
tests/packaging-suite/individually.yml
Normal file
24
tests/packaging-suite/individually.yml
Normal file
@ -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
|
||||
@ -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']));
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user