Skip to content

Commit

Permalink
Merge pull request #276 from gemini-testing/fix/assert.view
Browse files Browse the repository at this point in the history
fix: tests do not fail on assert view fails
  • Loading branch information
j0tunn authored Jul 17, 2018
2 parents 7d0704e + 1a5ed83 commit a1d765b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 7 additions & 3 deletions lib/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const HookRunner = require('./hook-runner');
const ExecutionThread = require('./execution-thread');
const OneTimeScreenshooter = require('./one-time-screenshooter');
const AssertViewError = require('../../../browser/commands/assert-view/errors/assert-view-error');

module.exports = class TestRunner {
static create(...args) {
Expand Down Expand Up @@ -40,9 +41,12 @@ module.exports = class TestRunner {
error = error || e;
}

hermioneCtx.assertViewResults = hermioneCtx.assertViewResults
? hermioneCtx.assertViewResults.toRawObject()
: [];
const assertViewResults = hermioneCtx.assertViewResults;
if (assertViewResults && assertViewResults.hasFails()) {
error = new AssertViewError();
}

hermioneCtx.assertViewResults = assertViewResults ? assertViewResults.toRawObject() : [];
const {meta, changes} = browser;
const results = {hermioneCtx, meta, changes};

Expand Down
24 changes: 18 additions & 6 deletions test/lib/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const HookRunner = require('lib/worker/runner/test-runner/hook-runner');
const ExecutionThread = require('lib/worker/runner/test-runner/execution-thread');
const OneTimeScreenshooter = require('lib/worker/runner/test-runner/one-time-screenshooter');
const BrowserAgent = require('lib/worker/runner/browser-agent');
const AssertViewError = require('lib/browser/commands/assert-view/errors/assert-view-error');
const AssertViewResults = require('lib/browser/commands/assert-view/assert-view-results');
const {makeConfigStub} = require('../../../../utils');
const {Suite, Test} = require('../../../_mocha');

Expand Down Expand Up @@ -234,9 +236,7 @@ describe('worker/runner/test-runner', () => {
});

it('should convert assert view results to raw object', async () => {
const assertViewResults = {
toRawObject: () => [{foo: 'bar'}]
};
const assertViewResults = AssertViewResults.create([{foo: 'bar'}]);

ExecutionThread.create.callsFake(({hermioneCtx}) => {
ExecutionThread.prototype.run.callsFake(() => {
Expand All @@ -251,6 +251,20 @@ describe('worker/runner/test-runner', () => {
assert.match(result.hermioneCtx, {assertViewResults: [{foo: 'bar'}]});
});

it('should fail if assert view results have fails', async () => {
const assertViewResults = AssertViewResults.create([new Error()]);

ExecutionThread.create.callsFake(({hermioneCtx}) => {
ExecutionThread.prototype.run.callsFake(() => {
hermioneCtx.assertViewResults = assertViewResults;
});

return Object.create(ExecutionThread.prototype);
});

await assert.isRejected(run_(), AssertViewError);
});

it('should resolve with browser meta and changes', async () => {
ExecutionThread.create.callsFake(({browser}) => {
ExecutionThread.prototype.run.callsFake(() => {
Expand Down Expand Up @@ -291,9 +305,7 @@ describe('worker/runner/test-runner', () => {
});

it('should convert assert view results to raw object', async () => {
const assertViewResults = {
toRawObject: () => [{foo: 'bar'}]
};
const assertViewResults = AssertViewResults.create([{foo: 'bar'}]);

ExecutionThread.create.callsFake(({hermioneCtx}) => {
ExecutionThread.prototype.run.callsFake(() => {
Expand Down

0 comments on commit a1d765b

Please sign in to comment.