diff --git a/detox/src/artifacts/log/android/ADBLogcatPlugin.js b/detox/src/artifacts/log/android/ADBLogcatPlugin.js index 8a2a1033b0..292dc19d76 100644 --- a/detox/src/artifacts/log/android/ADBLogcatPlugin.js +++ b/detox/src/artifacts/log/android/ADBLogcatPlugin.js @@ -9,9 +9,11 @@ class ADBLogcatPlugin extends LogArtifactPlugin { this._devicePathBuilder = config.devicePathBuilder; } - async onLaunchApp({ pid }) { + async onLaunchApp(event) { + super.onLaunchApp(event); + if (this.currentRecording) { - await this.currentRecording.start({ pid }); + await this.currentRecording.start({ pid: event.pid }); } } diff --git a/detox/src/artifacts/log/ios/SimulatorLogPlugin.js b/detox/src/artifacts/log/ios/SimulatorLogPlugin.js index 4d4c316492..a4415ff560 100644 --- a/detox/src/artifacts/log/ios/SimulatorLogPlugin.js +++ b/detox/src/artifacts/log/ios/SimulatorLogPlugin.js @@ -9,13 +9,17 @@ class SimulatorLogPlugin extends LogArtifactPlugin { this.appleSimUtils = config.appleSimUtils; } - async onShutdownDevice() { + async onShutdownDevice(event) { + await super.onShutdownDevice(event); + if (this.currentRecording) { await this.currentRecording.stop(); } } - async onLaunchApp() { + async onLaunchApp(event) { + await super.onLaunchApp(event); + if (this.currentRecording) { await this.currentRecording.start(); } diff --git a/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js b/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js index d569cc04e8..9e91cace2e 100644 --- a/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js +++ b/detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js @@ -12,26 +12,28 @@ class SimulatorScreenshotter extends ScreenshotArtifactPlugin { this.appleSimUtils = config.appleSimUtils; } - async onBootDevice({ coldBoot, deviceId }) { - if (this.enabled && coldBoot) { + async onBootDevice(event) { + super.onBootDevice(event); + + if (this.enabled && event.coldBoot) { // NOTE: the line below is supposed to prevent an error, which tends to occur // when you take a screenshot for the first time on iOS Simulator running // in a hidden window mode or on CI. This is why we don't write the screenshot // anywhere and ignore an error. - await this.appleSimUtils.takeScreenshot(deviceId, '/dev/null').catch(_.noop); + await this.appleSimUtils.takeScreenshot(event.deviceId, '/dev/null').catch(_.noop); } } createTestArtifact() { - const { api, appleSimUtils } = this; + const { context, appleSimUtils } = this; const temporaryFilePath = tempfile('.png'); return new Artifact({ name: 'SimulatorScreenshot', async start() { - await appleSimUtils.takeScreenshot(api.getDeviceId(), temporaryFilePath); + await appleSimUtils.takeScreenshot(context.deviceId, temporaryFilePath); }, async save(artifactPath) { diff --git a/detox/src/artifacts/templates/plugin/__mocks__/ArtifactsApi.mock.js b/detox/src/artifacts/templates/plugin/__mocks__/ArtifactsApi.mock.js index 9ef8a6d709..228d21fd43 100644 --- a/detox/src/artifacts/templates/plugin/__mocks__/ArtifactsApi.mock.js +++ b/detox/src/artifacts/templates/plugin/__mocks__/ArtifactsApi.mock.js @@ -1,8 +1,5 @@ class ArtifactsApiMock { constructor() { - this.getDeviceId = jest.fn(); - this.getBundleId = jest.fn(); - this.getPid = jest.fn(); this.preparePathForArtifact = jest.fn(); this.trackArtifact = jest.fn(); this.untrackArtifact = jest.fn(); diff --git a/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js b/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js index e844c11532..9eb66711b9 100644 --- a/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js +++ b/detox/src/artifacts/video/SimulatorRecordVideoPlugin.js @@ -13,14 +13,14 @@ class SimulatorRecordVideoPlugin extends VideoArtifactPlugin { } createTestRecording() { - const { api, appleSimUtils } = this; + const { context, appleSimUtils } = this; const temporaryFilePath = tempfile('.mp4'); let processPromise = null; return new Artifact({ name: 'SimulatorVideoRecording', start: async () => { - processPromise = appleSimUtils.recordVideo(api.getDeviceId(), temporaryFilePath); + processPromise = appleSimUtils.recordVideo(context.deviceId, temporaryFilePath); }, stop: async () => { if (processPromise) { diff --git a/detox/src/utils/exec.js b/detox/src/utils/exec.js index e896962cc2..94e3449339 100644 --- a/detox/src/utils/exec.js +++ b/detox/src/utils/exec.js @@ -1,8 +1,9 @@ const _ = require('lodash'); -const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); -const execLogger = require('../utils/logger').child({ __filename }); -const retry = require('../utils/retry'); const {exec, spawn} = require('child-process-promise'); +const execLogger = require('./logger').child({ __filename }); +const retry = require('./retry'); +const { escape } = require('./pipeCommands'); +const DetoxRuntimeError = require('../errors/DetoxRuntimeError'); let _operationCounter = 0; @@ -91,7 +92,7 @@ function _composeCommand(bin, options) { function spawnAndLog(command, flags, options) { const trackingId = _operationCounter++; - const cmd = [command, ...flags].join(' '); + const cmd = _joinCommandAndFlags(command, flags); const log = execLogger.child({ fn: 'spawnAndLog', cmd, trackingId }); const result = spawn(command, flags, {stdio: ['ignore', 'pipe', 'pipe'], detached: true, ...options}); @@ -118,6 +119,16 @@ function spawnAndLog(command, flags, options) { return result; } +function _joinCommandAndFlags(command, flags) { + let result = command; + + for (const flag of flags.map(String)) { + result += ' ' + (flag.indexOf(' ') === -1 ? flag : `"${escape.inQuotedString(flag)}"`); + } + + return result; +} + module.exports = { execWithRetriesAndLogs, spawnAndLog