Skip to content

Commit 72874f0

Browse files
committed
Eslint fix
1 parent 4761f4e commit 72874f0

5 files changed

Lines changed: 253 additions & 80 deletions

File tree

packages/nightwatch-devtools/src/helpers/browserProxy.ts

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,23 @@ export class BrowserProxy {
7171
const sessionCapturer = this.sessionCapturer
7272

7373
const wrapNav = (methodName: string) => {
74-
if (typeof (browser as any)[methodName] !== 'function') return
74+
if (typeof (browser as any)[methodName] !== 'function') {
75+
return
76+
}
7577
const original = (browser as any)[methodName].bind(browser)
7678

7779
;(browser as any)[methodName] = function (...args: any[]) {
7880
const result = original(...args)
7981

80-
const injectAndCapture = () =>
81-
sessionCapturer
82+
const injectAndCapture = () => {
83+
log.info(`[nav] ${methodName}(${args[0] ?? ''}) — injecting script`)
84+
return sessionCapturer
8285
.injectScript(browser)
8386
.then(() => sessionCapturer.captureTrace(browser))
8487
.catch((err: Error) =>
8588
log.error(`Failed to inject script: ${err.message}`)
8689
)
90+
}
8791

8892
if (result && typeof result.perform === 'function') {
8993
// Standard Nightwatch (chained API): queue inside perform so it
@@ -94,7 +98,9 @@ export class BrowserProxy {
9498
})
9599
} else {
96100
// Cucumber async/await: result is a Promise (or thenable).
97-
Promise.resolve(result).then(injectAndCapture).catch(() => {})
101+
Promise.resolve(result)
102+
.then(injectAndCapture)
103+
.catch(() => {})
98104
}
99105

100106
return result
@@ -162,7 +168,9 @@ export class BrowserProxy {
162168
args: any[]
163169
): any {
164170
const currentNightwatchTest = browserAny.currentTest
165-
const currentTestName = this.testManager.detectTestBoundary(currentNightwatchTest)
171+
const currentTestName = this.testManager.detectTestBoundary(
172+
currentNightwatchTest
173+
)
166174
this.testManager.startTestIfPending(currentTestName)
167175

168176
const callInfo = getCallSourceFromStack()
@@ -272,7 +280,11 @@ export class BrowserProxy {
272280
.then((screenshot) => {
273281
if (screenshot) {
274282
;(entryToScreenshot as any).screenshot = screenshot
275-
this.sessionCapturer.sendReplaceCommand(ts, entryToScreenshot)
283+
this.sessionCapturer.sendReplaceCommand(
284+
ts,
285+
entryToScreenshot
286+
)
287+
log.info(`[screenshot] Attached to ${methodName} (retry)`)
276288
}
277289
done()
278290
})
@@ -308,18 +320,26 @@ export class BrowserProxy {
308320
if (lastCommand) {
309321
this.lastCapturedId = (lastCommand as any)._id ?? null
310322
this.sessionCapturer.sendCommand(lastCommand)
323+
log.info(`[command] ${methodName}`)
311324
}
312325

313326
const entryToScreenshot = lastCommand
314-
if (entryToScreenshot && typeof (browser as any).perform === 'function') {
327+
if (
328+
entryToScreenshot &&
329+
typeof (browser as any).perform === 'function'
330+
) {
315331
const ts = (entryToScreenshot as any).timestamp
316332
;(browser as any).perform((done: Function) => {
317333
this.sessionCapturer
318334
.takeScreenshotViaHttp(browser)
319335
.then((screenshot) => {
320336
if (screenshot) {
321337
;(entryToScreenshot as any).screenshot = screenshot
322-
this.sessionCapturer.sendReplaceCommand(ts, entryToScreenshot)
338+
this.sessionCapturer.sendReplaceCommand(
339+
ts,
340+
entryToScreenshot
341+
)
342+
log.info(`[screenshot] Attached to ${methodName}`)
323343
}
324344
done()
325345
})
@@ -330,9 +350,20 @@ export class BrowserProxy {
330350
// After DOM-mutating commands, re-poll mutations from the injected
331351
// script so the browser preview stays in sync. Use setTimeout to
332352
// run OUTSIDE Nightwatch's current callback stack (safer queue-wise).
333-
const isDomMutating = (NAVIGATION_COMMANDS as readonly string[]).includes(methodName) ||
334-
['click', 'doubleClick', 'rightClick', 'setValue', 'clearValue',
335-
'sendKeys', 'submitForm', 'back', 'forward', 'refresh'].includes(methodName)
353+
const isDomMutating =
354+
(NAVIGATION_COMMANDS as readonly string[]).includes(methodName) ||
355+
[
356+
'click',
357+
'doubleClick',
358+
'rightClick',
359+
'setValue',
360+
'clearValue',
361+
'sendKeys',
362+
'submitForm',
363+
'back',
364+
'forward',
365+
'refresh'
366+
].includes(methodName)
336367
if (isDomMutating) {
337368
setTimeout(() => {
338369
this.sessionCapturer.captureTrace(browser).catch(() => {})
@@ -375,6 +406,9 @@ export class BrowserProxy {
375406
return
376407
}
377408

409+
const errMsg = error instanceof Error ? error.message : String(error)
410+
log.error(`[command error] ${methodName}: ${errMsg}`)
411+
378412
this.sessionCapturer
379413
.captureCommand(
380414
methodName,

0 commit comments

Comments
 (0)