Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions lib/gui/tool-runner-factory/base-tool-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
44 changes: 18 additions & 26 deletions lib/gui/tool-runner-factory/gemini/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = class GeminiRunner extends BaseToolRunner {
constructor(paths, tool, configs) {
super(paths, tool, configs);

this._collection = null;
this._collectionStates = null;
}

Expand All @@ -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() {
Expand Down
28 changes: 9 additions & 19 deletions lib/gui/tool-runner-factory/hermione/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = class HermioneRunner extends BaseToolRunner {
constructor(paths, tool, configs) {
super(paths, tool, configs);

this._collection = null;
this._tests = {};
}

Expand All @@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions test/lib/gui/tool-runner-factory/base-tool-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down