Skip to content

Commit

Permalink
feat: enhance stacktraces
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Apr 24, 2024
1 parent f08cc0a commit da9b2ad
Show file tree
Hide file tree
Showing 16 changed files with 576 additions and 20 deletions.
94 changes: 80 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"clear-require": "1.0.1",
"debug": "2.6.9",
"devtools": "8.21.0",
"error-stack-parser": "2.1.4",
"expect-webdriverio": "3.5.3",
"fastq": "1.13.0",
"fs-extra": "5.0.0",
Expand Down Expand Up @@ -106,6 +107,7 @@
"@types/chai": "4.3.4",
"@types/chai-as-promised": "7.1.5",
"@types/debug": "4.1.12",
"@types/fs-extra": "11.0.4",
"@types/lodash": "4.14.191",
"@types/node": "18.19.3",
"@types/proxyquire": "1.3.28",
Expand Down
5 changes: 5 additions & 0 deletions src/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const _ = require("lodash");
const { SAVE_HISTORY_MODE } = require("../constants/config");
const { X_REQUEST_ID_DELIMITER } = require("../constants/browser");
const history = require("./history");
const stacktrace = require("./stacktrace");
const addRunStepCommand = require("./commands/runStep").default;

const CUSTOM_SESSION_OPTS = [
Expand Down Expand Up @@ -64,6 +65,10 @@ module.exports = class Browser {
addRunStepCommand(this);
}

_extendStacktrace() {
stacktrace.enhanceStacktraces(this._session);
}

_addHistory() {
if (this._config.saveHistoryMode !== SAVE_HISTORY_MODE.NONE) {
this._callstackHistory = history.initCommandHistory(this._session);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/commands/clearSession.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Browser } from "../types";
import logger from "../../utils/logger";

export default async (browser: Browser): Promise<void> => {
export default (browser: Browser): void => {
const { publicAPI: session } = browser;

const clearStorage = async (storageName: "localStorage" | "sessionStorage"): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/browser/commands/moveCursorTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const makeMoveCursorToCommand = (session: WebdriverIO.Browser) =>
};

// TODO: remove after next major version
export default async (browser: Browser): Promise<void> => {
export default (browser: Browser): void => {
const { publicAPI: session } = browser;

session.addCommand("moveCursorTo", makeMoveCursorToCommand(session), true);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/commands/scrollIntoView.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Browser } from "../types";

// TODO: remove after fix https://github.com/webdriverio/webdriverio/issues/9620
export default async (browser: Browser): Promise<void> => {
export default (browser: Browser): void => {
const { publicAPI: session } = browser;

session.overwriteCommand(
Expand Down
2 changes: 1 addition & 1 deletion src/browser/commands/switchToRepl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Browser } from "../types";

const REPL_LINE_EVENT = "line";

export default async (browser: Browser): Promise<void> => {
export default (browser: Browser): void => {
const { publicAPI: session } = browser;

const applyContext = (replServer: repl.REPLServer, ctx: Record<string, unknown> = {}): void => {
Expand Down
1 change: 1 addition & 0 deletions src/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = class ExistingBrowser extends Browser {
this._startCollectingCustomCommands();
}

this._extendStacktrace();
this._addSteps();
this._addHistory();

Expand Down
4 changes: 2 additions & 2 deletions src/browser/history/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports.runWithHooks = ({ fn, before, after, error }) => {

return value
.catch(err => {
error();
error(err);

throw err;
})
Expand All @@ -63,7 +63,7 @@ exports.runWithHooks = ({ fn, before, after, error }) => {
return value;
} catch (err) {
if (!isReturnedValuePromise) {
error();
error(err);

throw err;
}
Expand Down
1 change: 1 addition & 0 deletions src/browser/new-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = class NewBrowser extends Browser {
async init() {
this._session = await this._createSession();

this._extendStacktrace();
this._addSteps();
this._addHistory();

Expand Down
Loading

0 comments on commit da9b2ad

Please sign in to comment.