UNPKG

wdio-docker-service

Version:

WebdriverIO service to start and stop docker container (for Selenium and more)

53 lines (47 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runCommand = runCommand; exports.runProcess = runProcess; var _child_process = require("child_process"); /** * Runs continuous shell process * @param {String[]} cmd Shell command * @return {Promise<process>} */ function runProcess(cmd) { return new Promise((resolve, reject) => { const [app, ...args] = cmd; const childProcess = (0, _child_process.spawn)(app, args); childProcess.on('error', err => { reject(err); }); process.nextTick(() => { resolve(childProcess); }); }); } /** * Runs shell command * @param {String[]} cmd Shell command * @return {Promise<process>} */ function runCommand(cmd) { return new Promise((resolve, reject) => { const [app, ...args] = cmd; const childProcess = (0, _child_process.spawn)(app, args, { stdio: 'ignore' }); childProcess.on('error', err => { reject(err); }); childProcess.on('close', code => { if (!code) { resolve(childProcess); return; } reject(new Error(`Command '${cmd.join(' ')}' exited with code ${code}`)); }); }); }