stop running server in build step of wercker.yml file

375 Views Asked by At

I want to test that my server can actually start in a build step so one step runs sails lift (I'm using a sails.js app). The sails server then starts fine but it times out after 5 minutes causing the build to fail.

Is there anyway I can still get the build to pass. Maybe after 30 seconds, which would mean the server started fine, to exit myself and return true?

1

There are 1 best solutions below

0
On

I think you can't do that. If you just wanna check that you server will lift before deploy, I recommend you to write one test. Sails integrate a boostrap.test.js file which follow this step :
1. your sails app lift
2. your test is runned
3. your sails app lower

Here is the file bootstrap.test.js which do that :

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);
});

Follow the recommendation of the sails documentation testing section and you will able to organize your tests and write one.

You will run your test with mocha

You can had a shortcut with npm test command by editing your package.json :

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

Concerning Wercker, you will have to install mocha in one of your steps before running your tests with something like that:

# 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