Running integration tests from Gulp

Gulp tasks are just ordinary JavaScript functions, so can contain any functionality we like. Let's look at a more complex use case. We'll create a task that starts up our server, runs integration tests, and then closes the server. For this, we'll need the Gulp Shell plugin:

> npm install gulp-shell --save-dev

First, we update our integration test script so that we can pass in the port number of the test server. This makes use of the PhantomJS 'system' module as follows (in integration-test/game.js):

var rootUrl = 'http://localhost:' +
                  require('system').env.TEST_PORT || 3000;

Now we can define a Gulp task to run the server and the integration test:

const shell = require('gulp-shell'); ... gulp.task('integration-test', ...

Get Learning Node.js for .NET Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.