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

feat: enhance stacktraces #916

Merged
merged 1 commit into from
Apr 25, 2024
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
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 => {
Copy link
Member

Choose a reason for hiding this comment

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

👍

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
8 changes: 8 additions & 0 deletions src/browser/stacktrace/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const WDIO_STACK_TRACE_LIMIT = 64;
export const WDIO_IGNORED_STACK_FUNCTIONS = [
"Browser.wrapCommandFn",
"Element.wrapCommandFn",
"Element.<anonymous>",
"Element.newCommand",
"Element.elementErrorHandlerCallbackFn",
];
Loading
Loading