Integrating our tests with Gulp
So far, we've executed our tests manually using environment variables and mocha
. It would be nice if we could use gulp
to execute our tests instead, right?
Thankfully, that's really pretty simple. First, we need to install a plugin that integrates Gulp and Mocha:
npm install --save-dev gulp-mocha@2.1.3
Then, we need to add a line to the top of gulpfile.js
, if you haven’t already done so:
require("babel/register"); // enable ES2015 in our tests
We also need to add a few configuration settings to the config
object in gulp/config.js
:
var config = { … test: { code: "test/*.js", ui: "test-ui/*.js" }, }
These configuration settings will be used in our testing tasks to indicate the JavaScript files that should be considered as tests. Notice that our code and UI automation tests live in different directories.
Next, we need to add a new task executes our code tests. Let's call it gulp/tasks/test.js
:
"use strict"; var gulp = require("gulp"), ...