diff --git a/lib/gui/tool-runner-factory/base-tool-runner.js b/lib/gui/tool-runner-factory/base-tool-runner.js index ee6373551..4e7d0199d 100644 --- a/lib/gui/tool-runner-factory/base-tool-runner.js +++ b/lib/gui/tool-runner-factory/base-tool-runner.js @@ -22,6 +22,7 @@ module.exports = class ToolRunner { this._testFiles = [].concat(paths); this._tool = tool; this._tree = null; + this._collection = null; this._globalOpts = globalOpts; this._guiOpts = guiOpts; @@ -41,7 +42,18 @@ module.exports = class ToolRunner { initialize() { return this._readTests() - .then(() => this._subscribeOnEvents()); + .then((collection) => { + this._collection = collection; + + this._handleRunnableCollection(); + this._subscribeOnEvents(); + }); + } + + _readTests() { + const {grep, set: sets, browser: browsers} = this._globalOpts; + + return this._tool.readTests(this._testFiles, {grep, sets, browsers}); } finalize() { @@ -81,13 +93,11 @@ module.exports = class ToolRunner { }); } - _loadReuseData() { - try { - return utils.require(path.resolve(this._reportPath, 'data')); - } catch (e) { - utils.logger.warn(chalk.yellow(`Nothing to reuse in ${this._reportPath}`)); - return {}; - } + _fillTestsTree() { + const {autoRun} = this._guiOpts; + + this._tree = Object.assign(this._reportBuilder.getResult(), {gui: true, autoRun}); + this._tree.suites = this._applyReuseData(this._tree.suites); } _applyReuseData(testSuites) { @@ -103,6 +113,15 @@ module.exports = class ToolRunner { return testSuites.map((suite) => applyReuse(reuseData)(suite)); } + + _loadReuseData() { + try { + return utils.require(path.resolve(this._reportPath, 'data')); + } catch (e) { + utils.logger.warn(chalk.yellow(`Nothing to reuse in ${this._reportPath}`)); + return {}; + } + } }; function applyReuse(reuseData) { diff --git a/lib/gui/tool-runner-factory/gemini/index.js b/lib/gui/tool-runner-factory/gemini/index.js index d3037df2f..9b4279e2c 100644 --- a/lib/gui/tool-runner-factory/gemini/index.js +++ b/lib/gui/tool-runner-factory/gemini/index.js @@ -11,7 +11,6 @@ module.exports = class GeminiRunner extends BaseToolRunner { constructor(paths, tool, configs) { super(paths, tool, configs); - this._collection = null; this._collectionStates = null; } @@ -22,36 +21,29 @@ module.exports = class GeminiRunner extends BaseToolRunner { .run((collection) => this._tool.test(collection, {reporters: ['vflat']})); } - _readTests() { - const {grep, set, browser} = this._globalOpts; - const {autoRun} = this._guiOpts; + _handleRunnableCollection() { + const {browser: browsers} = this._globalOpts; + const suites = this._collection.topLevelSuites(); - return this._tool.readTests(this._testFiles, {grep, sets: set}) - .then((collection) => { - this._collection = collection; - const suites = this._collection.topLevelSuites(); - - if (browser) { - suites.forEach((suite) => { - suite.browsers = _.intersection(suite.browsers, browser); - }); - } + if (browsers) { + suites.forEach((suite) => { + suite.browsers = _.intersection(suite.browsers, browsers); + }); + } - this._collectionStates = getAllStates(this._collection.clone().allSuites()); + this._collectionStates = getAllStates(this._collection.clone().allSuites()); - this._collectionStates.forEach((state) => { - if (state.state.shouldSkip(state.browserId)) { - return this._reportBuilder.addSkipped(state); - } + this._collectionStates.forEach((state) => { + if (state.state.shouldSkip(state.browserId)) { + return this._reportBuilder.addSkipped(state); + } - const referencePath = this._tool.getScreenshotPath(state.suite, state.state.name, state.browserId); - state.referencePath = path.relative(process.cwd(), referencePath); - return this._reportBuilder.addIdle(state); - }); + const referencePath = this._tool.getScreenshotPath(state.suite, state.state.name, state.browserId); + state.referencePath = path.relative(process.cwd(), referencePath); + return this._reportBuilder.addIdle(state); + }); - this._tree = Object.assign(this._reportBuilder.getResult(), {gui: true, autoRun}); - this._tree.suites = this._applyReuseData(this._tree.suites); - }); + this._fillTestsTree(); } _subscribeOnEvents() { diff --git a/lib/gui/tool-runner-factory/hermione/index.js b/lib/gui/tool-runner-factory/hermione/index.js index 18981742e..9fac13844 100644 --- a/lib/gui/tool-runner-factory/hermione/index.js +++ b/lib/gui/tool-runner-factory/hermione/index.js @@ -11,7 +11,6 @@ module.exports = class HermioneRunner extends BaseToolRunner { constructor(paths, tool, configs) { super(paths, tool, configs); - this._collection = null; this._tests = {}; } @@ -23,26 +22,17 @@ module.exports = class HermioneRunner extends BaseToolRunner { .run((collection) => this._tool.run(collection, {grep, sets, browsers})); } - _readTests() { - const {browser: browsers} = this._globalOpts; - const {autoRun} = this._guiOpts; + _handleRunnableCollection() { + this._collection.eachTest((test, browserId) => { + const testId = formatId(test.id(), browserId); + this._tests[testId] = _.extend(test, {browserId}); - return this._tool.readTests(this._testFiles, {browsers}) - .then((collection) => { - this._collection = collection; - - this._collection.eachTest((test, browserId) => { - const testId = formatId(test.id(), browserId); - this._tests[testId] = _.extend(test, {browserId}); - - test.pending - ? this._reportBuilder.addSkipped(test) - : this._reportBuilder.addIdle(test); - }); + test.pending + ? this._reportBuilder.addSkipped(test) + : this._reportBuilder.addIdle(test); + }); - this._tree = Object.assign(this._reportBuilder.getResult(), {gui: true, autoRun}); - this._tree.suites = this._applyReuseData(this._tree.suites); - }); + this._fillTestsTree(); } _subscribeOnEvents() { diff --git a/test/lib/gui/tool-runner-factory/base-tool-runner.js b/test/lib/gui/tool-runner-factory/base-tool-runner.js index ff635c1ff..68ba034f9 100644 --- a/test/lib/gui/tool-runner-factory/base-tool-runner.js +++ b/test/lib/gui/tool-runner-factory/base-tool-runner.js @@ -114,6 +114,31 @@ describe('lib/gui/tool-runner-factory/base-tool-runner', () => { }); }); + describe(`initialize ${name}`, () => { + it('should pass paths to "readTests" method', () => { + const gui = initGuiReporter({paths: ['foo', 'bar']}); + + return gui.initialize() + .then(() => assert.calledOnceWith(tool.readTests, ['foo', 'bar'])); + }); + + it('should pass "grep", "sets" and "browsers" options to "readTests" method', () => { + const grep = 'foo'; + const set = 'bar'; + const browser = 'yabro'; + const gui = initGuiReporter({ + configs: { + program: {name: () => 'tool', grep, set, browser} + } + }); + + return gui.initialize() + .then(() => { + assert.calledOnceWith(tool.readTests, sinon.match.any, {grep, sets: set, browsers: browser}); + }); + }); + }); + describe(`finalize ${name}`, () => { it('should save data file', () => { const gui = initGuiReporter();