diff --git a/lib/subcommands/bootstatus.js b/lib/subcommands/bootstatus.js index b9ac94f..5b9e7a5 100644 --- a/lib/subcommands/bootstatus.js +++ b/lib/subcommands/bootstatus.js @@ -1,6 +1,6 @@ import log from '../logger'; import { waitForCondition } from 'asyncbox'; - +import _ from 'lodash'; const commands = {}; @@ -40,7 +40,8 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) { } = opts; const udid = this.requireUdid('bootstatus'); - let status = ''; + /** @type {string[]} */ + const status = []; let isBootingFinished = false; let error = null; let timeoutHandler = null; @@ -52,17 +53,18 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) { args, asynchronous: true, }); - bootMonitor.on('output', (stdout, stderr) => { - status += stdout || stderr; - if (stdout) { - if (stdout.includes('Waiting on Data Migration') && onWaitingDataMigration) { - onWaitingDataMigration(); - } else if (stdout.includes('Waiting on System App') && onWaitingSystemApp) { - onWaitingSystemApp(); - } + const onStreamLine = (/** @type {string} */ line) => { + status.push(line); + if (onWaitingDataMigration && line.includes('Waiting on Data Migration')) { + onWaitingDataMigration(); + } else if (onWaitingSystemApp && line.includes('Waiting on System App')) { + onWaitingSystemApp(); } - }); - bootMonitor.on('exit', (code, signal) => { + }; + for (const streamName of ['stdout', 'stderr']) { + bootMonitor.on(`line-${streamName}`, onStreamLine); + } + bootMonitor.once('exit', (code, signal) => { if (timeoutHandler) { clearTimeout(timeoutHandler); } @@ -72,8 +74,10 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) { } isBootingFinished = true; } else { - status = status || signal; - error = new Error(status); + const errMessage = _.isEmpty(status) + ? `The simulator booting process has exited with code ${code} by signal ${signal}` + : status.join('\n'); + error = new Error(errMessage); if (onError) { onError(error); } @@ -105,7 +109,8 @@ commands.startBootMonitor = async function startBootMonitor (opts = {}) { const [seconds] = process.hrtime(start); throw new Error( `The simulator ${udid} has failed to finish booting after ${seconds}s. ` + - `Original status: ${status}`); + `Original status: ${status.join('\n')}` + ); } } return bootMonitor; diff --git a/package.json b/package.json index cb43781..bac6477 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "rimraf": "^5.0.0", "semver": "^7.0.0", "source-map-support": "^0.x", - "teen_process": "^2.0.0", + "teen_process": "^2.2.0", "uuid": "^10.0.0", "which": "^4.0.0" }, @@ -61,7 +61,6 @@ "singleQuote": true }, "devDependencies": { - "@appium/eslint-config-appium": "^8.0.4", "@appium/eslint-config-appium-ts": "^0.x", "@appium/tsconfig": "^0.x", "@appium/types": "^0.x",