fix(webdriver): move killDriverProcess to a node specific import
This commit is contained in:
parent
80cfd4a3d4
commit
4710259155
6 changed files with 44 additions and 26 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -10,8 +10,7 @@
|
|||
// Debugging.
|
||||
"debug.javascript.unmapMissingSources": true,
|
||||
"files.exclude": {
|
||||
"*[!test]**/node_modules": true,
|
||||
"**/build": true
|
||||
"*[!test]**/node_modules": true
|
||||
},
|
||||
"search.exclude": {
|
||||
"**/build": true
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ const log = logger('webdriver')
|
|||
environment.value = {
|
||||
Request: FetchRequest,
|
||||
Socket: BrowserSocket,
|
||||
killDriverProcess: () => { /* noop */ },
|
||||
createBidiConnection: (webSocketUrl: string, options: ClientOptions) => {
|
||||
log.info(`Connecting to webSocketUrl ${webSocketUrl}`)
|
||||
const ws = new BrowserSocket(webSocketUrl, options)
|
||||
|
|
|
|||
|
|
@ -191,33 +191,11 @@ export default function (
|
|||
const browser = this as { _bidiHandler?: BidiHandler }
|
||||
browser._bidiHandler?.close()
|
||||
|
||||
const shutdownDriver = (maskedBody.deleteSessionOpts as { shutdownDriver?: boolean })?.shutdownDriver !== false
|
||||
/**
|
||||
* kill driver process if there is one
|
||||
*/
|
||||
if (shutdownDriver && 'wdio:driverPID' in this.capabilities && this.capabilities['wdio:driverPID']) {
|
||||
log.info(`Kill driver process with PID ${this.capabilities['wdio:driverPID']}`)
|
||||
try {
|
||||
const killedSuccessfully = process.kill(this.capabilities['wdio:driverPID'], 'SIGKILL')
|
||||
if (!killedSuccessfully) {
|
||||
log.warn('Failed to kill driver process, manually clean-up might be required')
|
||||
}
|
||||
} catch (err) {
|
||||
log.warn('Failed to kill driver process', err)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
/**
|
||||
* clear up potential leaked TLS Socket handles
|
||||
* see https://github.com/puppeteer/puppeteer/pull/10667
|
||||
*/
|
||||
for (const handle of process._getActiveHandles()) {
|
||||
if (handle.servername && handle.servername.includes('edgedl.me')) {
|
||||
handle.destroy()
|
||||
}
|
||||
}
|
||||
}, 10)
|
||||
}
|
||||
const shutdownDriver = (maskedBody.deleteSessionOpts as { shutdownDriver?: boolean })?.shutdownDriver !== false
|
||||
environment.value.killDriverProcess(this.capabilities, shutdownDriver)
|
||||
|
||||
/**
|
||||
* clear logger stream if session has been terminated
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export interface EnvironmentDependencies {
|
|||
Request: typeof FetchRequest,
|
||||
Socket: typeof BrowserSocket,
|
||||
createBidiConnection: (wsUrl?: string, options?: WebSocket.ClientOptions) => Promise<WebSocket | undefined>,
|
||||
killDriverProcess: (capabilities: WebdriverIO.Capabilities, shutdownDriver: boolean) => void,
|
||||
variables: EnvironmentVariables
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +44,9 @@ export const environment: {
|
|||
get createBidiConnection(): EnvironmentDependencies['createBidiConnection'] {
|
||||
throw new Error('createBidiConnection is not available in this environment')
|
||||
},
|
||||
get killDriverProcess(): EnvironmentDependencies['killDriverProcess'] {
|
||||
throw new Error('killDriverProcess is not available in this environment')
|
||||
},
|
||||
get variables(): EnvironmentDependencies['variables'] {
|
||||
return {} as EnvironmentVariables
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import WebDriver from './index.js'
|
|||
import { FetchRequest } from './request/node.js'
|
||||
import { FetchRequest as WebFetchRequest } from './request/web.js'
|
||||
import { createBidiConnection } from './node/bidi.js'
|
||||
import { killDriverProcess } from './node/utils.js'
|
||||
import type { BrowserSocket } from './bidi/socket.js'
|
||||
|
||||
export default WebDriver
|
||||
|
|
@ -30,6 +31,7 @@ environment.value = {
|
|||
) ? WebFetchRequest : FetchRequest,
|
||||
Socket: ws as unknown as typeof BrowserSocket,
|
||||
createBidiConnection,
|
||||
killDriverProcess,
|
||||
variables: {
|
||||
WDIO_LOG_LEVEL: process.env.WDIO_LOG_LEVEL as Options.WebDriverLogTypes | undefined,
|
||||
DISABLE_WEBDRIVERIO_DEPRECATION_WARNINGS: process.env.DISABLE_WEBDRIVERIO_DEPRECATION_WARNINGS,
|
||||
|
|
|
|||
34
packages/webdriver/src/node/utils.ts
Normal file
34
packages/webdriver/src/node/utils.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import logger from '@wdio/logger'
|
||||
|
||||
const log = logger('webdriver')
|
||||
|
||||
/**
|
||||
* Kill the driver process after `deleteSession` command is done
|
||||
* @param capabilities - the capabilities of the driver
|
||||
* @param shutdownDriver - whether to shutdown the driver
|
||||
*/
|
||||
export function killDriverProcess(capabilities: WebdriverIO.Capabilities, shutdownDriver: boolean) {
|
||||
if (shutdownDriver && 'wdio:driverPID' in capabilities && capabilities['wdio:driverPID']) {
|
||||
log.info(`Kill driver process with PID ${capabilities['wdio:driverPID']}`)
|
||||
try {
|
||||
const killedSuccessfully = process.kill(capabilities['wdio:driverPID'], 'SIGKILL')
|
||||
if (!killedSuccessfully) {
|
||||
log.warn('Failed to kill driver process, manually clean-up might be required')
|
||||
}
|
||||
} catch (err) {
|
||||
log.warn('Failed to kill driver process', err)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
/**
|
||||
* clear up potential leaked TLS Socket handles
|
||||
* see https://github.com/puppeteer/puppeteer/pull/10667
|
||||
*/
|
||||
for (const handle of process._getActiveHandles()) {
|
||||
if (handle.servername && handle.servername.includes('edgedl.me')) {
|
||||
handle.destroy()
|
||||
}
|
||||
}
|
||||
}, 10)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue