-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* processKiller feature * changed changelog * linter fixes * linter fix * test fix * killing selenium port if port is busy * processKiller in config by default
- Loading branch information
Showing
11 changed files
with
549 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const fkill = require('fkill'); | ||
const findProcess = require('find-process'); | ||
const { command } = require('execa'); | ||
|
||
function getConfigProcessesName(drivers) { | ||
const driversName = Object.keys(drivers); | ||
const processesName = []; | ||
|
||
if (driversName && driversName.length) { | ||
for (const driverName of driversName) { | ||
if (driverName === 'chrome') { | ||
processesName.push('chromedriver'); | ||
} else if (driverName === 'firefox') { | ||
processesName.push('geckodriver'); | ||
} else if (driverName === 'chromiumedge') { | ||
processesName.push('msedgedriver'); | ||
} else if (driverName === 'ie') { | ||
processesName.push('IEDriverServer'); | ||
} else if (driverName === 'safari') { | ||
processesName.push('safaridriver'); | ||
} | ||
} | ||
} | ||
return processesName; | ||
} | ||
|
||
async function processKiller(drivers, portValue) { | ||
if (portValue) { | ||
if (!Number.isNaN(Number(`${portValue}`.startsWith(':') ? `${portValue}`.substring(1) : `${portValue}`))) { | ||
const portCast = `${portValue}`.startsWith(':') ? portValue : `:${portValue}`; | ||
|
||
await killProcessByFkill([portCast]); | ||
await killProcessByCmd([`${portValue}`.startsWith(':') ? `${portValue}`.substring(1) : portValue], 'port'); | ||
} | ||
} | ||
if (drivers && typeof drivers === 'object' && Object.keys(drivers).length) { | ||
await killProcess(getConfigProcessesName(drivers), 'name'); | ||
} | ||
} | ||
|
||
async function killProcess(processesNameArr, type) { | ||
await killProcessByFkill(processesNameArr); | ||
await killProcessByCmd(processesNameArr, type); | ||
} | ||
|
||
async function killProcessByCmd(processes, type) { | ||
if (processes && processes.length) { | ||
for (const processSingle of processes) { | ||
const results = await findProcess(type, processSingle, true); | ||
|
||
if (results && results.length) { | ||
for (const result of results) { | ||
try { | ||
if (process.platform === 'win32' && !result.name.includes('node')) { | ||
await command(`taskkill /F /IM ${result.name} /T`); | ||
|
||
console.log(`Killed process: "${processSingle}" system name is "${result.name}"`); | ||
} else if (!process.name.includes('node')) { | ||
await command(`pkill -f ${result.name}`); | ||
|
||
console.log(`Killed process: "${processSingle}" system name is "${result.name}"`); | ||
} | ||
} catch (_) { | ||
// eslint-disable-next-line no-empty | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function killProcessByFkill(processes) { | ||
for (const process of processes) { | ||
try { | ||
await fkill([process], { force: true, tree: true, ignoreCase: true }); | ||
|
||
console.log(`Killed process: "${process}"`); | ||
} catch (_) { | ||
// eslint-disable-next-line no-empty | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
processKiller, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.