Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not ignore assertView errors in broken session rejection #798

Merged
merged 1 commit into from
Oct 18, 2023
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
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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем тебе эти 2 строки (такое ощущение, что можно выгасить)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

при стабе комманд мы проходимся именно по списку команд из commandList. И стабаем только те команды, которые являются функциями

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
Loading