[英]How to start serverless-offline in mocha test before function
I'd like to use serverless-offline in some mocha tests.我想在一些 mocha 测试中使用serverless-offline 。 Something like:就像是:
describe('run some tests', function() {
before(function(done) {
// Start serverless-offline here
return done();
});
after(function(done) {
// Stop serverless-offline here
return done();
});
it('run the test against serverless-offline', function(done) {
// test code here
return done();
});
});
Is there a way to start serverless-offline programatically rather than via the cli?有没有办法以编程方式而不是通过 cli 启动无服务器离线? Or some other way to run tests on serverless functions offline?或者其他方式在无服务器功能上离线运行测试?
What I recommend is use concurrently
from npm (or a similar package that allows you to run multiple processes in a single command.我建议从concurrently
(或类似的 package 允许您在单个命令中运行多个进程)同时使用。
Then add in your before
function a loop that waits for the server to spin up by pinging an endpoint with a HTTP client repeatedly.然后在您before
的 function 中添加一个循环,该循环通过重复使用 HTTP 客户端 ping 端点来等待服务器启动。 You can add either a default route or a health-check route to do this.您可以添加默认路由或运行状况检查路由来执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.