Skip to content

Commit

Permalink
Merge branch '2.x' of https://github.com/linkedin/venus.js into 2.x
Browse files Browse the repository at this point in the history
Conflicts:
	test/unit/client/.venus/config
  • Loading branch information
jasonbelmonti committed Mar 16, 2015
2 parents 7c89011 + 8185a52 commit 048d808
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
10 changes: 6 additions & 4 deletions js/runner_client/VenusClientLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ VenusClientLibrary.prototype.done = function(results) {

// decorate the test results with metadata
results.userAgent = window.navigator.userAgent;
results.codeCoverageData = sandbox.contentWindow.__coverage__;
results.codeCoverageData = sandbox.contentWindow && sandbox.contentWindow.__coverage__;
results.testId = window.venus.testId;

this.socket.emit('results', results);
if (this.socket) {
this.socket.emit('results', results);
}

// append the test results to the document
doneEl.id = 'test-done-marker';
document.body.appendChild(doneEl);

$(document).trigger('results', results);

if (window.VenusTestList) {
VenusTestList.postTestResults(results);
if (window.parent && window.parent.VenusTestList && window.parent.VenusTestList.postTestResults) {
window.parent.VenusTestList.postTestResults(results);
}
};

Expand Down
25 changes: 12 additions & 13 deletions lib/uac/GhostDriverUac.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

var webdriver = require('selenium-webdriver'),
log = require('../util/logger'),
portscanner = require('portscanner'),
deferred = require('deferred'),
fsHelper = require('../util/fsHelper'),
spawn = require('child_process').spawn,
Expand All @@ -31,21 +32,11 @@ var webdriver = require('selenium-webdriver'),
* @param {Object} options
*/
function GhostDriverUac(options) {
this.host = options.host || 'http://localhast';
this.host = options.host || 'localhost';
this.port = options.port || 8910;

this.server = [
this.host || 'http://localhost',
':',
this.port
].join('');

this.startAttempts = 0;

if (this.server.indexOf('http://') !== 0) {
this.server = 'http://' + this.server;
}

if (options && options.binaryPath) {
this.binaryPath = fsHelper.getFirstValidPath(options.binaryPath);
}
Expand All @@ -67,11 +58,19 @@ GhostDriverUac.prototype.start = function () {
// First, try to kill other phantomjs processes
spawn('killall', ['-9', 'phantomjs']).on('exit', function () {
// Now, go ahead and start a new phantomjs process
spawnPhantom.call(this);
portscanner.findAPortNotInUse(this.port,
this.port + 2000,
this.host,
function(err, port) {
this.port = port;
this.server = 'http://' + this.host + ':' + this.port;
log.debug('Trying to create PhontamJS Selenium server at', this.server);
spawnPhantom.call(this);
}.bind(this));
}.bind(this));

function spawnPhantom () {
this.process = spawn(binary, ['--webdriver=' + this.options.port]);
this.process = spawn(binary, ['--webdriver=' + this.port]);
this.process.on('exit', function (code) {

// Invalid phantomjs path
Expand Down
6 changes: 5 additions & 1 deletion test/unit/client/.venus/config
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
},
includes: {
dom: [
'../../../../js/jquery/jquery-1.10.0.min.js',
'../../../../js/underscore/underscore-min.js'
],
default: [
'../../../../js/jquery/jquery-1.10.0.min.js',
'mocks/venusTestList.js',
'mocks/venus.js'
]
}
}
3 changes: 3 additions & 0 deletions test/unit/client/.venus/mocks/venus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.venus = window.venus || {
testId: 1
};
3 changes: 3 additions & 0 deletions test/unit/client/.venus/mocks/venusTestList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.parent.VenusTestList = window.parent.VenusTestList || {
postTestResults: function() {}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="sandbox"></div>
26 changes: 21 additions & 5 deletions test/unit/client/runner_client/VenusClientLibrary.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
/**
* @venus-fixture VenusClientLibrary.fixture.html
* @venus-code runnerClient/VenusClientLibrary.js
*/
describe('VenusClientLibrary', function() {
function createInstance() {
return new VenusClientLibrary({
host: 'www.example.com',
port: 1234
});
}

it('should expect on the window as VenusClientLibrary', function() {
expect(window.VenusClientLibrary).to.be.ok();
});

it('should instantiate a new VenusClientLibrary object', function() {
var venusClientLibrary = new VenusClientLibrary({
host: 'www.example.com',
port: 1234
});
expect(createInstance()).to.be.a(VenusClientLibrary);
});

describe('.done()', function() {
it('should execute VenusTestList.postTestReults from the parent context', sinon.test(function() {
var instance = createInstance(),
resultsStub = this.stub(window.parent.VenusTestList, 'postTestResults'),
results = {
band: 'Godspeed You! Black Emperor'
};

expect(venusClientLibrary).to.be.a(VenusClientLibrary);
instance.done(results);
sinon.assert.calledWith(resultsStub, sinon.match(results));
}));
});
});

0 comments on commit 048d808

Please sign in to comment.