Skip to content

Commit 186a69c

Browse files
committed
Revert "Improved the generic working of commands recorder"
This reverts commit 260ed6e.
1 parent 4201f34 commit 186a69c

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

packages/service/src/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { WebDriverCommands } from '@wdio/protocols'
1010
import { SessionCapturer } from './session.js'
1111
import { TestReporter } from './reporter.js'
1212
import { DevToolsAppLauncher } from './launcher.js'
13-
import { getBrowserObject, isUserCommand } from './utils.ts'
13+
import { getBrowserObject } from './utils.ts'
1414
import { parse } from 'stack-trace'
1515
import { type TraceLog, TraceType } from './types.ts'
1616

@@ -156,20 +156,25 @@ export default class DevToolsHookService implements Services.ServiceInstance {
156156
* Smart stack filtering to detect top-level user commands
157157
*/
158158
const stack = parse(new Error(''))
159+
const source = stack.find((frame) =>
160+
Boolean(frame.getFileName()) &&
161+
!frame.getFileName()?.includes('node_modules')
162+
)
159163

160-
if (isUserCommand(command, stack) && this.#commandStack.length === 0) {
161-
const topFrame = stack.find(f =>
162-
f.getFileName() && !f.getFileName()!.includes('node_modules')
163-
)
164+
// If the command is a selector command, we don't want to capture it
165+
// as it is not a top-level user command.
166+
const isSelectorCommand = command.startsWith('$') || command.includes('LocateNodes')
167+
168+
if (source && this.#commandStack.length === 0 && !isSelectorCommand) {
164169
const cmdSig = JSON.stringify({
165-
command,
166-
args,
167-
src: topFrame?.getFileName() + ':' + topFrame?.getLineNumber()
168-
})
170+
command,
171+
args,
172+
src: source.getFileName() + ':' + source.getLineNumber()
173+
});
169174

170175
if (this.#lastCommandSig !== cmdSig) {
171-
this.#commandStack.push(command)
172-
this.#lastCommandSig = cmdSig
176+
this.#commandStack.push(command);
177+
this.#lastCommandSig = cmdSig;
173178
}
174179
}
175180
}

packages/service/src/utils.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
import type { StackFrame } from 'stack-trace'
2-
31
export function getBrowserObject (elem: WebdriverIO.Element | WebdriverIO.Browser): WebdriverIO.Browser {
42
const elemObject = elem as WebdriverIO.Element
53
return (elemObject as WebdriverIO.Element).parent ? getBrowserObject(elemObject.parent) : elem as WebdriverIO.Browser
64
}
7-
8-
/**
9-
* Heuristics to decide whether a command is a "user-facing" command.
10-
* - skip selector helpers ($, $$, shadow$, etc.)
11-
* - only include commands invoked from user test files (not node_modules)
12-
*/
13-
export function isUserCommand(command: string, stack: StackFrame[]): boolean {
14-
// skip selector helpers or internal "LocateNodes"
15-
if (command.startsWith('$') || command.includes('LocateNodes')) return false
16-
17-
// check if stack contains at least one frame in a test file
18-
return stack.some(frame =>
19-
frame.getFileName() &&
20-
!frame.getFileName()!.includes('node_modules')
21-
)
22-
}

0 commit comments

Comments
 (0)