Last active
November 12, 2020 16:31
-
-
Save horike37/b6c02f4c49dcc163129a42aa41dc83b2 to your computer and use it in GitHub Desktop.
The sample code of unit test Lambda function in Serverless Framework projects .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'), | |
chai = require('chai'), | |
should = chai.should(), | |
Serverless = require('serverless') | |
describe('ServerlessProjectTest', function() { | |
beforeEach(function(done) { | |
this.timeout(0); | |
s = new Serverless(); | |
s.init().then(function() { | |
s.config.projectPath = __dirname + '/../'; | |
s.setProject(new s.classes.Project({ | |
stages: { | |
dev: { regions: { 'ap-northeast-1': {} }} | |
}, | |
variables: { | |
project: 'serverless-project', | |
stage: 'dev', | |
region: 'ap-northeast-1' | |
} | |
})); | |
s.getProject().setFunction(new s.classes.Function( | |
{ | |
name:"hello", | |
runtime:"nodejs4.3" | |
}, | |
__dirname + '/../hello/s-function.json')); | |
done(); | |
}); | |
}); | |
describe('#funciton hello()', function() { | |
it('should be funciton hello success', function() { | |
return s.getProject().getFunction('hello').run('dev', 'ap-northeast-1', {}) | |
.then(result => { | |
result.response.message.should.equal('Go Serverless! Your Lambda function executed successfully!') | |
}); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment