Book Image

Learning Node.js for .NET Developers

Book Image

Learning Node.js for .NET Developers

Overview of this book

Node.js is an open source, cross-platform runtime environment that allows you to use JavaScript to develop server-side web applications. This short guide will help you develop applications using JavaScript and Node.js, leverage your existing programming skills from .NET or Java, and make the most of these other platforms through understanding the Node.js programming model. You will learn how to build web applications and APIs in Node, discover packages in the Node.js ecosystem, test and deploy your Node.js code, and more. Finally, you will discover how to integrate Node.js and .NET code.
Table of Contents (16 chapters)
15
Index

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...