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', ['lint-integration-test', 'test'], (done) => { const TEST_PORT = 5000; let server = require('http') .createServer(require('./src/app.js')) .listen(TEST_PORT, function() { gulp.src('integration...