Skip to content

Commit 18f6aa4

Browse files
committed
[skip ci] refactor: adb class
1 parent e73a433 commit 18f6aa4

File tree

18 files changed

+328
-285
lines changed

18 files changed

+328
-285
lines changed

detox/src/artifacts/instruments/android/AndroidInstrumentsRecording.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ const InstrumentsArtifactRecording = require('../InstrumentsArtifactRecording');
44
class AndroidInstrumentsRecording extends InstrumentsArtifactRecording {
55
constructor({ adb, pluginContext, client, deviceId, userConfig, temporaryRecordingPath }) {
66
super({ pluginContext, client, userConfig, temporaryRecordingPath });
7-
this.adb = adb;
8-
this.deviceId = deviceId;
7+
this.adb = adb.bind({ deviceId });
98
}
109

1110
async doSave(artifactPath) {
1211
await super.doSave(artifactPath);
13-
await this.adb.pull(this.deviceId, this.temporaryRecordingPath, artifactPath);
14-
await this.adb.rm(this.deviceId, this.temporaryRecordingPath, true);
12+
await this.adb.pull(this.temporaryRecordingPath, artifactPath);
13+
await this.adb.rm(this.temporaryRecordingPath, true);
1514
}
1615

1716
async doDiscard() {
18-
await this.adb.rm(this.deviceId, this.temporaryRecordingPath, true);
17+
await this.adb.rm(this.temporaryRecordingPath, true);
1918
}
2019
}
2120

detox/src/artifacts/log/android/ADBLogcatPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ADBLogcatPlugin extends LogArtifactPlugin {
1414

1515
async onBeforeLaunchApp(event) {
1616
await super.onBeforeLaunchApp(event);
17-
this._lastTimestamp = await this._adb.now(event.deviceId);
17+
this._lastTimestamp = await this._adb.bind({ deviceId: event.deviceId }).now();
1818
}
1919

2020
async onLaunchApp(event) {

detox/src/artifacts/log/android/ADBLogcatRecording.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ADBLogcatRecording extends Artifact {
1313
pathToLogOnDevice,
1414
}) {
1515
super();
16-
this.adb = adb;
16+
this.adb = adb.bind({ deviceId });
1717

1818
this.deviceId = deviceId;
1919
this.pid = pid;
@@ -28,7 +28,7 @@ class ADBLogcatRecording extends Artifact {
2828
async doStart() {
2929
const pid = this.pid.get();
3030

31-
this.processPromise = this.adb.logcat(this.deviceId, {
31+
this.processPromise = this.adb.logcat({
3232
file: this.pathToLogOnDevice,
3333
time: this.since.get(),
3434
pid: pid > 0 ? pid : 0,
@@ -42,7 +42,7 @@ class ADBLogcatRecording extends Artifact {
4242
async doStop() {
4343
try {
4444
await this._waitUntilLogFileIsCreated;
45-
this.since.set(await this.adb.now(this.deviceId));
45+
this.since.set(await this.adb.now());
4646
} finally {
4747
if (this.processPromise) {
4848
await interruptProcess(this.processPromise);
@@ -52,16 +52,16 @@ class ADBLogcatRecording extends Artifact {
5252
}
5353

5454
async doSave(artifactPath) {
55-
await this.adb.pull(this.deviceId, this.pathToLogOnDevice, artifactPath);
56-
await this.adb.rm(this.deviceId, this.pathToLogOnDevice);
55+
await this.adb.pull(this.pathToLogOnDevice, artifactPath);
56+
await this.adb.rm(this.pathToLogOnDevice);
5757
}
5858

5959
async doDiscard() {
60-
await this.adb.rm(this.deviceId, this.pathToLogOnDevice);
60+
await this.adb.rm(this.pathToLogOnDevice);
6161
}
6262

6363
async _assertLogIsCreated() {
64-
const size = await this.adb.getFileSize(this.deviceId, this.pathToLogOnDevice);
64+
const size = await this.adb.getFileSize(this.pathToLogOnDevice);
6565

6666
if (size < 0) {
6767
throw new DetoxRuntimeError({

detox/src/artifacts/screenshot/ADBScreencapPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ class ADBScreencapPlugin extends ScreenshotArtifactPlugin {
1111
}
1212

1313
createTestArtifact() {
14-
const adb = this._adb;
1514
const deviceId = this.context.deviceId;
15+
const adb = this._adb.bind({ deviceId });
1616
const pathToScreenshotOnDevice = this._devicePathBuilder.buildTemporaryArtifactPath('.png');
1717

1818
return new Artifact({
1919
name: 'ADBScreencapRecording',
2020

2121
async start() {
22-
await adb.screencap(deviceId, pathToScreenshotOnDevice);
22+
await adb.screencap(pathToScreenshotOnDevice);
2323
},
2424

2525
async save(artifactPath) {
26-
await adb.pull(deviceId, pathToScreenshotOnDevice, artifactPath);
27-
await adb.rm(deviceId, pathToScreenshotOnDevice);
26+
await adb.pull(pathToScreenshotOnDevice, artifactPath);
27+
await adb.rm(pathToScreenshotOnDevice);
2828
},
2929

3030
async discard() {
31-
await adb.rm(deviceId, pathToScreenshotOnDevice);
31+
await adb.rm(pathToScreenshotOnDevice);
3232
},
3333
});
3434
}
3535
}
3636

37-
module.exports = ADBScreencapPlugin;
37+
module.exports = ADBScreencapPlugin;

detox/src/artifacts/video/ADBScreenrecorderArtifact.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ADBVideoRecording extends Artifact {
88
constructor(config) {
99
super(config);
1010

11-
this.adb = config.adb;
11+
this.adb = config.adb.bind({ deviceId: config.deviceId });
1212
this.deviceId = config.deviceId;
1313
this.pathToVideoOnDevice = config.pathToVideoOnDevice;
1414
this.screenRecordOptions = config.screenRecordOptions || {};
@@ -18,7 +18,7 @@ class ADBVideoRecording extends Artifact {
1818
}
1919

2020
async doStart() {
21-
this.processPromise = this.adb.screenrecord(this.deviceId, {
21+
this.processPromise = this.adb.screenrecord({
2222
...this.screenRecordOptions,
2323
path: this.pathToVideoOnDevice
2424
});
@@ -40,17 +40,17 @@ class ADBVideoRecording extends Artifact {
4040

4141
async doSave(artifactPath) {
4242
await this._waitWhileVideoIsBusy;
43-
await this.adb.pull(this.deviceId, this.pathToVideoOnDevice, artifactPath);
44-
await this.adb.rm(this.deviceId, this.pathToVideoOnDevice);
43+
await this.adb.pull(this.pathToVideoOnDevice, artifactPath);
44+
await this.adb.rm(this.pathToVideoOnDevice);
4545
}
4646

4747
async doDiscard() {
4848
await this._waitWhileVideoIsBusy;
49-
await this.adb.rm(this.deviceId, this.pathToVideoOnDevice);
49+
await this.adb.rm(this.pathToVideoOnDevice);
5050
}
5151

5252
async _assertVideoIsBeingRecorded() {
53-
const size = await this.adb.getFileSize(this.deviceId, this.pathToVideoOnDevice);
53+
const size = await this.adb.getFileSize(this.pathToVideoOnDevice);
5454

5555
if (size < 1) {
5656
throw new DetoxRuntimeError({
@@ -60,7 +60,7 @@ class ADBVideoRecording extends Artifact {
6060
}
6161

6262
async _assertVideoIsNotOpenedByProcesses() {
63-
const size = await this.adb.getFileSize(this.deviceId, this.pathToVideoOnDevice);
63+
const size = await this.adb.getFileSize(this.pathToVideoOnDevice);
6464

6565
if (size < 1) {
6666
throw new DetoxRuntimeError({

detox/src/devices/allocation/drivers/android/genycloud/services/GenyInstanceLifecycleService.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class GenyInstanceLifecycleService {
3636
};
3737

3838
const result = await retry(options, doAdbConnect);
39-
return new Instance(result.instance);
39+
const instance = new Instance(result.instance);
40+
this._adb = this._adb.bind({ deviceId: instance.adbName });
41+
return instance;
4042
}
4143

4244
async deleteInstance(instanceUUID) {

0 commit comments

Comments
 (0)