Skip to content

Commit

Permalink
fix: enables recording videos on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed May 17, 2018
1 parent 605f9f8 commit 830bf27
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
1 change: 0 additions & 1 deletion detox/src/artifacts/ArtifactsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class ArtifactsManager {
}

async onStart() {
await fs.ensureDir(this.artifactsRootDir);
await Promise.all(this.hooks.map(hook => hook.onStart()));
}

Expand Down
2 changes: 1 addition & 1 deletion detox/src/artifacts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const resolve = {
})),
ios: _.once((api) => new AppleSimUtilsVideoRecorder({
appleSimUtils: resolve.appleSimUtils(api),
deviceId: api.getDeviceId(),
udid: api.getDeviceId(),
})),
actual: _.once(resolveByDeviceClass({
'ios.none': (api) => resolve.artifacts.videoRecorder.none(api),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ const fs = require('fs-extra');
class AppleSimUtilsScreenshotHandle {
constructor(config) {
this.artifactPath = config.artifactPath;
this.temporaryFilePath = config.temporaryFilePath;
}

async save() {}
async save() {
await fs.ensureFile(this.artifactPath);
await fs.move(this.temporaryFilePath, this.artifactPath, { overwrite: true });
}

async discard() {
await fs.remove(this.artifactPath);
await fs.remove(this.temporaryFilePath);
}
}

Expand Down
11 changes: 7 additions & 4 deletions detox/src/artifacts/screenshotters/AppleSimUtilsScreenshotter.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
const fs = require('fs-extra');
const tempfile = require('tempfile');
const ensureExtension = require('../utils/ensureExtension');
const AppleSimUtilsScreenshotHandle = require('./AppleSimUtilsScreenshotHandle');

class AppleSimUtilsScreenshotter {
constructor(config) {
this.appleSimUtils = config.appleSimUtils;
this.temporaryFilePath = config.temporaryFilePath;
this.udid = config.udid;
}

async takeScreenshot(artifactPath) {
const pngArtifactPath = ensureExtension(artifactPath, '.png');
await fs.ensureFile(pngArtifactPath);
await this.appleSimUtils.takeScreenshot(this.udid, pngArtifactPath);
const temporaryPngPath = tempfile('.png');
await fs.ensureFile(temporaryPngPath);
await this.appleSimUtils.takeScreenshot(this.udid, temporaryPngPath);

return new AppleSimUtilsScreenshotHandle({
artifactPath: pngArtifactPath,
temporaryFilePath: temporaryPngPath,
artifactPath: ensureExtension(artifactPath, '.png'),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const tempfile = require('tempfile');
const ensureExtension = require('../utils/ensureExtension');
const IosVideoRecording = require('./AppleSimUtilsVideoRecording');

Expand All @@ -10,8 +11,9 @@ class AppleSimUtilsVideoRecorder {
recordVideo(artifactPath) {
return new IosVideoRecording({
appleSimUtils: this.appleSimUtils,
artifactPath: ensureExtension(artifactPath, '.mp4'),
udid: this.udid,
artifactPath: ensureExtension(artifactPath, '.mp4'),
temporaryFilePath: tempfile('.mp4'),
});
}
}
Expand Down
31 changes: 27 additions & 4 deletions detox/src/artifacts/videoRecorders/AppleSimUtilsVideoRecording.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
const fs = require('fs-extra');
const sleep = require('../../utils/sleep');

class AppleSimUtilsVideoRecording {
constructor(config) {
this.appleSimUtils = config.appleSimUtils;
this.artifactPath = config.artifactPath;
this.temporaryFilePath = config.temporaryFilePath;
this.udid = config.udid;
this.processPromise = null;
this.process = null;
}

async start() {
await fs.ensureFile(mp4ArtifactPath);
this.processPromise = this.appleSimUtils.recordVideo(this.udid, this.artifactPath);
await fs.ensureFile(this.temporaryFilePath);
this.processPromise = this.appleSimUtils.recordVideo(this.udid, this.temporaryFilePath);
this.process = this.processPromise.childProcess;

await this._avoidAbruptVideoBeginning();
}

async stop() {
if (!this.process) {
return;
}

await this._avoidAbruptVideoEnding();

this.process.kill('SIGINT');
await this.processPromise;
}

async save() {}
async _avoidAbruptVideoBeginning() {
await sleep(500);
}

async _avoidAbruptVideoEnding() {
await sleep(500);
}

async save() {
await fs.ensureFile(this.artifactPath);
await fs.move(this.temporaryFilePath, this.artifactPath, {
overwrite: true
});
}

async discard() {
await fs.remove(this.artifactPath);
await fs.remove(this.temporaryFilePath);
}
}

Expand Down
4 changes: 2 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"test": ":",
"packager": "react-native start",
"detox-server": "detox run-server",
"e2e:ios": "detox test --configuration ios.sim.release --debug-synchronization 10000",
"e2e:android": "detox test --configuration android.emu.release --loglevel verbose --record-videos failing",
"e2e:ios": "detox test --configuration ios.sim.release --debug-synchronization 10000 --take-screenshots failing --record-videos failing --record-logs failing",
"e2e:android": "detox test --configuration android.emu.release --take-screenshots failing --record-videos failing --record-logs failing",
"build:ios": "detox build --configuration ios.sim.release",
"build:android": "detox build --configuration android.emu.release"
},
Expand Down

0 comments on commit 830bf27

Please sign in to comment.