node.js - 在 wercker.yml 文件的构建步骤中停止运行服务器

标签 node.js ubuntu continuous-integration sails.js wercker

我想测试我的服务器是否实际上可以在构建步骤中启动,以便一步运行 sails lift (我正在使用 sails.js 应用程序)。 sails 服务器随后正常启动,但 5 分钟后超时,导致构建失败。

无论如何我仍然可以让构建通过。也许 30 秒后,这意味着服务器启动正常,退出并返回 true?

最佳答案

我认为你不能这样做。如果您只是想在部署之前检查服务器是否会提升,我建议您编写一个测试。 Sails 集成了一个 boostrap.test.js 文件,该文件遵循以下步骤:
1.您的 sails 应用程序提升
2.您的测试已运行
3.你的sails应用程序降低

这是执行此操作的文件 bootstrap.test.js :

var Sails = require('sails'),
  sails;

before(function(done) {

  // Increase the Mocha timeout so that Sails has enough time to lift.
  this.timeout(5000);

  Sails.lift({
    // configuration for testing purposes
  }, function(err, server) {
    sails = server;
    if (err) return done(err);
    // here you can load fixtures, etc.
    done(err, sails);
   });
});

after(function(done) {
  // here you can clear fixtures, etc.
  Sails.lower(done);
});

遵循sails documentation testing section的建议您将能够组织测试并编写测试。

您将使用 mocha 运行测试

您可以通过编辑 package.json 来获得 npm test 命令的快捷方式:

// package.json
scripts": {
    "start": "node app.js",
    "debug": "node debug app.js",
    "test": "mocha test/bootstrap.test.js test/unit/**/*.test.js"
},

关于 Wercker,在使用类似的东西运行测试之前,您必须在其中一个步骤中安装 mocha:

# Docker container based on lastest stable iamge of node on DockerHub
box:node

build:
    steps:
        # Install your project dependencies (npm)
        -npm-install
        # Install mocha globally
        - script:
            name: Install mocha globaly
            code: npm install -g mocha
        # Run your tests
        -npm-test    
deploy:
    steps:
    # deploy your application  

关于node.js - 在 wercker.yml 文件的构建步骤中停止运行服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31028978/

相关文章:

node.js - winston.debug 在终端上不显示任何内容

phpunit 命令在 ubuntu 16.04 上运行的 lumen 5.6 中不起作用

ios - XCode-bot 在物理设备上构建失败

Github Actions 作业被跳过

Gradle 仅在 CI 工作期间提示缺少 jar

javascript - 在Vue js中将组件模板拆分成多个部分有什么可行的解决方案吗?

node.js - 无法在 ubuntu slave 上运行 npm

node.js - 我可以在 CoffeeScript 中编写 npm 包吗?

php - 我无法在 ubuntu 上运行 artisan 命令

linux - 每天使用 cron 运行脚本并创建压缩日志文件