简体   繁体   English

如何在 function 之前在 mocha 测试中启动 serverless-offline

[英]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.

相关问题 如何在无服务器离线中使用 Cognito 事件/触发器调用 lambda 以进行本地测试 - How to invoke lambda with Cognito event/trigger in serverless-offline for local test 无服务器离线 - API REST 节点 typescript - Serverless-offline - API REST node typescript serverless-offline 可选路径参数 - serverless-offline optional path parameter 带有无服务器离线阶段中断路由的 aws-serverless-express - aws-serverless-express with serverless-offline stage breaks routing 如何摆脱包装无服务器离线 html 响应正文的双引号? - How to get rid of double quotes wrapping serverless-offline html response body? 无法获取路径:/{proxy+} 工作(无服务器离线) - Cant get path: /{proxy+} to work (serverless-offline) 在本地 docker localhost:8000 中使用 dynamodb 和在 localhost:4500 上运行的 serverless-framework serverless-offline 应用程序 - Using dynamodb in local docker localhost:8000 with serverless-framework serverless-offline application running on localhost:4500 Serverless-offline 抛出“配置错误”或“无法读取未定义的属性‘选项’” - Serverless-offline throws "Configuration error" or "Cannot read property 'options' of undefined" 如何在无服务器Mocha插件中模拟用于单元测试的功能 - How to mock function for unit testing in serverless-mocha-plugin 如何在无服务器离线状态下从另一个 lambda 调用 lambda function? - How to invoke a lambda function from another lambda in serverless offline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM