Skip to content

Commit 1fbdabb

Browse files
perf: remove extra logic from new-browser
1 parent baed939 commit 1fbdabb

4 files changed

Lines changed: 14 additions & 74 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: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { Capabilities, Options } from "@testplane/wdio-types";
88

99
import { Browser, BrowserOpts } from "./browser";
1010
import signalHandler from "../signal-handler";
11-
import { runGroup } from "./history";
1211
import { warn } from "../utils/logger";
1312
import { getNormalizedBrowserName } from "../utils/browser";
1413
import { getInstance } from "../config/runtime-config";
@@ -73,23 +72,9 @@ export class NewBrowser extends Browser {
7372
async init(): Promise<NewBrowser> {
7473
this._session = await this._createSession();
7574

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

9479
return this;
9580
}
@@ -158,9 +143,7 @@ export class NewBrowser extends Browser {
158143
}
159144

160145
const fullSessionOpts = Object.assign(sessionOpts!, thirdPartyGridCustomOptions);
161-
const sessionPromise = WebDriver.newSession(fullSessionOpts).then(res => {
162-
return res;
163-
});
146+
const sessionPromise = WebDriver.newSession(fullSessionOpts);
164147

165148
const session = await sessionPromise;
166149

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");
@@ -384,39 +384,6 @@ describe("NewBrowser", () => {
384384
});
385385
});
386386

387-
describe("commands-history", () => {
388-
it("should NOT init commands-history if it is off", async () => {
389-
await mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.NONE }).init();
390-
391-
assert.notCalled(initCommandHistoryStub);
392-
});
393-
394-
it("should save history of executed commands if it is enabled", async () => {
395-
await mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.ALL }).init();
396-
397-
assert.calledOnceWith(initCommandHistoryStub, session);
398-
});
399-
400-
it("should save history of executed commands if it is enabled on fails", async () => {
401-
await mkBrowser_({ saveHistoryMode: "onlyFailed" }).init();
402-
403-
assert.calledOnceWith(initCommandHistoryStub, session);
404-
});
405-
406-
it("should init commands-history before any commands have added", async () => {
407-
await mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.ALL }).init();
408-
409-
assert.callOrder(initCommandHistoryStub, session.addCommand);
410-
});
411-
412-
it('should log "init" to history if "saveHistoryMode" and "pageLoadTimeout" are set', async () => {
413-
const browser = mkBrowser_({ saveHistoryMode: SAVE_HISTORY_MODE.ALL, pageLoadTimeout: 500100 });
414-
await browser.init();
415-
416-
assert.calledOnceWith(runGroupStub, sinon.match.any, "testplane: init browser", sinon.match.func);
417-
});
418-
});
419-
420387
describe("set page load timeout if it is specified in a config", () => {
421388
let browser;
422389

0 commit comments

Comments
 (0)