Skip to content

Commit

Permalink
Merge branch 'release-0.4.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
apendua committed Mar 17, 2015
2 parents 1326ae6 + 9ff8642 commit 7e0e25a
Show file tree
Hide file tree
Showing 40 changed files with 2,106 additions and 1,416 deletions.
2 changes: 1 addition & 1 deletion .versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
anti:gagarin@0.4.3
anti:gagarin@0.4.4
base64@1.0.2
callback-hook@1.0.2
check@1.0.4
Expand Down
6 changes: 4 additions & 2 deletions bin/gagarin
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ program
.option('-w, --webdriver <url>', 'webdriver url [default: http://127.0.0.1:9515]', 'http://127.0.0.1:9515')
.option('-M, --dont-wait-for-meteor', 'do not wait until meteor is loaded')
.option('-l, --meteor-load-timeout <ms>', 'meteor load timeout [2000]', intParse, 2000)
.option('-p, --path-to-app <path>', 'path to a meteor application', path.resolve('.'))
.option('-a, --path-to-app <path>', 'path to a meteor application', path.resolve('.'))
.option('-r, --remote-server <url>', 'run tests on a remote server')
.option('-m, --mute-build', 'do not show build logs', false)
.option('-f, --flavor <name>', 'default flavor of api (promise, fiber)', 'promise')
.option('-T, --startup-timeout <ms>' ,'server startup timeout [5000]', intParse, 5000)
.option('-U, --build-timeout <ms>' ,'meteor building timeout [120000]', intParse, 120000);
.option('-U, --build-timeout <ms>' ,'meteor building timeout [120000]', intParse, 120000)
.option('-v, --velocity <url>', 'report results to velocity at given url')
.option('-p, --parallel <number>', 'run test suites in parallel', intParse, 0)

program.name = 'gagarin';

Expand Down
51 changes: 51 additions & 0 deletions lib/logs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

module.exports.table = require('./table');

var isBlocked = false;
var secret = 0;

var stdout_write = process.stdout._write.bind(process.stdout);
var stderr_write = process.stderr._write.bind(process.stderr);

process.stdout._write = function () {
"use strict";

var args = Array.prototype.slice.call(arguments, 0);

if (isBlocked) {
args[0] = '';
args[1] = null;
}
return stdout_write.apply(null, args);
}

process.stderr._write = function () {
"use strict";
var args = Array.prototype.slice.call(arguments, 0);
if (isBlocked) {
args[0] = '';
args[1] = null;
}
return stderr_write.apply(null, args);
}

module.exports.block = function block () {
"use strict";

var mySecret = secret = Math.random();

isBlocked = true;

return function write (data) {
if (mySecret !== secret) {
// someone has blocked after we did it
return;
}
return stdout_write.call(null, data, null, function () {});
}
}

module.exports.unblock = function unblock () {
"use strict";
isBlocked = false;
}
73 changes: 73 additions & 0 deletions lib/logs/table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

var Base = require('mocha').reporters.Base;
var chalk = require('chalk');

module.exports = function table (listOfStats, write) {

var labels = [];
var titles = [];
var symbol = '\u25A0';

write = write || process.stdout.write.bind(process.stdout);

listOfStats.forEach(function (stats, index) {
titles[index] = stats.title || '';
labels[index] = (index + 1) + "";
});

// trim titles to be at most 20 characters
titles = titles.map(function (title) {
if (title.length > 20) {
return title.substr(0, 17) + '...';
}
return title;
});

var maxLabel = labels.reduce(function (memo, value) { return Math.max(memo, value.length); }, 0);
var maxTitle = titles.reduce(function (memo, value) { return Math.max(memo, value.length); }, 0);

// align right
labels = labels.map(function (value) {
while (value.length < maxLabel) {
value = ' ' + value;
}
return value;
});

// align left
titles = titles.map(function (value) {
while (value.length < maxTitle) {
value = value + ' ';
}
return value;
});

listOfStats.forEach(function (stats, index) {
if (!!stats.end && stats.passes > 0) {
write(stats.failures > 0 ? chalk.red('[' + Base.symbols.err + ']') : chalk.green('[' + Base.symbols.ok + ']'));
} else {
write(chalk.grey('[ ]'));
}
write(' ' + labels[index] + '. ');
if (titles[index]) {
write(titles[index] + ' ' + (stats.end ? '|' : '*'));
}

// draw "progress bar"
write(' ' + stats.progress.map(function (data) {
if (data.what === 'passed') {
return chalk.green(symbol);
} else if (data.what === 'skipped') {
return chalk.cyan(symbol);
} else if (data.what === 'failed') {
return chalk.red('(') + chalk.grey(data.index) + chalk.red(')');
}
}).join(''));

write('\n');
});

// number of lines added
return listOfStats.length;
}

1 change: 1 addition & 0 deletions lib/meteor/meteorProcessManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module.exports = function createMeteorProcessManager (options) {
env.PORT = meteorPort;
env.MONGO_URL = mongoUrl;
env.GAGARIN_SETTINGS = "{}"; // only used if METEOR_SETTINGS does not contain gagarin field
env.NODE_ENV = "development";

setTimeout(function () {
meteorProcess = new createMeteorProcess(pathToNode, pathToMain, env, meteorProcessPrototype, options);
Expand Down
147 changes: 140 additions & 7 deletions lib/mocha/gagarin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@

var tools = require('../tools');
var Mocha = require('mocha');
var Base = require('mocha').reporters.Base;
var chalk = require('chalk');
var path = require('path');
var util = require('util');
var url = require('url');
var logs = require('../logs');
var table = require('../logs/table');

var BuildAsPromise = require('../meteor/build');
var Promise = require('es6-promise').Promise;

var createParallelReporterFactory = require('./reporters').createParallelReporterFactory;

module.exports = Gagarin;

Expand All @@ -21,21 +28,134 @@ module.exports = Gagarin;
*
* @param {Object} options
*/

function Gagarin (options) {
"use strict";

var write = process.stdout.write.bind(process.stdout);
var velocity = null;
var listOfFrameworks = [];
var numberOfLinesPrinted = 0;

// XXX gagarin user interface is defined here
require('./interface');

options.ui = 'gagarin';
options.settings = tools.getSettings(options.settings);
options.ui = 'gagarin';

// TODO: filter out our custom options
Mocha.call(this, options);
if (options.velocity) {
velocity = require('../velocity/reporter')(function () {
var parsed = url.parse(options.velocity);
return Promise.resolve({ host: parsed.hostname, port: parsed.port || 443 });
});
}

this.settings = tools.getSettings(options.settings);
}
var factory = !options.parallel ? null : createParallelReporterFactory(function (allStats, elapsed) {
if (numberOfLinesPrinted > 0) {
write('\u001b[' + numberOfLinesPrinted + 'A')
}
write(' elapsed time: ' + Math.floor(elapsed / 100) / 10 + 's' + '\n\n');
numberOfLinesPrinted = 2 + table(allStats, write);
});

function getMocha() {

if (options.parallel === 0 && listOfFrameworks.length > 0) {
return listOfFrameworks[0];
}

var mocha = new Mocha(options);

if (factory) {
// overwrite the default reporter
mocha._reporter = factory(listOfFrameworks.length);
}

var reporter = mocha._reporter;

if (velocity) {
// hijack the active reporter
mocha._reporter = function (runner, options) {
// install the velocity reporter listeners ...
velocity(runner);
// ... but return the original value
return new reporter(runner, options);
}
}

listOfFrameworks.push(mocha);
return mocha;

}; // getMocha

util.inherits(Gagarin, Mocha);
this.options = options;

this.addFile = function (file) {
getMocha().addFile(file);
}

this.runAllFrameworks = function (callback) {

var listOfErrors = [];

var pending = listOfFrameworks.slice(0);
var counter = 0;
var running = 0;

if (factory) {
factory.reset();
process.stdout.write('\n\n');
write = logs.block();
}

listOfFrameworks.forEach(function (mocha) {
mocha.loadFiles();
mocha.files = [];
});

function finish() {
if (factory) {
logs.unblock();
factory.epilogue();
}
callback && callback(listOfErrors, counter);
}

function update() {
var availableSlots = options.parallel > 0 ? options.parallel : 1;
if (running >= availableSlots) {
return false;
}
var next = pending.shift();
if (!next) {
return false;
}
running += 1;
try {
next.run(function (numberOfFailures) {
counter += numberOfFailures;
running -= 1;
if (running === 0 && pending.length === 0) {
finish();
} else {
while (update()); // run as many suites as you can
}
});
} catch (err) {
listOfErrors.push(err);
running -= 1;
if (running === 0 && pending.length === 0) {
finish();
}
return false;
}
return true;
}

while (update()); // run as many suites as you can

}
}

/**
* A not-so-thin wrapper around Mocha.run; first build the
Expand Down Expand Up @@ -92,7 +212,19 @@ Gagarin.prototype.run = function (callback) {
if (buildOnly) {
callback(0);
} else {
Mocha.prototype.run.call(self, callback);
self.runAllFrameworks(function (listOfErrors, failures) {
if (listOfErrors.length > 0) {
// since we're now loading all files prior to an further actions, this should no longer happen
// but I am leaving this error report for now in case something unexpected happens
console.error(chalk.red(' The following errors occured while configuring some test suites:\n'));
}
listOfErrors.forEach(function (err) {
console.error(err.stack.split('\n').map(function (line) {
return ' ' + line;
}).join('\n') + '\n');
});
callback(failures + listOfErrors.length);
});
}

}, function (err) {
Expand All @@ -109,3 +241,4 @@ Gagarin.prototype.run = function (callback) {
});

};

Loading

0 comments on commit 7e0e25a

Please sign in to comment.