Instead of using the cli with say serverless invoke
can I require('serverless').invoke
?
No, not at the moment. There have been other people discussing this, but it just doesn’t make sense for the project to address this use case at this point in time (while work is still in progress to v1.0).
@flomotlik For performing integration tests in CI. Currently I do:
const { test } = require('tap');
const exec = require('child_process').exec;
...
test('accepts request path variables', t =>
exec('serverless invoke -f path -p events/path2.json', (e, data) => {
...
Thanks @buggy I haven’t touched AWS.Lambda yet, thanks for bringing the invoke method to my attention.
In the future we want to provide testing libraries as well that make these things easier. Testing is a VERY important topic for us going forward. We’ve started by implementing this small mock library: https://github.com/serverless/aws-event-mocks but there will be more
And also we’re going to start opening issues and starting the discussion there, so checking out the issues and milestone goals we share could give you a chance to chime in there.