119 lines
4.3 KiB
JavaScript
Executable File
119 lines
4.3 KiB
JavaScript
Executable File
/* jslint node:true */
|
|
|
|
'use strict';
|
|
|
|
require('supererror')({ splatchError: true });
|
|
|
|
var async = require('async'),
|
|
debug = require('debug')('e2e:runner'),
|
|
fs = require('fs'),
|
|
path = require('path'),
|
|
shell = require('./shell.js'),
|
|
semver = require('semver'),
|
|
mailer = require('./mailer.js'),
|
|
superagent = require('superagent'),
|
|
util = require('util');
|
|
|
|
var E2E_TEST_DIR = path.join(process.env.HOME, 'e2e-test');
|
|
var INSTALLER_DIR = path.join(process.env.HOME, 'installer');
|
|
|
|
// override debug.log to print only as console.log
|
|
debug.log = console.log.bind(console);
|
|
|
|
var gLatestETag = null; // this allows us to rerun tests by restarting this process. and also for every appstore push
|
|
var gLatestBoxVersion = null; // for sending mail
|
|
|
|
function start() {
|
|
runTestsIfNeeded(function () {
|
|
setTimeout(start, 60 * 1000);
|
|
});
|
|
}
|
|
|
|
function runTestsIfNeeded(callback) {
|
|
debug('Getting latest box version');
|
|
|
|
getLatestBoxVersion(function (error, latestETag, latestBoxVersion) {
|
|
if (error) return callback(error);
|
|
|
|
if (latestETag === gLatestETag) {
|
|
debug('Box version has not changed. etag %s', gLatestETag);
|
|
return callback(null);
|
|
}
|
|
|
|
debug('Box version has changed. etag %s', latestETag);
|
|
|
|
runTests(latestETag, latestBoxVersion, function (error) {
|
|
debug('Finished running tests for etag %s: %s', latestETag, error);
|
|
gLatestETag = latestETag;
|
|
gLatestBoxVersion = latestBoxVersion;
|
|
callback(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
function getLatestBoxVersion(callback) {
|
|
superagent.get(process.env.BOX_VERSIONS_URL).end(function (error, res) {
|
|
if (error || res.statusCode !== 200 || !res.body) {
|
|
debug('Error downloading versions file', error, res.statusCode);
|
|
return callback(new Error('Error downloading versions file'));
|
|
}
|
|
|
|
var latestVersion = Object.keys(res.body).sort(semver.rcompare)[0];
|
|
var latestETag = res.headers['etag'];
|
|
|
|
debug('%j:', res.headers);
|
|
|
|
callback(null, latestETag, latestVersion);
|
|
});
|
|
}
|
|
|
|
function gitPullLatestTests(callback) {
|
|
async.series([
|
|
function (next) {
|
|
if (fs.existsSync(E2E_TEST_DIR)) return next();
|
|
debug('Cloning e2e-test repo on first run');
|
|
shell.system('gitCloneE2E', 'git clone ' + process.env.E2E_TEST_REPO + ' e2e-test',
|
|
{ cwd: process.env.HOME }, next);
|
|
},
|
|
function (next) {
|
|
if (fs.existsSync(INSTALLER_DIR)) return next();
|
|
debug('Cloning install repo on first run');
|
|
shell.system('gitCloneInstaller', 'git clone ' + process.env.INSTALLER_REPO + ' installer',
|
|
{ cwd: process.env.HOME }, next);
|
|
},
|
|
function (next) {
|
|
debug('getting latest e2e-test');
|
|
shell.system('gitFetchE2E', 'git fetch origin && git reset --hard origin/master && npm install',
|
|
{ cwd: E2E_TEST_DIR, env: { GIT_DIR: E2E_TEST_DIR + '/.git' } }, next); // it's not clear why GIT_DIR is needed
|
|
},
|
|
function (next) {
|
|
debug('getting latest installer');
|
|
shell.system('gitFetchInstaller', 'git fetch origin && git reset --hard origin/master && npm install',
|
|
{ cwd: INSTALLER_DIR, env: { GIT_DIR: INSTALLER_DIR + '/.git' } }, next); // it's not clear why GIT_DIR is needed
|
|
}
|
|
], callback);
|
|
}
|
|
|
|
function runTests(latestETag, latestBoxVersion, callback) {
|
|
var topic = util.format('box version: %s etag: %s', latestBoxVersion, latestETag);
|
|
|
|
debug('Running tests for %s', topic);
|
|
|
|
gitPullLatestTests(function (error, stdout, stderr) {
|
|
if (error) {
|
|
mailer.sendEndToEndTestResult(topic, stdout ? stdout.toString('utf8') : '', stderr ? stderr.toString('utf8') : '', function () { });
|
|
return callback(error);
|
|
}
|
|
|
|
shell.system('e2etestrunner', 'npm test', { cwd: E2E_TEST_DIR }, function (error, stdout, stderr) {
|
|
debug('Final test result', error);
|
|
|
|
mailer.sendEndToEndTestResult(topic, stdout ? stdout.toString('utf8') : '', stderr ? stderr.toString('utf8') : '', function () { });
|
|
return callback(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
debug('e2etest started.');
|
|
start();
|