@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.
Files changed (42) hide show
  1. package/dist/__tests__/adb-wait.test.d.ts +2 -0
  2. package/dist/__tests__/adb-wait.test.d.ts.map +1 -0
  3. package/dist/__tests__/adb-wait.test.js +69 -0
  4. package/dist/__tests__/app-session.test.d.ts +2 -0
  5. package/dist/__tests__/app-session.test.d.ts.map +1 -0
  6. package/dist/__tests__/app-session.test.js +57 -0
  7. package/dist/__tests__/avd-config.test.js +58 -0
  8. package/dist/__tests__/emulator-startup.test.js +30 -3
  9. package/dist/__tests__/instance.test.js +10 -4
  10. package/dist/adb.d.ts +3 -1
  11. package/dist/adb.d.ts.map +1 -1
  12. package/dist/adb.js +30 -21
  13. package/dist/app-session.d.ts +11 -2
  14. package/dist/app-session.d.ts.map +1 -1
  15. package/dist/app-session.js +17 -12
  16. package/dist/avd-config.d.ts +1 -0
  17. package/dist/avd-config.d.ts.map +1 -1
  18. package/dist/avd-config.js +11 -0
  19. package/dist/emulator-startup.d.ts +23 -0
  20. package/dist/emulator-startup.d.ts.map +1 -1
  21. package/dist/emulator-startup.js +58 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/instance.d.ts.map +1 -1
  26. package/dist/instance.js +21 -15
  27. package/dist/runner.d.ts +2 -2
  28. package/dist/runner.d.ts.map +1 -1
  29. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  30. package/package.json +4 -4
  31. package/src/__tests__/adb-wait.test.ts +95 -0
  32. package/src/__tests__/app-session.test.ts +76 -0
  33. package/src/__tests__/avd-config.test.ts +70 -0
  34. package/src/__tests__/emulator-startup.test.ts +53 -6
  35. package/src/__tests__/instance.test.ts +107 -108
  36. package/src/adb.ts +72 -65
  37. package/src/app-session.ts +28 -12
  38. package/src/avd-config.ts +17 -0
  39. package/src/emulator-startup.ts +74 -0
  40. package/src/index.ts +1 -0
  41. package/src/instance.ts +30 -16
  42. package/src/runner.ts +5 -9
@@ -6,6 +6,9 @@ import {
6
6
  resolveAvdCachingEnabled,
7
7
  } from '../avd-config.js';
8
8
  import { AndroidPlatformConfigSchema } from '../config.js';
9
+ import { getEmulatorCpuCores } from '../emulator-startup.js';
10
+
11
+ const emulatorCpuCores = getEmulatorCpuCores();
9
12
 
10
13
  describe('AVD config helpers', () => {
11
14
  it('parses snapshot config from Android schema', () => {
@@ -73,8 +76,11 @@ abi.type=x86_64
73
76
  hw.device.name=pixel_8
74
77
  disk.dataPartition.size=1G
75
78
  vm.heapSize=512M
79
+ hw.cpu.ncore=${emulatorCpuCores}
76
80
  `);
77
81
 
82
+ expect(avdConfig.hwCpuNcore).toBe(String(emulatorCpuCores));
83
+
78
84
  expect(
79
85
  isAvdCompatible({
80
86
  emulator: {
@@ -93,6 +99,69 @@ vm.heapSize=512M
93
99
  ).toEqual({ compatible: true });
94
100
  });
95
101
 
102
+ it('rejects AVDs missing hw.cpu.ncore', () => {
103
+ const avdConfig = parseAvdConfig(`
104
+ image.sysdir.1=system-images/android-35/default/x86_64/
105
+ abi.type=x86_64
106
+ hw.device.name=pixel_8
107
+ disk.dataPartition.size=1G
108
+ vm.heapSize=512M
109
+ `);
110
+
111
+ expect(
112
+ isAvdCompatible({
113
+ emulator: {
114
+ type: 'emulator',
115
+ name: 'Pixel_8_API_35',
116
+ avd: {
117
+ apiLevel: 35,
118
+ profile: 'pixel_8',
119
+ diskSize: '1G',
120
+ heapSize: '512M',
121
+ },
122
+ },
123
+ avdConfig,
124
+ hostArch: 'x86_64',
125
+ })
126
+ ).toMatchObject({
127
+ compatible: false,
128
+ reason: `CPU core count mismatch: expected ${emulatorCpuCores}, got missing.`,
129
+ });
130
+ });
131
+
132
+ it('rejects AVDs with a different hw.cpu.ncore', () => {
133
+ const avdConfig = parseAvdConfig(`
134
+ image.sysdir.1=system-images/android-35/default/x86_64/
135
+ abi.type=x86_64
136
+ hw.device.name=pixel_8
137
+ disk.dataPartition.size=1G
138
+ vm.heapSize=512M
139
+ hw.cpu.ncore=${emulatorCpuCores === 4 ? 3 : 4}
140
+ `);
141
+
142
+ expect(
143
+ isAvdCompatible({
144
+ emulator: {
145
+ type: 'emulator',
146
+ name: 'Pixel_8_API_35',
147
+ avd: {
148
+ apiLevel: 35,
149
+ profile: 'pixel_8',
150
+ diskSize: '1G',
151
+ heapSize: '512M',
152
+ },
153
+ },
154
+ avdConfig,
155
+ hostArch: 'x86_64',
156
+ })
157
+ ).toMatchObject({
158
+ compatible: false,
159
+ reason: `CPU core count mismatch: expected ${emulatorCpuCores}, got ${
160
+ emulatorCpuCores === 4 ? 3 : 4
161
+ }.`,
162
+ });
163
+ });
164
+
96
165
  it('accepts disk partition sizes rewritten to bytes', () => {
97
166
  const avdConfig = parseAvdConfig(`
98
167
  image.sysdir.1=system-images/android-35/default/x86_64/
@@ -100,6 +169,7 @@ abi.type=x86_64
100
169
  hw.device.name=pixel_8
101
170
  disk.dataPartition.size=6442450944
102
171
  vm.heapSize=512M
172
+ hw.cpu.ncore=${emulatorCpuCores}
103
173
  `);
104
174
 
105
175
  expect(
@@ -1,5 +1,19 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { getEmulatorStartupArgs } from '../emulator-startup.js';
2
+ import {
3
+ getEmulatorCpuCores,
4
+ getEmulatorStartupArgs,
5
+ isAccelerationUsable,
6
+ } from '../emulator-startup.js';
7
+ import { getDeviceCoreBudget } from '@react-native-harness/tools';
8
+ import os from 'node:os';
9
+
10
+ describe('getEmulatorCpuCores', () => {
11
+ it('uses the shared device-core budget for the current host', () => {
12
+ expect(getEmulatorCpuCores()).toBe(
13
+ getDeviceCoreBudget(os.availableParallelism())
14
+ );
15
+ });
16
+ });
3
17
 
4
18
  describe('emulator startup modes', () => {
5
19
  it('builds default boot args', () => {
@@ -8,17 +22,24 @@ describe('emulator startup modes', () => {
8
22
  '@Pixel_8_API_35',
9
23
  '-no-snapshot-load',
10
24
  '-no-snapshot-save',
25
+ '-no-metrics',
11
26
  ])
12
27
  );
13
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'default-boot')).not.toEqual(
14
- expect.arrayContaining(['-camera-back', 'none'])
15
- );
28
+ expect(
29
+ getEmulatorStartupArgs('Pixel_8_API_35', 'default-boot')
30
+ ).not.toEqual(expect.arrayContaining(['-camera-back', 'none']));
16
31
  });
17
32
 
18
33
  it('builds clean snapshot generation args', () => {
19
34
  expect(
20
35
  getEmulatorStartupArgs('Pixel_8_API_35', 'clean-snapshot-generation')
21
- ).toEqual(expect.arrayContaining(['@Pixel_8_API_35', '-no-snapshot-load']));
36
+ ).toEqual(
37
+ expect.arrayContaining([
38
+ '@Pixel_8_API_35',
39
+ '-no-snapshot-load',
40
+ '-no-metrics',
41
+ ])
42
+ );
22
43
  expect(
23
44
  getEmulatorStartupArgs('Pixel_8_API_35', 'clean-snapshot-generation')
24
45
  ).not.toContain('-no-snapshot-save');
@@ -26,10 +47,36 @@ describe('emulator startup modes', () => {
26
47
 
27
48
  it('builds snapshot reuse args', () => {
28
49
  expect(getEmulatorStartupArgs('Pixel_8_API_35', 'snapshot-reuse')).toEqual(
29
- expect.arrayContaining(['@Pixel_8_API_35', '-no-snapshot-save'])
50
+ expect.arrayContaining([
51
+ '@Pixel_8_API_35',
52
+ '-no-snapshot-save',
53
+ '-no-metrics',
54
+ ])
30
55
  );
31
56
  expect(
32
57
  getEmulatorStartupArgs('Pixel_8_API_35', 'snapshot-reuse')
33
58
  ).not.toContain('-no-snapshot-load');
34
59
  });
35
60
  });
61
+
62
+ describe('isAccelerationUsable', () => {
63
+ it('returns true when the emulator reports acceleration is usable', () => {
64
+ expect(
65
+ isAccelerationUsable(
66
+ 'accel:\n0\nKVM (version 12) is installed and usable.\naccel\n'
67
+ )
68
+ ).toBe(true);
69
+ });
70
+
71
+ it('returns false when acceleration is disabled', () => {
72
+ expect(
73
+ isAccelerationUsable(
74
+ 'accel:\n0\nKVM is not installed on this machine.\naccel\n'
75
+ )
76
+ ).toBe(false);
77
+ });
78
+
79
+ it('returns false for empty output', () => {
80
+ expect(isAccelerationUsable('')).toBe(false);
81
+ });
82
+ });