Skip to content

Commit bc36bfc

Browse files
Merge pull request #891 from gemini-testing/INFRADUTY-26752.backport_v7
fix: do not ignore assertView errors in broken session rejection (v7)
2 parents a33fd1e + 5221bef commit bc36bfc

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

src/browser/existing-browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ module.exports = class ExistingBrowser extends Browser {
5858
}
5959

6060
markAsBroken() {
61+
if (this.state.isBroken) {
62+
return;
63+
}
64+
6165
this.applyState({ isBroken: true });
6266

6367
this._stubCommands();

src/worker/runner/test-runner/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ module.exports = class TestRunner {
8686
}
8787
}
8888

89+
// we need to check session twice:
90+
// 1. before afterEach hook to prevent work with broken sessions
91+
// 2. after collecting all assertView errors (including afterEach section)
92+
if (!browser.state.isBroken && isSessionBroken(error, this._config)) {
93+
browser.markAsBroken();
94+
}
95+
8996
hermioneCtx.assertViewResults = assertViewResults ? assertViewResults.toRawObject() : [];
9097
const { meta } = browser;
9198
const commandsHistory = callstackHistory ? callstackHistory.release() : [];

test/src/browser/existing-browser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,18 @@ describe("ExistingBrowser", () => {
10571057
const result = await session.foo();
10581058
assert.isUndefined(result);
10591059
});
1060+
1061+
it("should not mark session as broken twice", async () => {
1062+
session.commandList = ["foo"];
1063+
session.foo = () => "foo";
1064+
const browser = await initBrowser_();
1065+
1066+
browser.markAsBroken();
1067+
session.overwriteCommand.resetHistory();
1068+
browser.markAsBroken();
1069+
1070+
assert.notCalled(session.overwriteCommand);
1071+
});
10601072
});
10611073

10621074
describe("quit", () => {

test/src/worker/runner/test-runner/index.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe("worker/runner/test-runner", () => {
4444
const publicAPI = _.defaults(prototype, {
4545
$: sandbox.stub().named("$").resolves(mkElement_()),
4646
execute: sandbox.stub().named("execute").resolves({ x: 0, y: 0 }),
47+
assertView: sandbox.stub().named("assertView").resolves(),
4748
});
4849
config = _.defaults(config, { resetCursor: true });
4950

@@ -52,8 +53,14 @@ describe("worker/runner/test-runner", () => {
5253
publicAPI,
5354
config,
5455
meta: {},
55-
state: {},
56-
markAsBroken: sandbox.stub(),
56+
state: {
57+
isBroken: false,
58+
},
59+
markAsBroken: sandbox.stub().callsFake(() => {
60+
this.state.isBroken = true;
61+
62+
return sandbox.stub();
63+
}),
5764
};
5865
};
5966

@@ -553,16 +560,41 @@ describe("worker/runner/test-runner", () => {
553560
});
554561

555562
describe('in "afterEach" hook', () => {
556-
it("should not mark even if session is broken", async () => {
563+
it("should mark if session is broken", async () => {
557564
const config = makeConfigStub({ system: { patternsOnReject: ["FOO_BAR"] } });
558-
const runner = mkRunner_({ config });
565+
const test = mkTest_({ fn: sinon.stub().resolves() });
566+
const runner = mkRunner_({ config, test });
559567
const browser = mkBrowser_();
560568
BrowserAgent.prototype.getBrowser.resolves(browser);
569+
HookRunner.prototype.hasAfterEachHooks.returns(true);
561570
HookRunner.prototype.runAfterEachHooks.rejects(new Error("FOO_BAR"));
562571

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

565-
assert.notCalled(browser.markAsBroken);
574+
assert.calledOnce(browser.markAsBroken);
575+
});
576+
});
577+
578+
describe("with assertView errors", () => {
579+
it("should mark if test fails with screenshot error", async () => {
580+
const config = makeConfigStub({ system: { patternsOnReject: ["image comparison failed"] } });
581+
const runner = mkRunner_({ config });
582+
const browser = mkBrowser_();
583+
BrowserAgent.prototype.getBrowser.resolves(browser);
584+
585+
const assertViewResults = AssertViewResults.create([new Error("image error")]);
586+
587+
ExecutionThread.create.callsFake(({ hermioneCtx }) => {
588+
ExecutionThread.prototype.run.callsFake(() => {
589+
hermioneCtx.assertViewResults = assertViewResults;
590+
});
591+
592+
return Object.create(ExecutionThread.prototype);
593+
});
594+
595+
await run_({ runner }).catch(() => {});
596+
597+
assert.calledOnce(browser.markAsBroken);
566598
});
567599
});
568600
});

0 commit comments

Comments
 (0)