@react-native-harness/platform-android 1.2.0-rc.1 → 1.2.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/src/adb.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { type AndroidAppLaunchOptions } from '@react-native-harness/platforms';
2
- import { logger, spawn, SubprocessError } from '@react-native-harness/tools';
2
+ import {
3
+ logger,
4
+ spawn,
5
+ SubprocessError,
6
+ type Subprocess,
7
+ } from '@react-native-harness/tools';
3
8
  import { spawn as nodeSpawn } from 'node:child_process';
4
9
  import type { ChildProcessByStdio } from 'node:child_process';
5
10
  import { access, rm } from 'node:fs/promises';
@@ -765,6 +770,15 @@ export const getLogcatTimestamp = async (adbId: string): Promise<string> => {
765
770
  return stdout.trim().replace(/^'+|'+$/g, '');
766
771
  };
767
772
 
773
+ export const startLogcat = (
774
+ adbId: string,
775
+ args: readonly string[],
776
+ ): Subprocess =>
777
+ spawn(getAdbBinaryPath(), ['-s', adbId, ...args], {
778
+ stdout: 'pipe',
779
+ stderr: 'pipe',
780
+ });
781
+
768
782
  export const getAvds = async (): Promise<string[]> => {
769
783
  try {
770
784
  const emulatorBinaryPath = await ensureEmulatorInstalled();
@@ -10,7 +10,6 @@ import {
10
10
  escapeRegExp,
11
11
  getEmitter,
12
12
  logger,
13
- spawn,
14
13
  SubprocessError,
15
14
  type Subprocess,
16
15
  } from '@react-native-harness/tools';
@@ -445,13 +444,9 @@ export const createAndroidAppMonitor = ({
445
444
  const startLogcat = async () => {
446
445
  const logcatTimestamp = await adb.getLogcatTimestamp(adbId);
447
446
 
448
- logcatProcess = spawn(
449
- 'adb',
450
- ['-s', adbId, ...getLogcatArgs(appUid, logcatTimestamp)],
451
- {
452
- stdout: 'pipe',
453
- stderr: 'pipe',
454
- }
447
+ logcatProcess = adb.startLogcat(
448
+ adbId,
449
+ getLogcatArgs(appUid, logcatTimestamp)
455
450
  );
456
451
 
457
452
  const currentProcess = logcatProcess;
package/test/setup.ts ADDED
@@ -0,0 +1,68 @@
1
+ import { PassThrough } from 'node:stream';
2
+ import { vi } from 'vitest';
3
+ import type { ChildProcessByStdio } from 'node:child_process';
4
+
5
+ const createMockChildProcess = (): ChildProcessByStdio<
6
+ null,
7
+ PassThrough,
8
+ PassThrough
9
+ > => {
10
+ const stdout = new PassThrough();
11
+ const stderr = new PassThrough();
12
+
13
+ return {
14
+ stdout,
15
+ stderr,
16
+ unref: vi.fn(),
17
+ once: vi.fn(),
18
+ removeAllListeners: vi.fn(),
19
+ } as unknown as ChildProcessByStdio<null, PassThrough, PassThrough>;
20
+ };
21
+
22
+ const createMockSubprocess = () => ({
23
+ nodeChildProcess: Promise.resolve({
24
+ kill: vi.fn(),
25
+ }),
26
+ [Symbol.asyncIterator]: async function* () {
27
+ yield* [];
28
+ },
29
+ });
30
+
31
+ vi.mock('../src/adb.js', async (importOriginal) => {
32
+ const actual = await importOriginal<typeof import('../src/adb.js')>();
33
+
34
+ return {
35
+ ...actual,
36
+ emulatorProcess: {
37
+ startDetachedProcess: vi.fn(createMockChildProcess),
38
+ },
39
+ verifyAndroidEmulatorSdk: vi.fn().mockResolvedValue(undefined),
40
+ isAppInstalled: vi.fn().mockResolvedValue(true),
41
+ reversePort: vi.fn().mockResolvedValue(undefined),
42
+ stopApp: vi.fn().mockResolvedValue(undefined),
43
+ startApp: vi.fn().mockResolvedValue(undefined),
44
+ getDeviceIds: vi.fn().mockResolvedValue([]),
45
+ getEmulatorName: vi.fn().mockResolvedValue(''),
46
+ getShellProperty: vi.fn().mockResolvedValue(''),
47
+ getDeviceInfo: vi.fn().mockResolvedValue(null),
48
+ isBootCompleted: vi.fn().mockResolvedValue(true),
49
+ stopEmulator: vi.fn().mockResolvedValue(undefined),
50
+ installApp: vi.fn().mockResolvedValue(undefined),
51
+ uninstallApp: vi.fn().mockResolvedValue(undefined),
52
+ hasAvd: vi.fn().mockResolvedValue(false),
53
+ createAvd: vi.fn().mockResolvedValue(undefined),
54
+ deleteAvd: vi.fn().mockResolvedValue(undefined),
55
+ startEmulator: vi.fn().mockResolvedValue(undefined),
56
+ waitForEmulator: vi.fn().mockResolvedValue('emulator-5554'),
57
+ waitForEmulatorDisconnect: vi.fn().mockResolvedValue(undefined),
58
+ waitForBoot: vi.fn().mockResolvedValue('emulator-5554'),
59
+ isAppRunning: vi.fn().mockResolvedValue(false),
60
+ getAppUid: vi.fn().mockResolvedValue(0),
61
+ setHideErrorDialogs: vi.fn().mockResolvedValue(undefined),
62
+ getLogcatTimestamp: vi.fn().mockResolvedValue('01-01 00:00:00.000'),
63
+ startLogcat: vi.fn(createMockSubprocess),
64
+ getAvds: vi.fn().mockResolvedValue([]),
65
+ getConnectedDevices: vi.fn().mockResolvedValue([]),
66
+ grantPermissions: vi.fn().mockResolvedValue(undefined),
67
+ };
68
+ });
package/vite.config.ts ADDED
@@ -0,0 +1,19 @@
1
+ /// <reference types='vitest' />
2
+ import { defineConfig } from 'vite';
3
+
4
+ export default defineConfig(() => ({
5
+ root: __dirname,
6
+ cacheDir: '../../node_modules/.vite/packages/platform-android',
7
+ test: {
8
+ watch: false,
9
+ globals: true,
10
+ environment: 'node',
11
+ setupFiles: ['./test/setup.ts'],
12
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
13
+ reporters: ['default'],
14
+ coverage: {
15
+ reportsDirectory: './test-output/vitest/coverage',
16
+ provider: 'v8' as const,
17
+ },
18
+ },
19
+ }));