Skip to content

Commit

Permalink
fix: super. calls in derived artifact plugin classes
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Jul 26, 2018
1 parent 3e310cd commit ed45740
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
6 changes: 4 additions & 2 deletions detox/src/artifacts/log/android/ADBLogcatPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

Expand Down
8 changes: 6 additions & 2 deletions detox/src/artifacts/log/ios/SimulatorLogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 5 additions & 3 deletions detox/src/artifacts/screenshot/SimulatorScreenshotPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
4 changes: 2 additions & 2 deletions detox/src/artifacts/video/SimulatorRecordVideoPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 15 additions & 4 deletions detox/src/utils/exec.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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});
Expand All @@ -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
Expand Down

0 comments on commit ed45740

Please sign in to comment.