Skip to content

Commit 3ec7e00

Browse files
authored
refactor: unify spawn verbose output (#259)
* refactor: unify spawn verbose output * changeset * fix tests; improve error handling
1 parent 9c37e12 commit 3ec7e00

36 files changed

+175
-183
lines changed

.changeset/cuddly-olives-travel.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@rnef/platform-apple-helpers': patch
3+
'@rnef/plugin-brownfield-ios': patch
4+
'@rnef/platform-android': patch
5+
'@rnef/tools': patch
6+
---
7+
8+
refactor: unify spawn verbose output

packages/platform-android/src/lib/commands/buildAndroid/__tests__/buildAndroid.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ test('buildAndroid runs gradle build with correct configuration for debug and ou
6767
await buildAndroid(androidProject, { ...args, aab: true });
6868

6969
expect(spawn).toBeCalledWith('./gradlew', ['app:bundleDebug', '-x', 'lint'], {
70-
stdio: !tools.isInteractive() ? 'inherit' : 'pipe',
7170
cwd: '/android',
7271
});
7372
expect(spinnerMock.stop).toBeCalledWith(
@@ -89,9 +88,6 @@ test('buildAndroid fails gracefully when gradle errors', async () => {
8988
expect(spawn).toBeCalledWith(
9089
'./gradlew',
9190
['app:assembleDebug', '-x', 'lint'],
92-
{
93-
stdio: !tools.isInteractive() ? 'inherit' : 'pipe',
94-
cwd: '/android',
95-
}
91+
{ cwd: '/android' }
9692
);
9793
});

packages/platform-android/src/lib/commands/generateKeystore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function runKeytool(androidProject: AndroidProjectConfig, args: Flags) {
9696
`Failed to generate keystore. Please try manually by following instructions at: ${color.cyan(
9797
'https://reactnative.dev/docs/signed-apk-android'
9898
)}`,
99-
{ cause: (error as SubprocessError).cause }
99+
{ cause: (error as SubprocessError).stderr }
100100
);
101101
}
102102
}

packages/platform-android/src/lib/commands/runAndroid/__tests__/runAndroid.test.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ test.each([['release'], ['debug'], ['staging']])(
307307
{ ...androidProject },
308308
{ ...args, variant },
309309
'/',
310-
undefined
310+
undefined,
311+
{ extraSources: [], ignorePaths: [] }
311312
);
312313

313314
expect(tools.outro).toBeCalledWith('Success 🎉.');
@@ -327,7 +328,7 @@ test.each([['release'], ['debug'], ['staging']])(
327328
'-PreactNativeDevServerPort=8081',
328329
'-PreactNativeArchitectures=arm64-v8a,armeabi-v7a',
329330
],
330-
{ stdio: !tools.isInteractive() ? 'inherit' : 'pipe', cwd: '/android' }
331+
{ cwd: '/android' }
331332
);
332333

333334
// launches com.test app with MainActivity on emulator-5552
@@ -336,8 +337,7 @@ test.each([['release'], ['debug'], ['staging']])(
336337
expect.arrayContaining([
337338
'emulator-5554',
338339
'com.test/com.test.MainActivity',
339-
]),
340-
{ stdio: ['ignore', 'ignore', 'pipe'] }
340+
])
341341
);
342342
}
343343
);
@@ -356,7 +356,8 @@ test('runAndroid runs gradle build with custom --appId, --appIdSuffix and --main
356356
mainActivity: 'OtherActivity',
357357
},
358358
'/',
359-
undefined
359+
undefined,
360+
{ extraSources: [], ignorePaths: [] }
360361
);
361362

362363
expect(tools.outro).toBeCalledWith('Success 🎉.');
@@ -368,8 +369,7 @@ test('runAndroid runs gradle build with custom --appId, --appIdSuffix and --main
368369
expect.arrayContaining([
369370
'emulator-5552',
370371
'com.custom.suffix/com.test.OtherActivity',
371-
]),
372-
{ stdio: ['ignore', 'ignore', 'pipe'] }
372+
])
373373
);
374374
});
375375

@@ -383,7 +383,8 @@ test('runAndroid fails to launch an app on not-connected device when specified w
383383
{ ...androidProject },
384384
{ ...args, device: 'emulator-5554' },
385385
'/',
386-
undefined
386+
undefined,
387+
{ extraSources: [], ignorePaths: [] }
387388
);
388389
expect(logWarnSpy).toBeCalledWith(
389390
'No devices or emulators found matching "emulator-5554". Using available one instead.'
@@ -451,7 +452,8 @@ test.each([['release'], ['debug']])(
451452
{ ...androidProject },
452453
{ ...args, device: 'emulator-5554', variant },
453454
'/',
454-
undefined
455+
undefined,
456+
{ extraSources: [], ignorePaths: [] }
455457
);
456458

457459
// we don't want to run installDebug when a device is selected, because gradle will install the app on all connected devices
@@ -472,7 +474,7 @@ test.each([['release'], ['debug']])(
472474
'-PreactNativeDevServerPort=8081',
473475
'-PreactNativeArchitectures=arm64-v8a,armeabi-v7a',
474476
],
475-
{ stdio: !tools.isInteractive() ? 'inherit' : 'pipe', cwd: '/android' }
477+
{ cwd: '/android' }
476478
);
477479

478480
// launches com.test app with MainActivity on emulator-5554
@@ -481,8 +483,7 @@ test.each([['release'], ['debug']])(
481483
expect.arrayContaining([
482484
'emulator-5554',
483485
'com.test/com.test.MainActivity',
484-
]),
485-
{ stdio: ['ignore', 'ignore', 'pipe'] }
486+
])
486487
);
487488
}
488489
);
@@ -509,7 +510,10 @@ test('runAndroid launches an app on all connected devices', async () => {
509510
});
510511
});
511512

512-
await runAndroid({ ...androidProject }, { ...args }, '/', undefined);
513+
await runAndroid({ ...androidProject }, { ...args }, '/', undefined, {
514+
extraSources: [],
515+
ignorePaths: [],
516+
});
513517

514518
// Runs assemble debug task with active architectures arm64-v8a, armeabi-v7a
515519
expect(spawn).toBeCalledWith(
@@ -521,21 +525,19 @@ test('runAndroid launches an app on all connected devices', async () => {
521525
'-PreactNativeDevServerPort=8081',
522526
'-PreactNativeArchitectures=arm64-v8a,armeabi-v7a',
523527
],
524-
{ stdio: !tools.isInteractive() ? 'inherit' : 'pipe', cwd: '/android' }
528+
{ cwd: '/android' }
525529
);
526530

527531
// launches com.test app with MainActivity on emulator-5552
528532
expect(spawn).toBeCalledWith(
529533
'/mock/android/home/platform-tools/adb',
530-
expect.arrayContaining(['emulator-5552', 'com.test/com.test.MainActivity']),
531-
{ stdio: ['ignore', 'ignore', 'pipe'] }
534+
expect.arrayContaining(['emulator-5552', 'com.test/com.test.MainActivity'])
532535
);
533536

534537
// launches com.test app with MainActivity on emulator-5554
535538
expect(spawn).toBeCalledWith(
536539
'/mock/android/home/platform-tools/adb',
537-
expect.arrayContaining(['emulator-5554', 'com.test/com.test.MainActivity']),
538-
{ stdio: ['ignore', 'ignore', 'pipe'] }
540+
expect.arrayContaining(['emulator-5554', 'com.test/com.test.MainActivity'])
539541
);
540542
});
541543

@@ -576,7 +578,8 @@ test('runAndroid skips building when --binary-path is passed', async () => {
576578
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
577579
},
578580
'/root',
579-
undefined
581+
undefined,
582+
{ extraSources: [], ignorePaths: [] }
580583
);
581584

582585
// Skips gradle
@@ -585,14 +588,12 @@ test('runAndroid skips building when --binary-path is passed', async () => {
585588
// launches com.test app with MainActivity on emulator-5554
586589
expect(spawn).toBeCalledWith(
587590
'/mock/android/home/platform-tools/adb',
588-
expect.arrayContaining(['emulator-5552', 'com.test/com.test.MainActivity']),
589-
{ stdio: ['ignore', 'ignore', 'pipe'] }
591+
expect.arrayContaining(['emulator-5552', 'com.test/com.test.MainActivity'])
590592
);
591593

592594
// launches com.test app with MainActivity on emulator-5554
593595
expect(spawn).toBeCalledWith(
594596
'/mock/android/home/platform-tools/adb',
595-
expect.arrayContaining(['emulator-5554', 'com.test/com.test.MainActivity']),
596-
{ stdio: ['ignore', 'ignore', 'pipe'] }
597+
expect.arrayContaining(['emulator-5554', 'com.test/com.test.MainActivity'])
597598
);
598599
});

packages/platform-android/src/lib/commands/runAndroid/__tests__/tryLaunchAppOnDevice.test.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,12 @@ const actionCategoryFlags = [
6262
test('launches adb shell with intent to launch com.myapp.MainActivity with different appId than packageName on a simulator', async () => {
6363
await tryLaunchAppOnDevice(device, androidProject, args);
6464

65-
expect(spawn).toHaveBeenCalledWith(
66-
'/mock/android/home/platform-tools/adb',
67-
[
68-
...shellStartCommand,
69-
'-n',
70-
'com.myapp.custom/com.myapp.MainActivity',
71-
...actionCategoryFlags,
72-
],
73-
{ stdio: ['ignore', 'ignore', 'pipe'] }
74-
);
65+
expect(spawn).toHaveBeenCalledWith('/mock/android/home/platform-tools/adb', [
66+
...shellStartCommand,
67+
'-n',
68+
'com.myapp.custom/com.myapp.MainActivity',
69+
...actionCategoryFlags,
70+
]);
7571
});
7672

7773
test('launches adb shell with intent to launch com.myapp.MainActivity with different appId than packageName on a simulator when mainActivity is fully qualified name', async () => {
@@ -81,16 +77,12 @@ test('launches adb shell with intent to launch com.myapp.MainActivity with diffe
8177
args
8278
);
8379

84-
expect(spawn).toHaveBeenCalledWith(
85-
'/mock/android/home/platform-tools/adb',
86-
[
87-
...shellStartCommand,
88-
'-n',
89-
'com.myapp.custom/com.myapp.MainActivity',
90-
...actionCategoryFlags,
91-
],
92-
{ stdio: ['ignore', 'ignore', 'pipe'] }
93-
);
80+
expect(spawn).toHaveBeenCalledWith('/mock/android/home/platform-tools/adb', [
81+
...shellStartCommand,
82+
'-n',
83+
'com.myapp.custom/com.myapp.MainActivity',
84+
...actionCategoryFlags,
85+
]);
9486
});
9587

9688
test('launches adb shell with intent to launch com.myapp.MainActivity with same appId as packageName on a simulator', async () => {
@@ -107,8 +99,7 @@ test('launches adb shell with intent to launch com.myapp.MainActivity with same
10799
'-n',
108100
'com.myapp/com.myapp.MainActivity',
109101
...actionCategoryFlags,
110-
],
111-
{ stdio: ['ignore', 'ignore', 'pipe'] }
102+
]
112103
);
113104
});
114105

@@ -122,8 +113,7 @@ test('launches adb shell with intent to launch com.myapp.MainActivity with diffe
122113
'-n',
123114
'com.myapp.custom/com.myapp.MainActivity',
124115
...actionCategoryFlags,
125-
],
126-
{ stdio: ['ignore', 'ignore', 'pipe'] }
116+
]
127117
);
128118
});
129119

@@ -147,8 +137,7 @@ test('launches adb shell with intent to launch fully specified activity with dif
147137
'-n',
148138
'com.myapp.custom.dev/com.zoontek.rnbootsplash.RNBootSplashActivity',
149139
...actionCategoryFlags,
150-
],
151-
{ stdio: ['ignore', 'ignore', 'pipe'] }
140+
]
152141
);
153142
});
154143

@@ -165,8 +154,7 @@ test('--appId flag overwrites applicationId setting in androidProject', async ()
165154
'-n',
166155
'my.app.id/com.myapp.MainActivity',
167156
...actionCategoryFlags,
168-
],
169-
{ stdio: ['ignore', 'ignore', 'pipe'] }
157+
]
170158
);
171159
});
172160

@@ -183,7 +171,6 @@ test('appIdSuffix Staging is appended to applicationId', async () => {
183171
'-n',
184172
'com.myapp.custom.Staging/com.myapp.MainActivity',
185173
...actionCategoryFlags,
186-
],
187-
{ stdio: ['ignore', 'ignore', 'pipe'] }
174+
]
188175
);
189176
});

packages/platform-android/src/lib/commands/runAndroid/adb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function parseDevicesResult(result: string): Array<string> {
3434
export async function getDevices() {
3535
const adbPath = getAdbPath();
3636
try {
37-
const { output } = await spawn(adbPath, ['devices']);
37+
const { output } = await spawn(adbPath, ['devices'], { stdio: 'pipe' });
3838
return parseDevicesResult(output);
3939
} catch {
4040
return [];

packages/platform-android/src/lib/commands/runAndroid/findOutputFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async function getAvailableCPUs(device?: string) {
8787
adbArgs.unshift('-s', device);
8888
}
8989

90-
const { output } = await spawn(adbPath, adbArgs);
90+
const { output } = await spawn(adbPath, adbArgs, { stdio: 'pipe' });
9191

9292
return output.trim().split(',');
9393
} catch {

packages/platform-android/src/lib/commands/runAndroid/listAndroidDevices.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ export type DeviceData = {
1717
*/
1818
async function getEmulatorName(deviceId: string) {
1919
const adbPath = getAdbPath();
20-
const { output } = await spawn(adbPath, [
21-
'-s',
22-
deviceId,
23-
'emu',
24-
'avd',
25-
'name',
26-
]);
20+
const { output } = await spawn(
21+
adbPath,
22+
['-s', deviceId, 'emu', 'avd', 'name'],
23+
{ stdio: 'pipe' }
24+
);
2725

2826
// 1st line should get us emu name
2927
return output
@@ -39,13 +37,11 @@ async function getEmulatorName(deviceId: string) {
3937
*/
4038
async function getPhoneName(deviceId: string) {
4139
const adbPath = getAdbPath();
42-
const { output } = await spawn(adbPath, [
43-
'-s',
44-
deviceId,
45-
'shell',
46-
'getprop',
47-
'ro.product.model',
48-
]);
40+
const { output } = await spawn(
41+
adbPath,
42+
['-s', deviceId, 'shell', 'getprop', 'ro.product.model'],
43+
{ stdio: 'pipe' }
44+
);
4945
return output.replace(/\[ro\.product\.model\]:\s*\[(.*)\]/, '$1').trim();
5046
}
5147

packages/platform-android/src/lib/commands/runAndroid/listAndroidUsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function checkUsers(device: string): Promise<User[]> {
1717
loader.start(`Checking users on "${device}"`);
1818

1919
try {
20-
const { stdout, stderr } = await spawn(adbPath, adbArgs);
20+
const { stdout, stderr } = await spawn(adbPath, adbArgs, { stdio: 'pipe' });
2121

2222
if (stderr) {
2323
loader.stop(`Failed to check users of "${device}". ${stderr}`, 1);

packages/platform-android/src/lib/commands/runAndroid/tryInstallAppOnDevice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function tryInstallAppOnDevice(
5959
`Installing the app on ${device.readableName} (id: ${deviceId})`
6060
);
6161
try {
62-
await spawn(adbPath, adbArgs, { stdio: ['ignore', 'ignore', 'pipe'] });
62+
await spawn(adbPath, adbArgs);
6363
loader.stop(
6464
`Installed the app on ${device.readableName} (id: ${deviceId}).`
6565
);

0 commit comments

Comments
 (0)