var async = require('async')
, _ = require('underscore')
, spawn = require('child_process').spawn
, path = require('path')
, local = require('./local')
, utils = require('./utils')
, Progress = require('./progress');
module.exports = Runner;
function Runner(options) {
this.options = _.extend({
environment: 'local',
config: './selenium.json',
parallel: false
}, options);
this.cwd = process.cwd();
var cfile = path.join(this.cwd, this.options.config);
try {
this.config = require(cfile);
} catch (e) {
if (e.message.match(/Cannot find/)) {
console.error('[error] Config file not found: ', cfile);
} else {
console.error('[error] Invalid config file: ', cfile);
}
console.error('Please specify a valid json file using -c, ' +
'or make sure there is a "selenium.json" in your current directory');
process.exit();
}
if (!this.config || !this.config.envs) {
throw new Error('Invalid config file. Need `envs: { ... }` defined');
}
this.env = this.config.envs[this.options.environment];
if (!this.env) {
throw new Error('Requested environmnet not found');
}
if (Array.isArray(this.env)) {
this.env = {browsers: this.env};
}
this.env.browsers = utils.extendEnv(this.config.envs, this.env);
}
Runner.prototype = {
execute: function (done) {
var self = this
, baseDir = path.dirname(this.options.config);
utils.resolveFiles(this.config.files, baseDir, function (err, files) {
if (err) return done(err);
if (!files.length) {
console.log('Failed to collect any files to test.', files, self.config.files);
return done();
}