@react-native-harness/platform-android 1.4.0-rc.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/adb-wait.test.d.ts +2 -0
- package/dist/__tests__/adb-wait.test.d.ts.map +1 -0
- package/dist/__tests__/adb-wait.test.js +69 -0
- package/dist/__tests__/app-session.test.d.ts +2 -0
- package/dist/__tests__/app-session.test.d.ts.map +1 -0
- package/dist/__tests__/app-session.test.js +57 -0
- package/dist/__tests__/avd-config.test.js +58 -0
- package/dist/__tests__/emulator-startup.test.js +30 -3
- package/dist/__tests__/instance.test.js +10 -4
- package/dist/adb.d.ts +3 -1
- package/dist/adb.d.ts.map +1 -1
- package/dist/adb.js +30 -21
- package/dist/app-session.d.ts +11 -2
- package/dist/app-session.d.ts.map +1 -1
- package/dist/app-session.js +17 -12
- package/dist/avd-config.d.ts +1 -0
- package/dist/avd-config.d.ts.map +1 -1
- package/dist/avd-config.js +11 -0
- package/dist/emulator-startup.d.ts +23 -0
- package/dist/emulator-startup.d.ts.map +1 -1
- package/dist/emulator-startup.js +58 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/instance.d.ts.map +1 -1
- package/dist/instance.js +21 -15
- package/dist/runner.d.ts +2 -2
- package/dist/runner.d.ts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/__tests__/adb-wait.test.ts +95 -0
- package/src/__tests__/app-session.test.ts +76 -0
- package/src/__tests__/avd-config.test.ts +70 -0
- package/src/__tests__/emulator-startup.test.ts +53 -6
- package/src/__tests__/instance.test.ts +107 -108
- package/src/adb.ts +72 -65
- package/src/app-session.ts +28 -12
- package/src/avd-config.ts +17 -0
- package/src/emulator-startup.ts +74 -0
- package/src/index.ts +1 -0
- package/src/instance.ts +30 -16
- package/src/runner.ts +5 -9
package/src/instance.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
HarnessPlatformRunner,
|
|
6
6
|
} from '@react-native-harness/platforms';
|
|
7
7
|
import type { Config as HarnessConfig } from '@react-native-harness/config';
|
|
8
|
-
import { logger } from '@react-native-harness/tools';
|
|
8
|
+
import { instrumented, logger, noopDiagnostics } from '@react-native-harness/tools';
|
|
9
9
|
import {
|
|
10
10
|
AndroidPlatformConfig,
|
|
11
11
|
assertAndroidDeviceEmulator,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
resolveAvdCachingEnabled,
|
|
18
18
|
} from './avd-config.js';
|
|
19
19
|
import { getAdbId } from './adb-id.js';
|
|
20
|
-
import * as
|
|
20
|
+
import * as adbModule from './adb.js';
|
|
21
21
|
import {
|
|
22
22
|
applyHarnessDebugHttpHost,
|
|
23
23
|
clearHarnessDebugHttpHost,
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
ensureAndroidEmulatorEnvironment,
|
|
30
30
|
getHostAndroidSystemImageArch,
|
|
31
31
|
} from './environment.js';
|
|
32
|
+
import { warnIfEmulatorAccelerationUnavailable } from './emulator-startup.js';
|
|
32
33
|
import { isInteractive } from '@react-native-harness/tools';
|
|
33
34
|
import fs from 'node:fs';
|
|
34
35
|
import { createAndroidAppSession } from './app-session.js';
|
|
@@ -71,13 +72,13 @@ const configureAndroidRuntime = async (
|
|
|
71
72
|
const metroPort = harnessConfig.metroPort;
|
|
72
73
|
|
|
73
74
|
await Promise.all([
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
adbModule.reversePort(adbId, metroPort),
|
|
76
|
+
adbModule.reversePort(adbId, 8080),
|
|
77
|
+
adbModule.setHideErrorDialogs(adbId, true),
|
|
77
78
|
applyHarnessDebugHttpHost(adbId, config.bundleId, `localhost:${metroPort}`),
|
|
78
79
|
]);
|
|
79
80
|
|
|
80
|
-
return
|
|
81
|
+
return adbModule.getAppUid(adbId, config.bundleId);
|
|
81
82
|
};
|
|
82
83
|
|
|
83
84
|
const startAndWaitForBoot = async ({
|
|
@@ -87,11 +88,12 @@ const startAndWaitForBoot = async ({
|
|
|
87
88
|
}: {
|
|
88
89
|
emulatorName: string;
|
|
89
90
|
signal: AbortSignal;
|
|
90
|
-
mode?: Parameters<typeof
|
|
91
|
+
mode?: Parameters<typeof adbModule.startEmulator>[1];
|
|
91
92
|
}): Promise<string> => {
|
|
92
93
|
await ensureAndroidEmulatorAvailable();
|
|
93
|
-
await
|
|
94
|
-
|
|
94
|
+
await warnIfEmulatorAccelerationUnavailable();
|
|
95
|
+
await adbModule.startEmulator(emulatorName, mode);
|
|
96
|
+
return adbModule.waitForBoot(emulatorName, signal);
|
|
95
97
|
};
|
|
96
98
|
|
|
97
99
|
const recreateAvd = async ({
|
|
@@ -106,7 +108,7 @@ const recreateAvd = async ({
|
|
|
106
108
|
throw new HarnessEmulatorConfigError(emulatorConfig.name);
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
await
|
|
111
|
+
await adbModule.createAvd({
|
|
110
112
|
name: emulatorConfig.name,
|
|
111
113
|
apiLevel: emulatorConfig.avd.apiLevel,
|
|
112
114
|
profile: emulatorConfig.avd.profile,
|
|
@@ -127,7 +129,7 @@ const prepareCachedAvd = async ({
|
|
|
127
129
|
}): Promise<string> => {
|
|
128
130
|
const emulatorName = emulatorConfig.name;
|
|
129
131
|
const hostArch = getHostAndroidSystemImageArch();
|
|
130
|
-
const hasExistingAvd = await
|
|
132
|
+
const hasExistingAvd = await adbModule.hasAvd(emulatorName);
|
|
131
133
|
const avdConfig = hasExistingAvd ? await readAvdConfig(emulatorName) : null;
|
|
132
134
|
const compatibility =
|
|
133
135
|
avdConfig == null
|
|
@@ -152,7 +154,7 @@ const prepareCachedAvd = async ({
|
|
|
152
154
|
emulatorName,
|
|
153
155
|
compatibility.reason
|
|
154
156
|
);
|
|
155
|
-
await
|
|
157
|
+
await adbModule.deleteAvd(emulatorName);
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
await recreateAvd({ emulatorConfig });
|
|
@@ -164,8 +166,8 @@ const prepareCachedAvd = async ({
|
|
|
164
166
|
});
|
|
165
167
|
|
|
166
168
|
logger.info('Saving Android emulator snapshot for %s...', emulatorName);
|
|
167
|
-
await
|
|
168
|
-
await
|
|
169
|
+
await adbModule.stopEmulator(generationAdbId);
|
|
170
|
+
await adbModule.waitForEmulatorDisconnect(generationAdbId, signal);
|
|
169
171
|
} else {
|
|
170
172
|
logger.info('Using cached Android emulator %s...', emulatorName);
|
|
171
173
|
}
|
|
@@ -183,6 +185,11 @@ export const getAndroidEmulatorPlatformInstance = async (
|
|
|
183
185
|
init: HarnessPlatformInitOptions
|
|
184
186
|
): Promise<HarnessPlatformRunner> => {
|
|
185
187
|
assertAndroidDeviceEmulator(config.device);
|
|
188
|
+
const adb = instrumented(
|
|
189
|
+
adbModule,
|
|
190
|
+
'platform.android.adb',
|
|
191
|
+
init.diagnostics ?? noopDiagnostics
|
|
192
|
+
);
|
|
186
193
|
const permissionsEnabled = harnessConfig.permissions ?? false;
|
|
187
194
|
const emulatorConfig = config.device;
|
|
188
195
|
const emulatorName = emulatorConfig.name;
|
|
@@ -290,10 +297,11 @@ export const getAndroidEmulatorPlatformInstance = async (
|
|
|
290
297
|
stopApp: () => adb.stopApp(adbId, config.bundleId),
|
|
291
298
|
getAppPid: () => adb.getAppPid(adbId, config.bundleId),
|
|
292
299
|
getLogcatTimestamp: () => adb.getLogcatTimestamp(adbId),
|
|
293
|
-
startLogcat: (args) => adb.startLogcat(adbId, args),
|
|
300
|
+
startLogcat: (args, options) => adb.startLogcat(adbId, args, options),
|
|
294
301
|
getDropboxOutput: () => adb.getDropboxPrint(adbId),
|
|
295
302
|
getExitInfo: () => adb.getActivityExitInfo(adbId, config.bundleId),
|
|
296
303
|
crashArtifactWriter: init.crashArtifactWriter,
|
|
304
|
+
signal: init.signal,
|
|
297
305
|
});
|
|
298
306
|
},
|
|
299
307
|
dispose: async () => {
|
|
@@ -315,6 +323,11 @@ export const getAndroidPhysicalDevicePlatformInstance = async (
|
|
|
315
323
|
init?: HarnessPlatformInitOptions
|
|
316
324
|
): Promise<HarnessPlatformRunner> => {
|
|
317
325
|
assertAndroidDevicePhysical(config.device);
|
|
326
|
+
const adb = instrumented(
|
|
327
|
+
adbModule,
|
|
328
|
+
'platform.android.adb',
|
|
329
|
+
init?.diagnostics ?? noopDiagnostics
|
|
330
|
+
);
|
|
318
331
|
const permissionsEnabled = harnessConfig.permissions ?? false;
|
|
319
332
|
|
|
320
333
|
const adbId = await getAdbId(config.device);
|
|
@@ -358,10 +371,11 @@ export const getAndroidPhysicalDevicePlatformInstance = async (
|
|
|
358
371
|
stopApp: () => adb.stopApp(adbId, config.bundleId),
|
|
359
372
|
getAppPid: () => adb.getAppPid(adbId, config.bundleId),
|
|
360
373
|
getLogcatTimestamp: () => adb.getLogcatTimestamp(adbId),
|
|
361
|
-
startLogcat: (args) => adb.startLogcat(adbId, args),
|
|
374
|
+
startLogcat: (args, options) => adb.startLogcat(adbId, args, options),
|
|
362
375
|
getDropboxOutput: () => adb.getDropboxPrint(adbId),
|
|
363
376
|
getExitInfo: () => adb.getActivityExitInfo(adbId, config.bundleId),
|
|
364
377
|
crashArtifactWriter: init?.crashArtifactWriter,
|
|
378
|
+
signal: init?.signal,
|
|
365
379
|
});
|
|
366
380
|
},
|
|
367
381
|
dispose: async () => {
|
package/src/runner.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HarnessPlatformRunner,
|
|
3
|
-
type HarnessPlatformInitOptions,
|
|
4
|
-
} from '@react-native-harness/platforms';
|
|
1
|
+
import { type HarnessPlatformRunnerFactory } from '@react-native-harness/platforms';
|
|
5
2
|
import type { Config as HarnessConfig } from '@react-native-harness/config';
|
|
6
3
|
import {
|
|
7
4
|
AndroidPlatformConfigSchema,
|
|
@@ -17,11 +14,10 @@ import {
|
|
|
17
14
|
initializeAndroidProcessEnv,
|
|
18
15
|
} from './environment.js';
|
|
19
16
|
|
|
20
|
-
const getAndroidRunner
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
): Promise<HarnessPlatformRunner> => {
|
|
17
|
+
const getAndroidRunner: HarnessPlatformRunnerFactory<
|
|
18
|
+
AndroidPlatformConfig,
|
|
19
|
+
HarnessConfig
|
|
20
|
+
> = async (config, harnessConfig, init) => {
|
|
25
21
|
const parsedConfig = AndroidPlatformConfigSchema.parse(config);
|
|
26
22
|
|
|
27
23
|
initializeAndroidProcessEnv();
|