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 18, 2023
1 parent 05ec28e commit b65fe38
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,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 (!browser.state.isBroken && isSessionBroken(error, this._config)) {
browser.markAsBroken();
}

hermioneCtx.assertViewResults = assertViewResults ? assertViewResults.toRawObject() : [];
const { meta } = browser;
const commandsHistory = callstackHistory ? callstackHistory.release() : [];
Expand Down
12 changes: 12 additions & 0 deletions test/src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,18 @@ 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();
session.overwriteCommand.resetHistory();
browser.markAsBroken();

assert.notCalled(session.overwriteCommand);
});
});

describe("quit", () => {
Expand Down
42 changes: 37 additions & 5 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 All @@ -52,8 +53,14 @@ describe("worker/runner/test-runner", () => {
publicAPI,
config,
meta: {},
state: {},
markAsBroken: sandbox.stub(),
state: {
isBroken: false,
},
markAsBroken: sandbox.stub().callsFake(() => {
this.state.isBroken = true;

return sandbox.stub();
}),
};
};

Expand Down Expand Up @@ -548,16 +555,41 @@ describe("worker/runner/test-runner", () => {
});

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 b65fe38

Please sign in to comment.