Skip to content

Commit c2e1858

Browse files
committed
Eslint fix
1 parent ed32a4a commit c2e1858

4 files changed

Lines changed: 75 additions & 27 deletions

File tree

packages/app/src/components/workbench/console.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ export class DevtoolsConsoleLogs extends Element {
211211
<div class="console-container">
212212
${this.logs.map((log: any) => {
213213
const icon = LOG_ICONS[log.type] || LOG_ICONS.log
214-
const sourceLabel = log.source === 'test'
215-
? '[TEST]'
216-
: log.source === 'terminal'
217-
? '[WDIO]'
218-
: log.source === 'browser'
219-
? '[BROWSER]'
220-
: ''
214+
const sourceLabel =
215+
log.source === 'test'
216+
? '[TEST]'
217+
: log.source === 'terminal'
218+
? '[WDIO]'
219+
: log.source === 'browser'
220+
? '[BROWSER]'
221+
: ''
221222
const sourceClass = log.source ? `source-${log.source}` : ''
222223
223224
return html`
@@ -230,7 +231,9 @@ export class DevtoolsConsoleLogs extends Element {
230231
<div class="log-icon">${icon}</div>
231232
<div class="log-content">
232233
${sourceLabel
233-
? html`<span class="log-prefix ${sourceClass}">${sourceLabel}</span>`
234+
? html`<span class="log-prefix ${sourceClass}"
235+
>${sourceLabel}</span
236+
>`
234237
: nothing}
235238
<span class="log-message">${this.#formatArgs(log.args)}</span>
236239
</div>

packages/service/src/constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export const CONSOLE_METHODS = ['log', 'info', 'warn', 'error'] as const
1818
/**
1919
* Log level detection patterns with priority order (highest to lowest)
2020
*/
21-
export const LOG_LEVEL_PATTERNS: ReadonlyArray<{ level: 'trace' | 'debug' | 'info' | 'warn' | 'error'; pattern: RegExp }> = [
21+
export const LOG_LEVEL_PATTERNS: ReadonlyArray<{
22+
level: 'trace' | 'debug' | 'info' | 'warn' | 'error'
23+
pattern: RegExp
24+
}> = [
2225
{ level: 'trace', pattern: /\btrace\b/i },
2326
{ level: 'debug', pattern: /\bdebug\b/i },
2427
{ level: 'info', pattern: /\binfo\b/i },

packages/service/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export default class DevToolsHookService implements Services.ServiceInstance {
359359
await fs.writeFile(traceFilePath, JSON.stringify(traceLog))
360360
log.info(`DevTools trace saved to ${traceFilePath}`)
361361

362-
// Clean up console patching (but keep process output patched for final reporter output)
362+
// Clean up console patching
363363
this.#sessionCapturer.cleanup()
364364
}
365365

packages/service/src/session.ts

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import { resolve } from 'import-meta-resolve'
88
import { SevereServiceError } from 'webdriverio'
99
import type { WebDriverCommands } from '@wdio/protocols'
1010

11-
import { PAGE_TRANSITION_COMMANDS, ANSI_REGEX, CONSOLE_METHODS, LOG_LEVEL_PATTERNS, ERROR_INDICATORS, LOG_SOURCES } from './constants.js'
11+
import {
12+
PAGE_TRANSITION_COMMANDS,
13+
ANSI_REGEX,
14+
CONSOLE_METHODS,
15+
LOG_LEVEL_PATTERNS,
16+
ERROR_INDICATORS,
17+
LOG_SOURCES
18+
} from './constants.js'
1219
import { type CommandLog, type TraceLog, type LogLevel } from './types.js'
1320

1421
const log = logger('@wdio/devtools-service:SessionCapturer')
@@ -26,11 +33,17 @@ const detectLogLevel = (text: string): LogLevel => {
2633

2734
// Check log level patterns in priority order
2835
for (const { level, pattern } of LOG_LEVEL_PATTERNS) {
29-
if (pattern.test(cleanText)) return level
36+
if (pattern.test(cleanText)) {
37+
return level
38+
}
3039
}
3140

3241
// Check for error indicators
33-
if (ERROR_INDICATORS.some(indicator => cleanText.includes(indicator.toLowerCase()))) {
42+
if (
43+
ERROR_INDICATORS.some((indicator) =>
44+
cleanText.includes(indicator.toLowerCase())
45+
)
46+
) {
3447
return 'error'
3548
}
3649

@@ -40,7 +53,11 @@ const detectLogLevel = (text: string): LogLevel => {
4053
/**
4154
* Generic helper to create a console log entry
4255
*/
43-
const createLogEntry = (type: LogLevel, args: any[], source: typeof LOG_SOURCES[keyof typeof LOG_SOURCES]): ConsoleLogs => ({
56+
const createLogEntry = (
57+
type: LogLevel,
58+
args: any[],
59+
source: (typeof LOG_SOURCES)[keyof typeof LOG_SOURCES]
60+
): ConsoleLogs => ({
4461
timestamp: Date.now(),
4562
type,
4663
args,
@@ -50,7 +67,10 @@ const createLogEntry = (type: LogLevel, args: any[], source: typeof LOG_SOURCES[
5067
export class SessionCapturer {
5168
#ws: WebSocket | undefined
5269
#isInjected = false
53-
#originalConsoleMethods: Record<typeof CONSOLE_METHODS[number], typeof console.log>
70+
#originalConsoleMethods: Record<
71+
(typeof CONSOLE_METHODS)[number],
72+
typeof console.log
73+
>
5474
#originalProcessMethods: {
5575
stdoutWrite: typeof process.stdout.write
5676
stderrWrite: typeof process.stderr.write
@@ -108,13 +128,23 @@ export class SessionCapturer {
108128
CONSOLE_METHODS.forEach((method) => {
109129
const originalMethod = this.#originalConsoleMethods[method]
110130
console[method] = (...args: any[]) => {
111-
const serializedArgs = args.map(arg =>
131+
const serializedArgs = args.map((arg) =>
112132
typeof arg === 'object' && arg !== null
113-
? (() => { try { return JSON.stringify(arg) } catch { return String(arg) } })()
133+
? (() => {
134+
try {
135+
return JSON.stringify(arg)
136+
} catch {
137+
return String(arg)
138+
}
139+
})()
114140
: String(arg)
115141
)
116142

117-
const logEntry = createLogEntry(method, serializedArgs, LOG_SOURCES.TEST)
143+
const logEntry = createLogEntry(
144+
method,
145+
serializedArgs,
146+
LOG_SOURCES.TEST
147+
)
118148
this.consoleLogs.push(logEntry)
119149
this.sendUpstream('consoleLogs', [logEntry])
120150

@@ -129,22 +159,34 @@ export class SessionCapturer {
129159
#patchProcessOutput() {
130160
const captureOutput = (data: string | Uint8Array) => {
131161
const text = typeof data === 'string' ? data : data.toString()
132-
if (!text?.trim()) return
162+
if (!text?.trim()) {
163+
return
164+
}
133165

134-
text.split('\n')
135-
.filter(line => line.trim())
136-
.forEach(line => {
137-
const logEntry = createLogEntry(detectLogLevel(line), [stripAnsi(line)], LOG_SOURCES.TERMINAL)
166+
text
167+
.split('\n')
168+
.filter((line) => line.trim())
169+
.forEach((line) => {
170+
const logEntry = createLogEntry(
171+
detectLogLevel(line),
172+
[stripAnsi(line)],
173+
LOG_SOURCES.TERMINAL
174+
)
138175
this.consoleLogs.push(logEntry)
139176
this.sendUpstream('consoleLogs', [logEntry])
140177
})
141178
}
142179

143-
const patchStream = (stream: NodeJS.WriteStream, originalWrite: (...args: any[]) => boolean) => {
180+
const patchStream = (
181+
stream: NodeJS.WriteStream,
182+
originalWrite: (...args: any[]) => boolean
183+
) => {
144184
const self = this
145-
stream.write = function(data: any, ...rest: any[]): boolean {
185+
stream.write = function (data: any, ...rest: any[]): boolean {
146186
const result = originalWrite.call(stream, data, ...rest)
147-
if (data && !self.#isCapturingConsole) captureOutput(data)
187+
if (data && !self.#isCapturingConsole) {
188+
captureOutput(data)
189+
}
148190
return result
149191
} as any
150192
}
@@ -154,7 +196,7 @@ export class SessionCapturer {
154196
}
155197

156198
#restoreConsole() {
157-
CONSOLE_METHODS.forEach(method => {
199+
CONSOLE_METHODS.forEach((method) => {
158200
console[method] = this.#originalConsoleMethods[method]
159201
})
160202
}

0 commit comments

Comments
 (0)