-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from gemini-testing/config/sets
Support configuration of 'sets'
- Loading branch information
Showing
7 changed files
with
426 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,9 @@ | |
var Runner = require('./runner'), | ||
HermioneFacade = require('./hermione-facade'), | ||
RunnerEvents = require('./constants/runner-events'), | ||
pathUtils = require('./path-utils'), | ||
logger = require('./utils').logger, | ||
readTests = require('./tests-reader'), | ||
_ = require('lodash'), | ||
inherit = require('inherit'), | ||
util = require('util'), | ||
chalk = require('chalk'); | ||
inherit = require('inherit'); | ||
|
||
// Hack for [email protected] and lower | ||
// Remove restriction for maximum open concurrent sockets | ||
|
@@ -25,8 +22,6 @@ module.exports = inherit({ | |
}, | ||
|
||
run: function(testPaths, browsers) { | ||
browsers = this._filterBrowsers(browsers, _.keys(this._config.browsers)); | ||
|
||
var runner = Runner.create(this._config); | ||
runner.on(RunnerEvents.TEST_FAIL, this._fail.bind(this)); | ||
runner.on(RunnerEvents.ERROR, this._fail.bind(this)); | ||
|
@@ -35,10 +30,8 @@ module.exports = inherit({ | |
|
||
this._loadPlugins(runner); | ||
|
||
return this._getTests(testPaths) | ||
.then(function(tests) { | ||
return runner.run(tests, browsers); | ||
}) | ||
return readTests(testPaths, browsers, this._config) | ||
.then(runner.run.bind(runner)) | ||
.then(function() { | ||
return !this._failed; | ||
}.bind(this)); | ||
|
@@ -52,30 +45,6 @@ module.exports = inherit({ | |
|
||
_fail: function() { | ||
this._failed = true; | ||
}, | ||
|
||
_filterBrowsers: function(browsers, allBrowsers) { | ||
if (!browsers) { | ||
return allBrowsers; | ||
} | ||
|
||
var unknownBrowsers = _.difference(browsers, allBrowsers); | ||
if (unknownBrowsers.length) { | ||
logger.warn(util.format( | ||
'%s Unknown browsers id: %s. Use one of the browser ids specified in config file: %s', | ||
chalk.yellow('WARNING:'), unknownBrowsers.join(', '), allBrowsers.join(', ') | ||
)); | ||
} | ||
|
||
return _.intersection(browsers, allBrowsers); | ||
}, | ||
|
||
_getTests: function(paths) { | ||
if (_.isEmpty(paths)) { | ||
paths = this._config.specs; | ||
} | ||
|
||
return pathUtils.expandPaths(paths); | ||
} | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
'use strict'; | ||
|
||
var pathUtils = require('./path-utils'), | ||
logger = require('./utils').logger, | ||
chalk = require('chalk'), | ||
_ = require('lodash'), | ||
q = require('q'), | ||
format = require('util').format; | ||
|
||
module.exports = function(testPaths, browsers, config) { | ||
var specs = config.specs, | ||
configBrowsers = _.keys(config.browsers); | ||
|
||
validateUnknownBrowsers(getBrowsersFromSpecs(specs), browsers, configBrowsers); | ||
|
||
return q.all([ | ||
expandSpecs(specs, configBrowsers), | ||
pathUtils.expandPaths(testPaths) | ||
]) | ||
.spread(function(specs, testFiles) { | ||
return filterSpecs(specs, testFiles, browsers); | ||
}) | ||
.then(assignBrowsersToTestFiles); | ||
}; | ||
|
||
function validateUnknownBrowsers(specsBrowsers, cliBrowsers, configBrowsers) { | ||
var unknownBrowsers = getUnknownBrowsers_(); | ||
|
||
if (_.isEmpty(unknownBrowsers)) { | ||
return; | ||
} | ||
|
||
logger.warn(format( | ||
'%s Unknown browsers id: %s. Use one of the browser ids specified in config file: %s', | ||
chalk.yellow('WARNING:'), unknownBrowsers.join(', '), configBrowsers.join(', ') | ||
)); | ||
|
||
function getUnknownBrowsers_() { | ||
return _(specsBrowsers) | ||
.concat(cliBrowsers) | ||
.compact() | ||
.uniq() | ||
.difference(configBrowsers) | ||
.value(); | ||
} | ||
} | ||
|
||
function expandSpecs(specs, configBrowsers) { | ||
return _(specs) | ||
.map(revealSpec_) | ||
.thru(q.all) | ||
.value(); | ||
|
||
function revealSpec_(spec) { | ||
if (!_.isString(spec) && !_.isPlainObject(spec)) { | ||
throw new TypeError('config.specs must be an array of strings or/and plain objects'); | ||
} | ||
|
||
var paths = _.isString(spec) ? [spec] : spec.files; | ||
|
||
return pathUtils.expandPaths(paths) | ||
.then(function(files) { | ||
return { | ||
files: files, | ||
browsers: spec.browsers ? _.intersection(spec.browsers, configBrowsers) : configBrowsers | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
function filterSpecs(specs, testFiles, browsers) { | ||
return specs.map(function(spec) { | ||
return { | ||
files: filterSpec_(spec.files, testFiles), | ||
browsers: filterSpec_(spec.browsers, browsers) | ||
}; | ||
}); | ||
|
||
function filterSpec_(specValue, value) { | ||
return _.isEmpty(value) ? specValue : _.intersection(specValue, value); | ||
} | ||
} | ||
|
||
function assignBrowsersToTestFiles(specs) { | ||
var browsers = getBrowsersFromSpecs(specs); | ||
|
||
return _(browsers) | ||
.map(getTestFilesForBrowser_) | ||
.thru(_.zipObject.bind(null, browsers)) | ||
.omit(_.isEmpty) | ||
.value(); | ||
|
||
function getTestFilesForBrowser_(browser) { | ||
return _(specs) | ||
.filter(function(spec) { | ||
return _.contains(spec.browsers, browser); | ||
}) | ||
.thru(getFilesFromSpecs) | ||
.value(); | ||
} | ||
} | ||
|
||
function getFilesFromSpecs(specs) { | ||
return getDataFromSpecs(specs, 'files'); | ||
} | ||
|
||
function getBrowsersFromSpecs(specs) { | ||
return getDataFromSpecs(specs, 'browsers'); | ||
} | ||
|
||
function getDataFromSpecs(specs, prop) { | ||
return _(specs) | ||
.map(prop) | ||
.flatten() | ||
.uniq() | ||
.value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.