Skip to content

Commit

Permalink
fix: do not ignore assertView errors in broken session rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
sipayRT committed Oct 17, 2023
1 parent 83e33e0 commit 75708f6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ module.exports = class ExistingBrowser extends Browser {
}

markAsBroken() {
if (this.state.isBroken) {
return;
}

this.applyState({ isBroken: true });

this._stubCommands();
Expand Down
7 changes: 7 additions & 0 deletions src/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ module.exports = class TestRunner {
}
}

// we need to check session twice:
// 1. before afterEach hook to prevent work with broken sessions
// 2. after collecting all assertView errors (including afterEach section)
if (isSessionBroken(error, this._config)) {
browser.markAsBroken();
}

hermioneCtx.assertViewResults = assertViewResults ? assertViewResults.toRawObject() : [];
const { meta } = browser;
const commandsHistory = callstackHistory ? callstackHistory.release() : [];
Expand Down
13 changes: 13 additions & 0 deletions test/src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,19 @@ describe("ExistingBrowser", () => {
const result = await session.foo();
assert.isUndefined(result);
});

it("should not mark session as broken twice", async () => {
session.commandList = ["foo"];
session.foo = () => "foo";
const browser = await initBrowser_();

browser.markAsBroken();
const callCount = session.overwriteCommand.callCount;
browser.markAsBroken();
const callCount2 = session.overwriteCommand.callCount;

assert.equal(callCount, callCount2);
});
});

describe("quit", () => {
Expand Down
38 changes: 32 additions & 6 deletions test/src/worker/runner/test-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("worker/runner/test-runner", () => {
const publicAPI = _.defaults(prototype, {
$: sandbox.stub().named("$").resolves(mkElement_()),
execute: sandbox.stub().named("execute").resolves({ x: 0, y: 0 }),
assertView: sandbox.stub().named("assertView").resolves(),
});
config = _.defaults(config, { resetCursor: true });

Expand Down Expand Up @@ -491,7 +492,7 @@ describe("worker/runner/test-runner", () => {

await run_({ runner }).catch(() => {});

assert.calledOnce(browser.markAsBroken);
assert.calledTwice(browser.markAsBroken);
});
});

Expand All @@ -517,7 +518,7 @@ describe("worker/runner/test-runner", () => {

await run_({ runner }).catch(() => {});

assert.calledOnce(browser.markAsBroken);
assert.calledTwice(browser.markAsBroken);
});
});

Expand All @@ -543,21 +544,46 @@ describe("worker/runner/test-runner", () => {

await run_({ runner }).catch(() => {});

assert.calledOnce(browser.markAsBroken);
assert.calledTwice(browser.markAsBroken);
});
});

describe('in "afterEach" hook', () => {
it("should not mark even if session is broken", async () => {
it("should mark if session is broken", async () => {
const config = makeConfigStub({ system: { patternsOnReject: ["FOO_BAR"] } });
const runner = mkRunner_({ config });
const test = mkTest_({ fn: sinon.stub().resolves() });
const runner = mkRunner_({ config, test });
const browser = mkBrowser_();
BrowserAgent.prototype.getBrowser.resolves(browser);
HookRunner.prototype.hasAfterEachHooks.returns(true);
HookRunner.prototype.runAfterEachHooks.rejects(new Error("FOO_BAR"));

await run_({ runner }).catch(() => {});

assert.notCalled(browser.markAsBroken);
assert.calledOnce(browser.markAsBroken);
});
});

describe("with assertView errors", () => {
it("should mark if test fails with screenshot error", async () => {
const config = makeConfigStub({ system: { patternsOnReject: ["image comparison failed"] } });
const runner = mkRunner_({ config });
const browser = mkBrowser_();
BrowserAgent.prototype.getBrowser.resolves(browser);

const assertViewResults = AssertViewResults.create([new Error("image error")]);

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

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

await run_({ runner }).catch(() => {});

assert.calledOnce(browser.markAsBroken);
});
});
});
Expand Down

0 comments on commit 75708f6

Please sign in to comment.