Skip to content

Commit

Permalink
Merge branch 'release-0.4.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
apendua committed Apr 2, 2015
2 parents 70c4a83 + 50057d4 commit 7c56112
Show file tree
Hide file tree
Showing 35 changed files with 560 additions and 158 deletions.
8 changes: 4 additions & 4 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
anti:gagarin@0.4.6
anti:gagarin@0.4.7
base64@1.0.3
callback-hook@1.0.3
check@1.0.5
Expand All @@ -9,10 +9,10 @@ id-map@1.0.3
json@1.0.3
livedata@1.0.13
logging@1.0.7
meteor@1.1.5
minimongo@1.0.7
meteor@1.1.6
minimongo@1.0.8
ordered-dict@1.0.3
random@1.0.3
retry@1.0.3
tracker@1.0.6
tracker@1.0.7
underscore@1.0.3
4 changes: 4 additions & 0 deletions bin/gagarin
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var program = require('commander');
var Gagarin = require('../lib/mocha/gagarin');
var logs = require('../lib/logs');
var path = require('path');
var fs = require('fs');
var coffee = require('coffee-script/register');
Expand Down Expand Up @@ -46,6 +47,9 @@ program.parse(process.argv);
var gagarin = new Gagarin(program);
var pathToTests = program.args[0] || path.join(program.pathToApp, 'tests', 'gagarin');

// set verbose mode if necessary
logs.setVerbose(program.verbose);

if (!fs.existsSync(pathToTests)) {
console.warn('looking for tests in ' + pathToTests + ' but this path does not exist');
process.exit(1);
Expand Down
44 changes: 40 additions & 4 deletions lib/browser/browserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
var portscanner = require('portscanner');
var Promise = require('es6-promise').Promise;
var either = require('../tools').either;
var logs = require('../logs');
var url = require('url');
var wd = require('wd');
var _ = require('lodash');

module.exports = function createBrowserManager (options) {
"use strict";
Expand All @@ -16,10 +18,19 @@ module.exports = function createBrowserManager (options) {
var windowSize = options.windowSize;
var myLocation = options.location || "http://localhost:3000";
var browserPromise = null;
var getDDPSetup = typeof myLocation === 'string' ? Promise.resolve(myLocation) : myLocation.getDDPSetup;
var getDDPSetup = null;

if (typeof myLocation === 'string') {
getDDPSetup = _.memoize(function () {
return Promise.resolve(url.parse(myLocation));
});
} else if (myLocation.getDDPSetup) {

getDDPSetup = myLocation.getDDPSetup;
}

if (!getDDPSetup) {
throw new Error('the location option must be either string or a meteor server');
throw new Error("the 'location' option must be either string or a meteor server");
}

return function getBrowser () {
Expand Down Expand Up @@ -52,12 +63,19 @@ module.exports = function createBrowserManager (options) {
// NOTE: it was not easy to find in the docs, so I am leaving it here as a comment
// capabilities.loggingPrefs = { "driver": "INFO", "browser": "INFO" };

logs.system('using webdriver at ' + driverLocation);

browser.init(capabilities, either(_reject).or(function () {

logs.system('browser session initialized');

isInitialized = true;

if (windowSize) {
browser.setWindowSize(windowSize.width, windowSize.height, either(_reject).or(function () {

logs.system('resized window to ' + JSON.stringify(windowSize));

afterResize(either(_reject).or(resolve));
}));
} else {
Expand All @@ -73,11 +91,24 @@ module.exports = function createBrowserManager (options) {
function afterResize (done) {
if (getDDPSetup) {
getDDPSetup().then(function (setup) {

logs.system('connecting to meteor server at ' + JSON.stringify(setup));

if (!setup.hostname) {
setup.hostname = "localhost";
}

if (!setup.protocol) {
setup.protocol = "http";
}

if (setup.host) {
getLocation(setup.host, done);
getLocation(url.format(setup), done);

} else {
getLocation('http://localhost:' + setup.port, done);
getLocation(url.format(setup), done);
}

}).catch(done);
} else {
done(null, browser);
Expand All @@ -94,6 +125,8 @@ module.exports = function createBrowserManager (options) {
return done(null, browser);
}

logs.system('loading meteor app at ' + url);

browser.setAsyncScriptTimeout(meteorLoadTimeout, function (err) {
// XXX asyncScriptTimeout is only relevant in "onStartup" routine
if (err) {
Expand All @@ -116,6 +149,9 @@ module.exports = function createBrowserManager (options) {
return done(err);
}
if (isOK) {

logs.system('meteor code loaded');

onStartup(function (err) {
clearTimeout(handle2);
done(err, !err && browser);
Expand Down
3 changes: 2 additions & 1 deletion lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var browserHelpers = require('./helpers');
var Closure = require('../tools/closure');
var generic = require('../tools/generic');
var chalk = require('chalk');
var logs = require('../logs');

module.exports = function createBrowser (options) {
"use strict";
Expand Down Expand Up @@ -80,7 +81,7 @@ module.exports = function createBrowser (options) {
operand.browser.log('browser', function (err, listOfLogs) {
if (!err) {
listOfLogs.forEach(function (logEntry) {
console.log(chalk.yellow('[client]') + ' ' + logEntry.message);
logs.client(logEntry.message);
});
logsCache.push.apply(logsCache, listOfLogs);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ddp/ddpClientManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function createDDPClientManager () {

code = setup.code;
port = setup.port;
host = setup.host || 'localhost';
host = setup.hostname || 'localhost';

ddpClientPromise = new Promise(function (resolve, reject) {

Expand Down
74 changes: 74 additions & 0 deletions lib/logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var chalk = require('chalk');
var verbose = true;

exports.setVerbose = function (value) {
verbose = !!value;
}

exports.client = function system (data, options) {
if (!verbose) {
return;
}
var color = options && options.isError ? chalk.bgRed.white : chalk.bgYellow.black;
//--------------------------------------------------------------------------------
process.stdout.write(indent(data.toString(), color(' client '), chalk.inverse));
if (!options || !options.raw) {
process.stdout.write('\n');
}
}

exports.server = function system (data, options) {
if (!verbose) {
return;
}
var color = options && options.isError ? chalk.bgRed.white : chalk.bgBlue.white;
//------------------------------------------------------------------------------
process.stdout.write(indent(data.toString(), color(' server '), chalk.inverse));
if (!options || !options.raw) {
process.stdout.write('\n');
}
}

exports.system = function system (data, options) {
if (!verbose) {
return;
}
var color = options && options.isError ? chalk.bgRed.white : chalk.bgCyan.black;
//------------------------------------------------------------------------------
process.stdout.write(indent(data.toString(), color(' system '), chalk.inverse));
if (!options || !options.raw) {
process.stdout.write('\n');
}
}

exports.test = function system (data, options) {
if (!verbose) {
return;
}
var color = options && options.isError ? chalk.bgRed.white : chalk.bgGreen.black;
//-------------------------------------------------------------------------------
process.stdout.write(indent(data.toString(), color(' test '), chalk.inverse));
if (!options || !options.raw) {
process.stdout.write('\n');
}
}


function indent(text, prefix, color) {
if (!color) {
color = function (x) { return x; }
}
return text.toString().split('\n').map(function (line) {
var length = chalk.stripColor(prefix + " " + line).length;
if (line === '\r') {
return;
}
if (line.length === 0) {
return "";
}
if (length < process.stdout.columns) {
line += new Array(process.stdout.columns - length + 1).join(' ');
}
return prefix + color(" " + line);
}).join('\n');
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7c56112

Please sign in to comment.