MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / commandCallStructure

Function commandCallStructure

packages/wdio-utils/src/utils.ts:78–127  ·  view source on GitHub ↗
(commandName: string, args: unknown[], unfurl = false)

Source from the content-addressed store, hash-verified

76 * (for logging purposes)
77 */
78export function commandCallStructure (commandName: string, args: unknown[], unfurl = false) {
79 const callArgs = args.map((arg) => {
80 if (
81 typeof arg === 'string' &&
82 /**
83 * The regex pattern matches:
84 * - Regular functions: `function()` or `function foo()`
85 * - Async functions: `async function()` or `async function foo()`
86 * - IIFEs: `!function()`
87 * - Returned functions: `return function` or `return (function`
88 * - Returned async functions: `return async function` or `return (async function`
89 * - Arrow functions: `() =>` or `param =>` or `(param1, param2) =>`
90 */
91 /^\s*(?:(?:async\s+)?function(?:\s+\w+)?\s*\(|!function\(|return\s+\(?(?:async\s+)?function|\([^)]*\)\s*=>|\w+\s*=>)/.test(arg.trim())
92 ) {
93 arg = '<fn>'
94 } else if (
95 typeof arg === 'string' &&
96 /**
97 * the isBase64 method returns for xPath values like
98 * "/html/body/a" a true value which is why we should
99 * include a command check in here.
100 */
101 !commandName.startsWith('findElement') &&
102 /**
103 * the isBase64 method returns for the argument value like
104 * "9A562133B0552E0ECB7628F2E8A09E86" a true value which is
105 * why we should include a command check in here.
106 */
107 !commandName.startsWith('switch') &&
108 isBase64(arg)
109 ) {
110 arg = SCREENSHOT_REPLACEMENT
111 } else if (typeof arg === 'string') {
112 arg = `"${arg}"`
113 } else if (typeof arg === 'function') {
114 arg = '<fn>'
115 } else if (arg === null) {
116 arg = 'null'
117 } else if (typeof arg === 'object') {
118 arg = unfurl ? JSON.stringify(arg) : '<object>'
119 } else if (typeof arg === 'undefined') {
120 arg = typeof arg
121 }
122
123 return arg
124 }).join(', ')
125
126 return `${commandName}(${callArgs})`
127}
128
129/**
130 * transforms WebDriver result for log stream to avoid unnecessary long

Callers 3

command.tsFile · 0.90
WebDriverFunction · 0.85
utils.test.tsFile · 0.85

Calls 1

isBase64Function · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…