Skip to content

Commit 7838f1d

Browse files
perf: remove extra logic from new-browser
1 parent bdca2a6 commit 7838f1d

4 files changed

Lines changed: 13 additions & 71 deletions

File tree

src/browser/history/callstack.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ export class Callstack {
6565
}
6666
}
6767

68+
clear(): void {
69+
this._stack = [];
70+
this._history = [];
71+
}
72+
6873
release(): TestStep[] {
6974
const history = this._history;
7075

71-
this._stack = [];
72-
this._history = [];
76+
this.clear();
7377

7478
return history;
7579
}

src/browser/new-browser.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { Capabilities } from "@testplane/wdio-types";
66

77
import { Browser, BrowserOpts } from "./browser";
88
import signalHandler from "../signal-handler";
9-
import { runGroup } from "./history";
109
import { warn } from "../utils/logger";
1110
import { getNormalizedBrowserName } from "../utils/browser";
1211
import { getInstance } from "../config/runtime-config";
@@ -71,23 +70,9 @@ export class NewBrowser extends Browser {
7170
async init(): Promise<NewBrowser> {
7271
this._session = await this._createSession();
7372

74-
this._extendStacktrace();
75-
this._addSteps();
76-
this._addHistory();
77-
78-
await runGroup(
79-
{
80-
session: this._session,
81-
callstack: this._callstackHistory!,
82-
config: this._config,
83-
},
84-
"testplane: init browser",
85-
async () => {
86-
this._addCommands();
87-
this.restoreHttpTimeout();
88-
await this._setPageLoadTimeout();
89-
},
90-
);
73+
this._addCommands();
74+
this.restoreHttpTimeout();
75+
await this._setPageLoadTimeout();
9176

9277
return this;
9378
}

test/src/browser/history/index.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const webdriver = require("@testplane/webdriver");
44
const webdriverio = require("@testplane/webdriverio");
55
const proxyquire = require("proxyquire");
66
const { Callstack } = require("../../../../src/browser/history/callstack");
7-
const { mkNewBrowser_, mkExistingBrowser_, mkSessionStub_, createBrowserConfig_ } = require("../utils");
7+
const { mkExistingBrowser_, mkSessionStub_, createBrowserConfig_ } = require("../utils");
88

99
describe("commands-history", () => {
1010
const sandbox = sinon.createSandbox();
@@ -206,28 +206,14 @@ describe("commands-history", () => {
206206
sandbox.stub(webdriverio, "remote").resolves(mkSessionStub_());
207207
sandbox.stub(webdriverio, "attach").resolves(mkSessionStub_());
208208
sandbox.stub(webdriver.WebDriver, "newSession").resolves(mkSessionStub_());
209-
browser = mkNewBrowser_({ saveHistory: true });
210-
211-
await browser.init();
212-
});
213-
214-
mkTestsSet(() => browser, "addCommand");
215-
mkTestsSet(() => browser, "overwriteCommand");
216-
});
217-
218-
describe("ExistingBrowser", () => {
219-
let browser;
220-
221-
beforeEach(async () => {
222-
sandbox.stub(webdriverio, "attach").resolves(mkSessionStub_());
223209
const ExistingBrowser = proxyquire("src/browser/existing-browser", {
224210
"./client-bridge": {
225211
build: sandbox.stub().resolves(),
226212
},
227213
}).ExistingBrowser;
228-
browser = mkExistingBrowser_({ saveHistory: true }, undefined, ExistingBrowser);
214+
browser = mkExistingBrowser_({ saveHistory: true }, void 0, ExistingBrowser);
229215

230-
await browser.init({ sessionOpts: {}, sessionCaps: {} });
216+
await browser.init({ sessionId: "session-id", sessionCaps: {}, sessionOpts: { capabilities: {} } });
231217
});
232218

233219
mkTestsSet(() => browser, "addCommand");

test/src/browser/new-browser.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const crypto = require("crypto");
44
const proxyquire = require("proxyquire");
55
const signalHandler = require("src/signal-handler");
66
const history = require("src/browser/history");
7-
const { WEBDRIVER_PROTOCOL, DEVTOOLS_PROTOCOL, SAVE_HISTORY_MODE } = require("src/constants/config");
7+
const { WEBDRIVER_PROTOCOL, DEVTOOLS_PROTOCOL } = require("src/constants/config");
88
const { X_REQUEST_ID_DELIMITER } = require("src/constants/browser");
99
const RuntimeConfig = require("src/config/runtime-config");
1010
const { mkNewBrowser_, mkSessionStub_, mkWdPool_ } = require("./utils");
@@ -339,39 +339,6 @@ describe("NewBrowser", () => {
339339
});
340340
});
341341

342-
describe("commands-history", () => {
343-
it("should NOT init commands-history if it is off", async () => {
344-
await mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.NONE }).init();
345-
346-
assert.notCalled(initCommandHistoryStub);
347-
});
348-
349-
it("should save history of executed commands if it is enabled", async () => {
350-
await mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.ALL }).init();
351-
352-
assert.calledOnceWith(initCommandHistoryStub, session);
353-
});
354-
355-
it("should save history of executed commands if it is enabled on fails", async () => {
356-
await mkBrowser_({ saveHistoryMode: "onlyFailed" }).init();
357-
358-
assert.calledOnceWith(initCommandHistoryStub, session);
359-
});
360-
361-
it("should init commands-history before any commands have added", async () => {
362-
await mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.ALL }).init();
363-
364-
assert.callOrder(initCommandHistoryStub, session.addCommand);
365-
});
366-
367-
it('should log "init" to history if "saveHistoryMode" and "pageLoadTimeout" are set', async () => {
368-
const browser = mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.ALL, pageLoadTimeout: 500100 });
369-
await browser.init();
370-
371-
assert.calledOnceWith(runGroupStub, sinon.match.any, "testplane: init browser", sinon.match.func);
372-
});
373-
});
374-
375342
describe("set page load timeout if it is specified in a config", () => {
376343
let browser;
377344

0 commit comments

Comments
 (0)