Skip to content

Running against a local app server

James Wright edited this page Mar 19, 2020 · 7 revisions

In a continuous integration scenario, it could be ideal validate your app server with the latest code changes. If this server is developed in Node.js, then you can use the Valimate Notifier module to defer the execution of tests until the server has started up and is ready to serve HTML.

Install the module in your terminal with npm i --save valimate-notifier

In the valimate.json file, set the localAppServer to point to your server's entry script. You can also use the env property to pass environment variables to the process as key-value pairs:

{
  "localAppServer": {
    "entryPoint": "app.js",

    "env": {
      "TEST": "true"
    }
  },

  "urls": [
    "http://localhost:8081/"
  ]
}

Then use the Valimate Notifier module to notify Valimate when the server is ready to be validated. The module exports a fuction which accepts one argument; a truthy value suggests that start up was successful, whereas a falsy value suggests failure, causing Valimate to exit:

'use strict';

const http = require('http');
const notifyValimate = require('valimate-notifier');
const dataService = require('./services/myDataService');
const htmlBuilder = require('./view/htmlBuilder');

const PORT = 8081;

dataService.someAsyncOperation().then(data => {
  http.createServer((req, res) => {
    res.end(htmlBuilder(data), 'utf-8');
  }).listen(PORT, () => {
    notifyValimate(true);
  });
}).catch(e => notifyValimate(false));

Upon running the valimate CLI, your app server will be started as a child process, and killed when testing is complete.

If your app server has not been started by Valimate (e.g. running in production), then this method will do nothing.

I run Valimate against my personal website using a local process running on Travis CI. See this build for an example of how it looks.

Clone this wiki locally