@react-native-harness/platform-android 1.1.0-rc.3 → 1.1.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 (41) hide show
  1. package/dist/__tests__/adb.test.js +77 -5
  2. package/dist/__tests__/environment.test.js +67 -1
  3. package/dist/__tests__/instance.test.js +1 -1
  4. package/dist/__tests__/targets.test.d.ts +2 -0
  5. package/dist/__tests__/targets.test.d.ts.map +1 -0
  6. package/dist/__tests__/targets.test.js +49 -0
  7. package/dist/adb.d.ts.map +1 -1
  8. package/dist/adb.js +47 -13
  9. package/dist/config.d.ts +16 -16
  10. package/dist/environment.d.ts +3 -0
  11. package/dist/environment.d.ts.map +1 -1
  12. package/dist/environment.js +33 -11
  13. package/dist/instance.d.ts.map +1 -1
  14. package/dist/instance.js +2 -4
  15. package/dist/runner.d.ts.map +1 -1
  16. package/dist/runner.js +2 -5
  17. package/dist/targets.d.ts.map +1 -1
  18. package/dist/targets.js +4 -2
  19. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  20. package/package.json +4 -4
  21. package/src/__tests__/adb.test.ts +133 -28
  22. package/src/__tests__/environment.test.ts +135 -10
  23. package/src/__tests__/instance.test.ts +49 -49
  24. package/src/__tests__/targets.test.ts +53 -0
  25. package/src/adb.ts +106 -48
  26. package/src/environment.ts +99 -55
  27. package/src/instance.ts +17 -17
  28. package/src/runner.ts +5 -10
  29. package/src/targets.ts +9 -2
  30. package/dist/assertions.d.ts +0 -5
  31. package/dist/assertions.d.ts.map +0 -1
  32. package/dist/assertions.js +0 -6
  33. package/dist/emulator.d.ts +0 -6
  34. package/dist/emulator.d.ts.map +0 -1
  35. package/dist/emulator.js +0 -27
  36. package/dist/reader.d.ts +0 -6
  37. package/dist/reader.d.ts.map +0 -1
  38. package/dist/reader.js +0 -57
  39. package/dist/types.d.ts +0 -381
  40. package/dist/types.d.ts.map +0 -1
  41. package/dist/types.js +0 -107
@@ -36,7 +36,7 @@ describe('Android platform instance', () => {
36
36
  const ensureAndroidEmulatorEnvironment = vi
37
37
  .spyOn(
38
38
  await import('../environment.js'),
39
- 'ensureAndroidEmulatorEnvironment'
39
+ 'ensureAndroidEmulatorEnvironment',
40
40
  )
41
41
  .mockResolvedValue('/tmp/android-sdk');
42
42
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue(['emulator-5554']);
@@ -47,10 +47,10 @@ describe('Android platform instance', () => {
47
47
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
48
48
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
49
49
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
50
- undefined
50
+ undefined,
51
51
  );
52
52
  vi.spyOn(sharedPrefs, 'clearHarnessDebugHttpHost').mockResolvedValue(
53
- undefined
53
+ undefined,
54
54
  );
55
55
  vi.spyOn(adb, 'stopApp').mockResolvedValue(undefined);
56
56
  const stopEmulator = vi.spyOn(adb, 'stopEmulator').mockResolvedValue();
@@ -72,19 +72,19 @@ describe('Android platform instance', () => {
72
72
  activityName: '.MainActivity',
73
73
  },
74
74
  harnessConfig,
75
- init
75
+ init,
76
76
  );
77
77
 
78
78
  await instance.dispose();
79
79
 
80
- expect(ensureAndroidEmulatorEnvironment).toHaveBeenCalledWith(35);
80
+ expect(ensureAndroidEmulatorEnvironment).not.toHaveBeenCalled();
81
81
  expect(stopEmulator).not.toHaveBeenCalled();
82
82
  });
83
83
 
84
84
  it('creates and boots an emulator when missing and shuts it down on dispose', async () => {
85
85
  vi.spyOn(
86
86
  await import('../environment.js'),
87
- 'ensureAndroidEmulatorEnvironment'
87
+ 'ensureAndroidEmulatorEnvironment',
88
88
  ).mockResolvedValue('/tmp/android-sdk');
89
89
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue([]);
90
90
  vi.spyOn(adb, 'hasAvd').mockResolvedValue(false);
@@ -98,10 +98,10 @@ describe('Android platform instance', () => {
98
98
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
99
99
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
100
100
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
101
- undefined
101
+ undefined,
102
102
  );
103
103
  vi.spyOn(sharedPrefs, 'clearHarnessDebugHttpHost').mockResolvedValue(
104
- undefined
104
+ undefined,
105
105
  );
106
106
  vi.spyOn(adb, 'stopApp').mockResolvedValue(undefined);
107
107
  const stopEmulator = vi.spyOn(adb, 'stopEmulator').mockResolvedValue();
@@ -123,7 +123,7 @@ describe('Android platform instance', () => {
123
123
  activityName: '.MainActivity',
124
124
  },
125
125
  harnessConfig,
126
- init
126
+ init,
127
127
  );
128
128
 
129
129
  expect(createAvd).toHaveBeenCalledWith({
@@ -144,7 +144,7 @@ describe('Android platform instance', () => {
144
144
  const ensureAndroidEmulatorEnvironment = vi
145
145
  .spyOn(
146
146
  await import('../environment.js'),
147
- 'ensureAndroidEmulatorEnvironment'
147
+ 'ensureAndroidEmulatorEnvironment',
148
148
  )
149
149
  .mockResolvedValue('/tmp/android-sdk');
150
150
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue([]);
@@ -159,7 +159,7 @@ describe('Android platform instance', () => {
159
159
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
160
160
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
161
161
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
162
- undefined
162
+ undefined,
163
163
  );
164
164
 
165
165
  await expect(
@@ -180,8 +180,8 @@ describe('Android platform instance', () => {
180
180
  activityName: '.MainActivity',
181
181
  },
182
182
  harnessConfig,
183
- init
184
- )
183
+ init,
184
+ ),
185
185
  ).resolves.toBeDefined();
186
186
 
187
187
  expect(ensureAndroidEmulatorEnvironment).toHaveBeenCalledWith(35);
@@ -193,7 +193,7 @@ describe('Android platform instance', () => {
193
193
  vi.stubEnv('HARNESS_AVD_CACHING', 'true');
194
194
  vi.spyOn(
195
195
  await import('../environment.js'),
196
- 'ensureAndroidEmulatorEnvironment'
196
+ 'ensureAndroidEmulatorEnvironment',
197
197
  ).mockResolvedValue('/tmp/android-sdk');
198
198
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue([]);
199
199
  vi.spyOn(adb, 'hasAvd').mockResolvedValue(true);
@@ -211,7 +211,7 @@ describe('Android platform instance', () => {
211
211
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
212
212
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
213
213
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
214
- undefined
214
+ undefined,
215
215
  );
216
216
 
217
217
  await expect(
@@ -233,14 +233,14 @@ describe('Android platform instance', () => {
233
233
  activityName: '.MainActivity',
234
234
  },
235
235
  harnessConfig,
236
- init
237
- )
236
+ init,
237
+ ),
238
238
  ).resolves.toBeDefined();
239
239
 
240
240
  expect(adb.startEmulator).toHaveBeenCalledTimes(1);
241
241
  expect(adb.startEmulator).toHaveBeenCalledWith(
242
242
  'Pixel_8_API_35',
243
- 'snapshot-reuse'
243
+ 'snapshot-reuse',
244
244
  );
245
245
  });
246
246
 
@@ -248,7 +248,7 @@ describe('Android platform instance', () => {
248
248
  vi.stubEnv('HARNESS_AVD_CACHING', 'true');
249
249
  vi.spyOn(
250
250
  await import('../environment.js'),
251
- 'ensureAndroidEmulatorEnvironment'
251
+ 'ensureAndroidEmulatorEnvironment',
252
252
  ).mockResolvedValue('/tmp/android-sdk');
253
253
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue([]);
254
254
  vi.spyOn(adb, 'hasAvd').mockResolvedValue(true);
@@ -272,7 +272,7 @@ describe('Android platform instance', () => {
272
272
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
273
273
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
274
274
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
275
- undefined
275
+ undefined,
276
276
  );
277
277
 
278
278
  await expect(
@@ -294,8 +294,8 @@ describe('Android platform instance', () => {
294
294
  activityName: '.MainActivity',
295
295
  },
296
296
  harnessConfig,
297
- init
298
- )
297
+ init,
298
+ ),
299
299
  ).resolves.toBeDefined();
300
300
 
301
301
  expect(deleteAvd).toHaveBeenCalledWith('Pixel_8_API_35');
@@ -303,17 +303,17 @@ describe('Android platform instance', () => {
303
303
  expect(stopEmulator).toHaveBeenCalledWith('emulator-5554');
304
304
  expect(waitForEmulatorDisconnect).toHaveBeenCalledWith(
305
305
  'emulator-5554',
306
- init.signal
306
+ init.signal,
307
307
  );
308
308
  expect(adb.startEmulator).toHaveBeenNthCalledWith(
309
309
  1,
310
310
  'Pixel_8_API_35',
311
- 'clean-snapshot-generation'
311
+ 'clean-snapshot-generation',
312
312
  );
313
313
  expect(adb.startEmulator).toHaveBeenNthCalledWith(
314
314
  2,
315
315
  'Pixel_8_API_35',
316
- 'snapshot-reuse'
316
+ 'snapshot-reuse',
317
317
  );
318
318
  });
319
319
 
@@ -321,7 +321,7 @@ describe('Android platform instance', () => {
321
321
  vi.stubEnv('HARNESS_AVD_CACHING', 'true');
322
322
  vi.spyOn(
323
323
  await import('../environment.js'),
324
- 'ensureAndroidEmulatorEnvironment'
324
+ 'ensureAndroidEmulatorEnvironment',
325
325
  ).mockResolvedValue('/tmp/android-sdk');
326
326
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue([]);
327
327
  vi.spyOn(adb, 'hasAvd').mockResolvedValue(false);
@@ -339,7 +339,7 @@ describe('Android platform instance', () => {
339
339
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
340
340
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
341
341
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
342
- undefined
342
+ undefined,
343
343
  );
344
344
 
345
345
  await expect(
@@ -361,24 +361,24 @@ describe('Android platform instance', () => {
361
361
  activityName: '.MainActivity',
362
362
  },
363
363
  harnessConfig,
364
- init
365
- )
364
+ init,
365
+ ),
366
366
  ).resolves.toBeDefined();
367
367
 
368
368
  expect(startEmulator).toHaveBeenNthCalledWith(
369
369
  1,
370
370
  'Pixel_8_API_35',
371
- 'clean-snapshot-generation'
371
+ 'clean-snapshot-generation',
372
372
  );
373
373
  expect(stopEmulator).toHaveBeenCalledWith('emulator-5554');
374
374
  expect(waitForEmulatorDisconnect).toHaveBeenCalledWith(
375
375
  'emulator-5554',
376
- init.signal
376
+ init.signal,
377
377
  );
378
378
  expect(startEmulator).toHaveBeenNthCalledWith(
379
379
  2,
380
380
  'Pixel_8_API_35',
381
- 'snapshot-reuse'
381
+ 'snapshot-reuse',
382
382
  );
383
383
  });
384
384
 
@@ -388,7 +388,7 @@ describe('Android platform instance', () => {
388
388
  vi.stubEnv('HARNESS_APP_PATH', appPath);
389
389
  vi.spyOn(
390
390
  await import('../environment.js'),
391
- 'ensureAndroidEmulatorEnvironment'
391
+ 'ensureAndroidEmulatorEnvironment',
392
392
  ).mockResolvedValue('/tmp/android-sdk');
393
393
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue(['emulator-5554']);
394
394
  vi.spyOn(adb, 'getEmulatorName').mockResolvedValue('Pixel_8_API_35');
@@ -399,7 +399,7 @@ describe('Android platform instance', () => {
399
399
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
400
400
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
401
401
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
402
- undefined
402
+ undefined,
403
403
  );
404
404
 
405
405
  await expect(
@@ -420,8 +420,8 @@ describe('Android platform instance', () => {
420
420
  activityName: '.MainActivity',
421
421
  },
422
422
  harnessConfig,
423
- init
424
- )
423
+ init,
424
+ ),
425
425
  ).resolves.toBeDefined();
426
426
 
427
427
  expect(installApp).toHaveBeenCalledWith('emulator-5554', appPath);
@@ -453,8 +453,8 @@ describe('Android platform instance', () => {
453
453
  activityName: '.MainActivity',
454
454
  },
455
455
  harnessConfig,
456
- init
457
- )
456
+ init,
457
+ ),
458
458
  ).rejects.toBeInstanceOf(HarnessAppPathError);
459
459
  });
460
460
 
@@ -483,8 +483,8 @@ describe('Android platform instance', () => {
483
483
  activityName: '.MainActivity',
484
484
  },
485
485
  harnessConfig,
486
- init
487
- )
486
+ init,
487
+ ),
488
488
  ).rejects.toBeInstanceOf(HarnessAppPathError);
489
489
  });
490
490
 
@@ -503,15 +503,15 @@ describe('Android platform instance', () => {
503
503
  activityName: '.MainActivity',
504
504
  },
505
505
  harnessConfig,
506
- init
507
- )
506
+ init,
507
+ ),
508
508
  ).rejects.toBeInstanceOf(HarnessEmulatorConfigError);
509
509
  });
510
510
 
511
511
  it('returns a noop emulator app monitor when native crash detection is disabled', async () => {
512
512
  vi.spyOn(
513
513
  await import('../environment.js'),
514
- 'ensureAndroidEmulatorEnvironment'
514
+ 'ensureAndroidEmulatorEnvironment',
515
515
  ).mockResolvedValue('/tmp/android-sdk');
516
516
  vi.spyOn(adb, 'getDeviceIds').mockResolvedValue(['emulator-5554']);
517
517
  vi.spyOn(adb, 'getEmulatorName').mockResolvedValue('Pixel_8_API_35');
@@ -521,7 +521,7 @@ describe('Android platform instance', () => {
521
521
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
522
522
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
523
523
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
524
- undefined
524
+ undefined,
525
525
  );
526
526
 
527
527
  const instance = await getAndroidEmulatorPlatformInstance(
@@ -541,7 +541,7 @@ describe('Android platform instance', () => {
541
541
  activityName: '.MainActivity',
542
542
  },
543
543
  harnessConfigWithoutNativeCrashDetection,
544
- init
544
+ init,
545
545
  );
546
546
 
547
547
  const listener = vi.fn();
@@ -565,7 +565,7 @@ describe('Android platform instance', () => {
565
565
  vi.spyOn(adb, 'setHideErrorDialogs').mockResolvedValue(undefined);
566
566
  vi.spyOn(adb, 'getAppUid').mockResolvedValue(10234);
567
567
  vi.spyOn(sharedPrefs, 'applyHarnessDebugHttpHost').mockResolvedValue(
568
- undefined
568
+ undefined,
569
569
  );
570
570
 
571
571
  await expect(
@@ -580,8 +580,8 @@ describe('Android platform instance', () => {
580
580
  bundleId: 'com.harnessplayground',
581
581
  activityName: '.MainActivity',
582
582
  },
583
- harnessConfigWithoutNativeCrashDetection
584
- )
583
+ harnessConfigWithoutNativeCrashDetection,
584
+ ),
585
585
  ).resolves.toBeDefined();
586
586
 
587
587
  const instance = await getAndroidPhysicalDevicePlatformInstance(
@@ -595,7 +595,7 @@ describe('Android platform instance', () => {
595
595
  bundleId: 'com.harnessplayground',
596
596
  activityName: '.MainActivity',
597
597
  },
598
- harnessConfigWithoutNativeCrashDetection
598
+ harnessConfigWithoutNativeCrashDetection,
599
599
  );
600
600
 
601
601
  const listener = vi.fn();
@@ -0,0 +1,53 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { getRunTargets } from '../targets.js';
3
+ import * as adb from '../adb.js';
4
+ import * as environment from '../environment.js';
5
+
6
+ describe('Android target discovery', () => {
7
+ beforeEach(() => {
8
+ vi.restoreAllMocks();
9
+ vi.unstubAllEnvs();
10
+ });
11
+
12
+ it('installs adb and emulator only for discovery', async () => {
13
+ const ensureAndroidAdbAvailable = vi
14
+ .spyOn(environment, 'ensureAndroidAdbAvailable')
15
+ .mockResolvedValue('/tmp/android-sdk');
16
+ const ensureAndroidEmulatorAvailable = vi
17
+ .spyOn(environment, 'ensureAndroidEmulatorAvailable')
18
+ .mockResolvedValue('/tmp/android-sdk');
19
+ vi.spyOn(adb, 'getAvds').mockResolvedValue(['Pixel_8_API_35']);
20
+ vi.spyOn(adb, 'getConnectedDevices').mockResolvedValue([
21
+ {
22
+ id: 'device-1',
23
+ manufacturer: 'Google',
24
+ model: 'Pixel 8',
25
+ },
26
+ ]);
27
+
28
+ await expect(getRunTargets()).resolves.toEqual([
29
+ {
30
+ type: 'emulator',
31
+ name: 'Pixel_8_API_35',
32
+ platform: 'android',
33
+ description: 'Android emulator',
34
+ device: {
35
+ name: 'Pixel_8_API_35',
36
+ },
37
+ },
38
+ {
39
+ type: 'physical',
40
+ name: 'Google Pixel 8',
41
+ platform: 'android',
42
+ description: 'Physical device (device-1)',
43
+ device: {
44
+ manufacturer: 'Google',
45
+ model: 'Pixel 8',
46
+ },
47
+ },
48
+ ]);
49
+
50
+ expect(ensureAndroidAdbAvailable).toHaveBeenCalledTimes(1);
51
+ expect(ensureAndroidEmulatorAvailable).toHaveBeenCalledTimes(1);
52
+ });
53
+ });