Skip to content

Commit

Permalink
feat(core): added remote runner/host capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
asciidisco committed Oct 28, 2013
1 parent 69bd9a4 commit 77ed1ec
Show file tree
Hide file tree
Showing 4 changed files with 874 additions and 5 deletions.
17 changes: 16 additions & 1 deletion lib/dalek.js
Expand Up @@ -33,6 +33,7 @@ var Driver = require('./dalek/driver');
var Reporter = require('./dalek/reporter');
var Timer = require('./dalek/timer');
var Config = require('./dalek/config');
var Host = require('./dalek/host');

/**
* Default options
Expand Down Expand Up @@ -90,14 +91,23 @@ var Dalek = function (opts) {
this._setupDriverEmitter();

// check for file option, throw error if none is given
if (!Array.isArray(this.config.get('tests'))) {
// only bypasses if dalek runs in the remote mode
if (!Array.isArray(this.config.get('tests')) && !this.options.remote) {
this.reporterEvents.emit('error', 'No test files given!');
this.driverEmitter.emit('killAll');
process.exit(127);
}

// init the driver instance
this._initDriver();

// check if dalek runs as a remote browser launcher
if (this.options.remote) {
var host = new Host({reporterEvents: this.reporterEvents, config: this.config});
host.run({
port: !isNaN(parseFloat(this.options.remote)) && isFinite(this.options.remote) ? this.options.remote : false
});
}
};

/**
Expand All @@ -119,6 +129,11 @@ Dalek.prototype = {
*/

run: function () {
// early return; in case of remote
if (this.options.remote) {
return this;
}

// start the timer to measure the execution time
this.timer.start();

Expand Down
26 changes: 22 additions & 4 deletions lib/dalek/driver.js
Expand Up @@ -175,14 +175,24 @@ Driver.prototype = {
getDefaultBrowserConfiguration: function (browser, browsers) {
var browserConfiguration = {configuration: null, module: null};

// set browser configuration
if (browsers[browser]) {
browserConfiguration.configuration = browsers[browser];
}

// try to load `normal` browser modules first,
// if that doesnt work, try canary builds
try {
browserConfiguration.module = require('dalek-browser-' + browser);
// check if the browser is a remote instance
// else, try to load the local browser
if (browserConfiguration.configuration && browserConfiguration.configuration.type === 'remote') {
browserConfiguration.module = require('./remote');
} else {
browserConfiguration.module = require('dalek-browser-' + browser);
}
} catch (e) {
browserConfiguration.module = require('dalek-browser-' + browser + '-canary');
}
if (browsers[browser]) {
browserConfiguration.configuration = browsers[browser];
}

return browserConfiguration;
},
Expand Down Expand Up @@ -326,7 +336,15 @@ Driver.prototype = {
browsers = browsersRaw[0];
}

// init the browser configuration
var browserConfiguration = this.loadBrowserConfiguration(browser, browsers, driverModule);

// check if we need to inject the browser alias into the browser module
if (browserConfiguration.module.setBrowser) {
browserConfiguration.module.setBrowser(browser);
}

// init the driver instance
var driverInstance = driverModule.create({events: this.driverEmitter, reporter: this.reporterEvents, browser: browser, config: this.config, browserMo: browserConfiguration.module, browserConf: browserConfiguration.configuration});
// couple driver & session status events for the reporter
this.coupleReporterEvents(driverName, browser);
Expand Down

0 comments on commit 77ed1ec

Please sign in to comment.