@react-native-harness/platform-android 1.4.0 → 1.5.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 (77) hide show
  1. package/dist/adb.d.ts +2 -4
  2. package/dist/adb.d.ts.map +1 -1
  3. package/dist/adb.js +2 -3
  4. package/dist/app-session.d.ts +3 -12
  5. package/dist/app-session.d.ts.map +1 -1
  6. package/dist/app-session.js +23 -33
  7. package/dist/instance.d.ts.map +1 -1
  8. package/dist/instance.js +2 -4
  9. package/package.json +4 -4
  10. package/src/adb.ts +5 -6
  11. package/src/app-session.ts +14 -31
  12. package/src/instance.ts +2 -4
  13. package/dist/__tests__/adb-id.test.d.ts +0 -2
  14. package/dist/__tests__/adb-id.test.d.ts.map +0 -1
  15. package/dist/__tests__/adb-id.test.js +0 -41
  16. package/dist/__tests__/adb-wait.test.d.ts +0 -2
  17. package/dist/__tests__/adb-wait.test.d.ts.map +0 -1
  18. package/dist/__tests__/adb-wait.test.js +0 -69
  19. package/dist/__tests__/adb.test.d.ts +0 -2
  20. package/dist/__tests__/adb.test.d.ts.map +0 -1
  21. package/dist/__tests__/adb.test.js +0 -552
  22. package/dist/__tests__/app-monitor.test.d.ts +0 -2
  23. package/dist/__tests__/app-monitor.test.d.ts.map +0 -1
  24. package/dist/__tests__/app-monitor.test.js +0 -257
  25. package/dist/__tests__/app-session.test.d.ts +0 -2
  26. package/dist/__tests__/app-session.test.d.ts.map +0 -1
  27. package/dist/__tests__/app-session.test.js +0 -57
  28. package/dist/__tests__/avd-config.test.d.ts +0 -2
  29. package/dist/__tests__/avd-config.test.d.ts.map +0 -1
  30. package/dist/__tests__/avd-config.test.js +0 -232
  31. package/dist/__tests__/ci-action.test.d.ts +0 -2
  32. package/dist/__tests__/ci-action.test.d.ts.map +0 -1
  33. package/dist/__tests__/ci-action.test.js +0 -46
  34. package/dist/__tests__/crash-diagnostics.test.d.ts +0 -2
  35. package/dist/__tests__/crash-diagnostics.test.d.ts.map +0 -1
  36. package/dist/__tests__/crash-diagnostics.test.js +0 -119
  37. package/dist/__tests__/crash-parser.test.d.ts +0 -2
  38. package/dist/__tests__/crash-parser.test.d.ts.map +0 -1
  39. package/dist/__tests__/crash-parser.test.js +0 -45
  40. package/dist/__tests__/crash-reporter.test.d.ts +0 -2
  41. package/dist/__tests__/crash-reporter.test.d.ts.map +0 -1
  42. package/dist/__tests__/crash-reporter.test.js +0 -150
  43. package/dist/__tests__/emulator-startup.test.d.ts +0 -2
  44. package/dist/__tests__/emulator-startup.test.d.ts.map +0 -1
  45. package/dist/__tests__/emulator-startup.test.js +0 -47
  46. package/dist/__tests__/environment.test.d.ts +0 -2
  47. package/dist/__tests__/environment.test.d.ts.map +0 -1
  48. package/dist/__tests__/environment.test.js +0 -117
  49. package/dist/__tests__/instance.test.d.ts +0 -2
  50. package/dist/__tests__/instance.test.d.ts.map +0 -1
  51. package/dist/__tests__/instance.test.js +0 -599
  52. package/dist/__tests__/shared-prefs.test.d.ts +0 -2
  53. package/dist/__tests__/shared-prefs.test.d.ts.map +0 -1
  54. package/dist/__tests__/shared-prefs.test.js +0 -87
  55. package/dist/__tests__/targets.test.d.ts +0 -2
  56. package/dist/__tests__/targets.test.d.ts.map +0 -1
  57. package/dist/__tests__/targets.test.js +0 -49
  58. package/dist/app-monitor.d.ts +0 -13
  59. package/dist/app-monitor.d.ts.map +0 -1
  60. package/dist/app-monitor.js +0 -376
  61. package/dist/device-state.d.ts +0 -6
  62. package/dist/device-state.d.ts.map +0 -1
  63. package/dist/device-state.js +0 -142
  64. package/dist/tsconfig.lib.tsbuildinfo +0 -1
  65. package/src/__tests__/adb-id.test.ts +0 -51
  66. package/src/__tests__/adb-wait.test.ts +0 -95
  67. package/src/__tests__/app-session.test.ts +0 -76
  68. package/src/__tests__/avd-config.test.ts +0 -276
  69. package/src/__tests__/ci-action.test.ts +0 -81
  70. package/src/__tests__/crash-diagnostics.test.ts +0 -144
  71. package/src/__tests__/crash-parser.test.ts +0 -52
  72. package/src/__tests__/crash-reporter.test.ts +0 -167
  73. package/src/__tests__/emulator-startup.test.ts +0 -82
  74. package/src/__tests__/instance.test.ts +0 -844
  75. package/src/__tests__/shared-prefs.test.ts +0 -144
  76. package/src/__tests__/targets.test.ts +0 -53
  77. package/tsconfig.tsbuildinfo +0 -1
@@ -1,119 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { collectDropboxArtifacts, filterExitInfo, getBestDropboxArtifact, parseDropboxOutput, } from '../crash-diagnostics.js';
3
- const javaCrashDropbox = `
4
- Drop box contents: 1 entries
5
- Max entries: 1000
6
- ========================================
7
- 2026-03-12 10:30:45.123 data_app_crash (text, 500 bytes)
8
- Process: com.harnessplayground
9
- PID: 7777
10
- Package: com.harnessplayground v1 (1.0)
11
- java.lang.RuntimeException: boom
12
- \tat com.harnessplayground.MainActivity.onCreate(MainActivity.kt:38)
13
- `;
14
- const nativeCrashDropbox = `
15
- ========================================
16
- 2026-03-12 10:31:10.456 data_app_native_crash (text, 800 bytes)
17
- Process: com.harnessplayground
18
- PID: 8888
19
- signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xdeadbeef
20
- Abort message: 'JNI DETECTED ERROR IN APPLICATION'
21
- backtrace:
22
- #00 pc 00001234 /data/app/lib/libapp.so
23
- `;
24
- const deviceJavaCrashDropbox = `
25
- Drop box contents: 8 entries
26
- Searching for: data_app_crash
27
-
28
- ========================================
29
- 2026-05-29 10:22:34 data_app_crash (text, 1328 bytes)
30
- SystemUptimeMs: 79467172
31
- Process: com.harnessplayground
32
- PID: 586
33
- Package: com.harnessplayground v1 (1.0)
34
- java.lang.RuntimeException: Intentional asynchronous Kotlin crash
35
- \tat com.harnessplayground.PlaygroundCrashModule.crashFromKotlinAsync(PlaygroundCrashModule.kt:44)
36
- `;
37
- describe('collectDropboxArtifacts', () => {
38
- it('matches harness playground crashes from merged per-tag dropbox output', async () => {
39
- const artifacts = await collectDropboxArtifacts({
40
- bundleId: 'com.harnessplayground',
41
- getDropboxOutput: async () => deviceJavaCrashDropbox,
42
- occurredAt: Date.now(),
43
- pid: 586,
44
- });
45
- expect(artifacts).toHaveLength(1);
46
- expect(artifacts[0]).toMatchObject({
47
- artifactType: 'dropbox-crash',
48
- pid: 586,
49
- processName: 'com.harnessplayground',
50
- });
51
- });
52
- it('ignores Dropbox entries older than the session start time', async () => {
53
- const artifacts = await collectDropboxArtifacts({
54
- bundleId: 'com.harnessplayground',
55
- getDropboxOutput: async () => deviceJavaCrashDropbox,
56
- minOccurredAt: Date.parse('2026-05-29T10:22:35.000Z'),
57
- occurredAt: Date.parse('2026-05-29T10:22:36.000Z'),
58
- });
59
- expect(artifacts).toHaveLength(0);
60
- });
61
- });
62
- describe('parseDropboxOutput', () => {
63
- it('parses java and native dropbox entries', () => {
64
- const entries = parseDropboxOutput(`${javaCrashDropbox}\n${nativeCrashDropbox}`);
65
- expect(entries).toHaveLength(2);
66
- expect(entries[0]).toMatchObject({
67
- tag: 'data_app_crash',
68
- pid: 7777,
69
- });
70
- expect(entries[1]).toMatchObject({
71
- tag: 'data_app_native_crash',
72
- pid: 8888,
73
- });
74
- expect(entries[1]?.content).toContain('SIGSEGV');
75
- });
76
- });
77
- describe('getBestDropboxArtifact', () => {
78
- it('prefers the highest-scored artifact', () => {
79
- const entries = parseDropboxOutput(`${javaCrashDropbox}\n${nativeCrashDropbox}`);
80
- const artifacts = entries.map((entry, index) => ({
81
- artifactType: entry.tag === 'data_app_native_crash'
82
- ? 'dropbox-native-crash'
83
- : 'dropbox-crash',
84
- dropboxTag: entry.tag,
85
- occurredAt: Date.now(),
86
- score: index === 0 ? 100 : 300,
87
- summary: entry.content,
88
- pid: entry.pid,
89
- processName: 'com.harnessplayground',
90
- }));
91
- expect(getBestDropboxArtifact(artifacts)?.dropboxTag).toBe('data_app_native_crash');
92
- });
93
- });
94
- describe('filterExitInfo', () => {
95
- it('returns matching exit-info records for the target package and pid', () => {
96
- const output = `
97
- ApplicationExitInfo #0:
98
- package=com.harnessplayground pid=7777 realUid=10123
99
- reason=4 (APP CRASH(NATIVE))
100
- timestamp=2026-03-12 10:31:10.456
101
- ApplicationExitInfo #1:
102
- package=com.other.app pid=9999 realUid=10199
103
- reason=10 (USER REQUESTED)
104
- `;
105
- const filtered = filterExitInfo({
106
- output,
107
- bundleId: 'com.harnessplayground',
108
- pid: 7777,
109
- });
110
- expect(filtered).toContain('com.harnessplayground pid=7777');
111
- expect(filtered).not.toContain('com.other.app');
112
- });
113
- it('returns null when no exit-info records exist', () => {
114
- expect(filterExitInfo({
115
- output: 'No exit info records for com.harnessplayground',
116
- bundleId: 'com.harnessplayground',
117
- })).toBeNull();
118
- });
119
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=crash-parser.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crash-parser.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/crash-parser.test.ts"],"names":[],"mappings":""}
@@ -1,45 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { androidCrashParser } from '../crash-parser.js';
3
- describe('androidCrashParser.parse', () => {
4
- it('parses an AndroidRuntime crash block into a crash details object', () => {
5
- expect(androidCrashParser.parse({
6
- contents: [
7
- '--------- beginning of crash',
8
- '03-12 11:35:09.000 1234 1234 E AndroidRuntime: Process: com.harnessplayground, PID: 1234',
9
- '03-12 11:35:09.001 1234 1234 E AndroidRuntime: java.lang.RuntimeException: boom',
10
- '03-12 11:35:09.002 1234 1234 E AndroidRuntime: at com.harnessplayground.MainActivity.onCreate(MainActivity.kt:42)',
11
- ].join('\n'),
12
- bundleId: 'com.harnessplayground',
13
- })).toEqual({
14
- source: 'logs',
15
- summary: [
16
- '--------- beginning of crash',
17
- '03-12 11:35:09.000 1234 1234 E AndroidRuntime: Process: com.harnessplayground, PID: 1234',
18
- '03-12 11:35:09.001 1234 1234 E AndroidRuntime: java.lang.RuntimeException: boom',
19
- '03-12 11:35:09.002 1234 1234 E AndroidRuntime: at com.harnessplayground.MainActivity.onCreate(MainActivity.kt:42)',
20
- ].join('\n'),
21
- signal: undefined,
22
- exceptionType: 'java.lang.RuntimeException: boom',
23
- processName: 'com.harnessplayground',
24
- pid: 1234,
25
- rawLines: [
26
- '--------- beginning of crash',
27
- '03-12 11:35:09.000 1234 1234 E AndroidRuntime: Process: com.harnessplayground, PID: 1234',
28
- '03-12 11:35:09.001 1234 1234 E AndroidRuntime: java.lang.RuntimeException: boom',
29
- '03-12 11:35:09.002 1234 1234 E AndroidRuntime: at com.harnessplayground.MainActivity.onCreate(MainActivity.kt:42)',
30
- ],
31
- stackTrace: [
32
- '03-12 11:35:09.002 1234 1234 E AndroidRuntime: at com.harnessplayground.MainActivity.onCreate(MainActivity.kt:42)',
33
- ],
34
- });
35
- });
36
- it('extracts fatal signals from a native crash block', () => {
37
- expect(androidCrashParser.parse({
38
- contents: '03-12 11:35:08.000 1234 1234 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) in tid 1234 (com.harnessplayground), pid 1234 (com.harnessplayground)',
39
- bundleId: 'com.harnessplayground',
40
- })).toMatchObject({
41
- signal: 'SIGSEGV',
42
- processName: 'com.harnessplayground',
43
- });
44
- });
45
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=crash-reporter.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crash-reporter.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/crash-reporter.test.ts"],"names":[],"mappings":""}
@@ -1,150 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import { createAndroidCrashReporter } from '../crash-reporter.js';
3
- const javaCrashDropbox = `
4
- ========================================
5
- 2026-03-12 10:30:45.123 data_app_crash (text, 500 bytes)
6
- Process: com.harnessplayground
7
- PID: 7777
8
- Package: com.harnessplayground v1 (1.0)
9
- java.lang.RuntimeException: boom
10
- \tat com.harnessplayground.MainActivity.onCreate(MainActivity.kt:38)
11
- `;
12
- const nativeCrashDropbox = `
13
- ========================================
14
- 2026-03-12 10:31:10.456 data_app_native_crash (text, 800 bytes)
15
- Process: com.harnessplayground
16
- PID: 8888
17
- signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xdeadbeef
18
- Abort message: 'JNI DETECTED ERROR IN APPLICATION'
19
- backtrace:
20
- #00 pc 00001234 /data/app/lib/libapp.so
21
- `;
22
- describe('createAndroidCrashReporter', () => {
23
- afterEach(() => {
24
- vi.useRealTimers();
25
- });
26
- it('persists the current logcat crash block with the test file path', async () => {
27
- vi.useFakeTimers();
28
- const persistArtifact = vi.fn(() => '/tmp/.harness/crash-reports/logcat.txt');
29
- const reporter = createAndroidCrashReporter({
30
- bundleId: 'com.harnessplayground',
31
- crashArtifactWriter: {
32
- runTimestamp: '2026-03-12T11-35-08-000Z',
33
- persistArtifact,
34
- },
35
- getLogs: () => [
36
- { line: 'ordinary crash-buffer line', occurredAt: 1_000 },
37
- { line: '--------- beginning of crash', occurredAt: 1_100 },
38
- {
39
- line: 'Process: com.harnessplayground, PID: 7777',
40
- occurredAt: 1_100,
41
- },
42
- { line: 'FATAL EXCEPTION: main', occurredAt: 1_100 },
43
- ],
44
- });
45
- const detailsPromise = reporter.getCrashDetails({
46
- occurredAt: 1_100,
47
- pid: 7777,
48
- testFilePath: '/test/native-crash.test.ts',
49
- });
50
- await vi.advanceTimersByTimeAsync(100);
51
- const details = await detailsPromise;
52
- expect(details).toMatchObject({
53
- artifactType: 'logcat',
54
- artifactPath: '/tmp/.harness/crash-reports/logcat.txt',
55
- pid: 7777,
56
- processName: 'com.harnessplayground',
57
- });
58
- expect(persistArtifact).toHaveBeenCalledWith({
59
- artifactKind: 'logcat',
60
- testFilePath: '/test/native-crash.test.ts',
61
- source: {
62
- kind: 'text',
63
- fileName: 'logcat.txt',
64
- text: [
65
- '--------- beginning of crash',
66
- 'Process: com.harnessplayground, PID: 7777',
67
- 'FATAL EXCEPTION: main',
68
- '',
69
- ].join('\n'),
70
- },
71
- });
72
- });
73
- it('adds dropbox artifacts as enrichment when logcat evidence is available', async () => {
74
- vi.useFakeTimers();
75
- const persistArtifact = vi
76
- .fn()
77
- .mockImplementation(({ artifactKind }) => {
78
- return `/tmp/.harness/crash-reports/${artifactKind}.txt`;
79
- });
80
- const reporter = createAndroidCrashReporter({
81
- bundleId: 'com.harnessplayground',
82
- crashArtifactWriter: {
83
- runTimestamp: '2026-03-12T11-35-08-000Z',
84
- persistArtifact,
85
- },
86
- getLogs: () => [
87
- { line: '--------- beginning of crash', occurredAt: 1_100 },
88
- {
89
- line: 'Process: com.harnessplayground, PID: 7777',
90
- occurredAt: 1_100,
91
- },
92
- { line: 'FATAL EXCEPTION: main', occurredAt: 1_100 },
93
- ],
94
- getDropboxOutput: async () => javaCrashDropbox,
95
- getExitInfo: async () => 'ApplicationExitInfo #0:\n package=com.harnessplayground pid=7777 reason=4 (APP CRASH(NATIVE))',
96
- });
97
- const detailsPromise = reporter.getCrashDetails({
98
- occurredAt: 1_100,
99
- pid: 7777,
100
- testFilePath: '/test/native-crash.test.ts',
101
- });
102
- await vi.advanceTimersByTimeAsync(100);
103
- const details = await detailsPromise;
104
- expect(details).toMatchObject({
105
- artifactType: 'logcat',
106
- artifactPath: '/tmp/.harness/crash-reports/logcat.txt',
107
- });
108
- expect(details?.enrichmentArtifacts).toEqual(expect.arrayContaining([
109
- {
110
- artifactType: 'dropbox-crash',
111
- artifactPath: '/tmp/.harness/crash-reports/dropbox-crash.txt',
112
- },
113
- {
114
- artifactType: 'exit-info',
115
- artifactPath: '/tmp/.harness/crash-reports/exit-info.txt',
116
- },
117
- ]));
118
- });
119
- it('falls back to native dropbox evidence when logcat is empty', async () => {
120
- vi.useFakeTimers();
121
- const persistArtifact = vi
122
- .fn()
123
- .mockImplementation(({ artifactKind }) => {
124
- return `/tmp/.harness/crash-reports/${artifactKind}.txt`;
125
- });
126
- const reporter = createAndroidCrashReporter({
127
- bundleId: 'com.harnessplayground',
128
- crashArtifactWriter: {
129
- runTimestamp: '2026-03-12T11-35-08-000Z',
130
- persistArtifact,
131
- },
132
- getLogs: () => [],
133
- getDropboxOutput: async () => nativeCrashDropbox,
134
- });
135
- const detailsPromise = reporter.getCrashDetails({
136
- occurredAt: 1_100,
137
- pid: 8888,
138
- testFilePath: '/test/native-crash.test.ts',
139
- });
140
- await vi.advanceTimersByTimeAsync(100);
141
- const details = await detailsPromise;
142
- expect(details).toMatchObject({
143
- artifactType: 'dropbox-native-crash',
144
- artifactPath: '/tmp/.harness/crash-reports/dropbox-native-crash.txt',
145
- pid: 8888,
146
- signal: 'SIGSEGV',
147
- processName: 'com.harnessplayground',
148
- });
149
- });
150
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=emulator-startup.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"emulator-startup.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/emulator-startup.test.ts"],"names":[],"mappings":""}
@@ -1,47 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getEmulatorCpuCores, getEmulatorStartupArgs, isAccelerationUsable, } from '../emulator-startup.js';
3
- import { getDeviceCoreBudget } from '@react-native-harness/tools';
4
- import os from 'node:os';
5
- describe('getEmulatorCpuCores', () => {
6
- it('uses the shared device-core budget for the current host', () => {
7
- expect(getEmulatorCpuCores()).toBe(getDeviceCoreBudget(os.availableParallelism()));
8
- });
9
- });
10
- describe('emulator startup modes', () => {
11
- it('builds default boot args', () => {
12
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'default-boot')).toEqual(expect.arrayContaining([
13
- '@Pixel_8_API_35',
14
- '-no-snapshot-load',
15
- '-no-snapshot-save',
16
- '-no-metrics',
17
- ]));
18
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'default-boot')).not.toEqual(expect.arrayContaining(['-camera-back', 'none']));
19
- });
20
- it('builds clean snapshot generation args', () => {
21
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'clean-snapshot-generation')).toEqual(expect.arrayContaining([
22
- '@Pixel_8_API_35',
23
- '-no-snapshot-load',
24
- '-no-metrics',
25
- ]));
26
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'clean-snapshot-generation')).not.toContain('-no-snapshot-save');
27
- });
28
- it('builds snapshot reuse args', () => {
29
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'snapshot-reuse')).toEqual(expect.arrayContaining([
30
- '@Pixel_8_API_35',
31
- '-no-snapshot-save',
32
- '-no-metrics',
33
- ]));
34
- expect(getEmulatorStartupArgs('Pixel_8_API_35', 'snapshot-reuse')).not.toContain('-no-snapshot-load');
35
- });
36
- });
37
- describe('isAccelerationUsable', () => {
38
- it('returns true when the emulator reports acceleration is usable', () => {
39
- expect(isAccelerationUsable('accel:\n0\nKVM (version 12) is installed and usable.\naccel\n')).toBe(true);
40
- });
41
- it('returns false when acceleration is disabled', () => {
42
- expect(isAccelerationUsable('accel:\n0\nKVM is not installed on this machine.\naccel\n')).toBe(false);
43
- });
44
- it('returns false for empty output', () => {
45
- expect(isAccelerationUsable('')).toBe(false);
46
- });
47
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=environment.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/environment.test.ts"],"names":[],"mappings":""}
@@ -1,117 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { ensureAndroidAdbAvailable, ensureAndroidEmulatorAvailable, getAndroidSdkRoot, getAndroidSystemImagePackage, getDefaultUnixAndroidSdkRoot, getHostAndroidSystemImageArch, getRequiredAndroidSdkPackages, } from '../environment.js';
6
- import * as tools from '@react-native-harness/tools';
7
- describe('Android environment', () => {
8
- beforeEach(() => {
9
- vi.restoreAllMocks();
10
- vi.unstubAllEnvs();
11
- });
12
- it('skips bootstrapping command-line tools when adb is already installed', async () => {
13
- const sdkRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'android-sdk-'));
14
- const adbPath = path.join(sdkRoot, 'platform-tools', 'adb');
15
- fs.mkdirSync(path.dirname(adbPath), { recursive: true });
16
- fs.writeFileSync(adbPath, '');
17
- const spawnSpy = vi.spyOn(tools, 'spawn');
18
- await expect(ensureAndroidAdbAvailable({
19
- env: { ANDROID_HOME: sdkRoot },
20
- })).resolves.toBe(sdkRoot);
21
- expect(spawnSpy).not.toHaveBeenCalled();
22
- fs.rmSync(sdkRoot, { force: true, recursive: true });
23
- });
24
- it('installs only platform-tools when adb is missing', async () => {
25
- const sdkRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'android-sdk-'));
26
- const sdkManagerDirectory = path.join(sdkRoot, 'cmdline-tools', 'latest', 'bin');
27
- fs.mkdirSync(sdkManagerDirectory, { recursive: true });
28
- fs.writeFileSync(path.join(sdkManagerDirectory, 'sdkmanager'), '');
29
- fs.writeFileSync(path.join(sdkManagerDirectory, 'avdmanager'), '');
30
- const spawnSpy = vi.spyOn(tools, 'spawn').mockImplementation((async (command, args) => {
31
- if (command === 'bash' && typeof args?.[1] === 'string') {
32
- const commandString = args[1];
33
- if (commandString.includes('platform-tools')) {
34
- const adbPath = path.join(sdkRoot, 'platform-tools', 'adb');
35
- fs.mkdirSync(path.dirname(adbPath), { recursive: true });
36
- fs.writeFileSync(adbPath, '');
37
- }
38
- }
39
- return {};
40
- }));
41
- await expect(ensureAndroidAdbAvailable({
42
- env: { ANDROID_HOME: sdkRoot },
43
- })).resolves.toBe(sdkRoot);
44
- expect(spawnSpy).toHaveBeenCalledWith('bash', ['-lc', expect.stringContaining('platform-tools')], expect.any(Object));
45
- expect(spawnSpy.mock.calls.some(([command, args]) => command === 'bash' &&
46
- typeof args?.[1] === 'string' &&
47
- args[1].includes('platform-tools') &&
48
- args[1].includes('emulator'))).toBe(false);
49
- fs.rmSync(sdkRoot, { force: true, recursive: true });
50
- });
51
- it('installs emulator only when emulator is missing', async () => {
52
- const sdkRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'android-sdk-'));
53
- const sdkManagerDirectory = path.join(sdkRoot, 'cmdline-tools', 'latest', 'bin');
54
- fs.mkdirSync(sdkManagerDirectory, { recursive: true });
55
- fs.writeFileSync(path.join(sdkManagerDirectory, 'sdkmanager'), '');
56
- fs.writeFileSync(path.join(sdkManagerDirectory, 'avdmanager'), '');
57
- const spawnSpy = vi.spyOn(tools, 'spawn').mockImplementation((async (command, args) => {
58
- if (command === 'bash' && typeof args?.[1] === 'string') {
59
- const commandString = args[1];
60
- if (commandString.includes('emulator')) {
61
- const emulatorPath = path.join(sdkRoot, 'emulator', 'emulator');
62
- fs.mkdirSync(path.dirname(emulatorPath), { recursive: true });
63
- fs.writeFileSync(emulatorPath, '');
64
- }
65
- }
66
- return {};
67
- }));
68
- await expect(ensureAndroidEmulatorAvailable({
69
- env: { ANDROID_HOME: sdkRoot },
70
- })).resolves.toBe(sdkRoot);
71
- expect(spawnSpy).toHaveBeenCalledWith('bash', ['-lc', expect.stringContaining('emulator')], expect.any(Object));
72
- fs.rmSync(sdkRoot, { force: true, recursive: true });
73
- });
74
- it('uses the default Unix SDK root when env vars are missing', () => {
75
- expect(getDefaultUnixAndroidSdkRoot({
76
- platform: 'darwin',
77
- homeDirectory: '/Users/tester',
78
- })).toBe('/Users/tester/Library/Android/sdk');
79
- expect(getAndroidSdkRoot({}, {
80
- platform: 'linux',
81
- homeDirectory: '/home/tester',
82
- })).toBe('/home/tester/Android/Sdk');
83
- });
84
- it('prefers ANDROID_HOME and ANDROID_SDK_ROOT over default paths', () => {
85
- expect(getAndroidSdkRoot({
86
- ANDROID_HOME: '/env/android-home',
87
- ANDROID_SDK_ROOT: '/env/android-sdk-root',
88
- }, {
89
- platform: 'darwin',
90
- homeDirectory: '/Users/tester',
91
- })).toBe('/env/android-home');
92
- expect(getAndroidSdkRoot({
93
- ANDROID_SDK_ROOT: '/env/android-sdk-root',
94
- }, {
95
- platform: 'linux',
96
- homeDirectory: '/home/tester',
97
- })).toBe('/env/android-sdk-root');
98
- });
99
- it('selects Android packages using the host architecture', () => {
100
- expect(getHostAndroidSystemImageArch('x64')).toBe('x86_64');
101
- expect(getHostAndroidSystemImageArch('arm64')).toBe('arm64-v8a');
102
- expect(getAndroidSystemImagePackage(35, 'x86_64')).toBe('system-images;android-35;default;x86_64');
103
- expect(getAndroidSystemImagePackage(35, 'arm64-v8a')).toBe('system-images;android-35;default;arm64-v8a');
104
- });
105
- it('derives emulator package requirements from runner config fields', () => {
106
- expect(getRequiredAndroidSdkPackages({
107
- apiLevel: 34,
108
- includeEmulator: true,
109
- architecture: 'x86_64',
110
- })).toEqual([
111
- 'platform-tools',
112
- 'emulator',
113
- 'platforms;android-34',
114
- 'system-images;android-34;default;x86_64',
115
- ]);
116
- });
117
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=instance.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"instance.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/instance.test.ts"],"names":[],"mappings":""}