xref: /expo/tools/src/FirebaseTestLab.ts (revision a272999e)
1import spawnAsync from '@expo/spawn-async';
2import path from 'path';
3
4import { getExpoRepositoryRootDir } from './Directories';
5
6const ANDROID_DIR = path.join(getExpoRepositoryRootDir(), 'android');
7
8export async function runAndroidTestsAsync(
9  pathToAppApk: string,
10  pathToTestApk: string
11): Promise<void> {
12  await spawnAsync(
13    'gcloud',
14    [
15      'firebase',
16      'test',
17      'android',
18      'run',
19      '--type',
20      'instrumentation',
21      '--app',
22      pathToAppApk,
23      '--test',
24      pathToTestApk,
25      '--device',
26      'model=Nexus6,version=25,locale=en,orientation=portrait',
27    ],
28    {
29      stdio: 'inherit',
30    }
31  );
32}
33
34export async function buildLocalAndroidAndRunTestAsync(
35  env: { [key: string]: any } = {}
36): Promise<void> {
37  await spawnAsync('./gradlew', [':app:assembleDebug'], {
38    cwd: ANDROID_DIR,
39    env: {
40      ...process.env,
41      ...env,
42    },
43  });
44
45  await spawnAsync('./gradlew', [':app:assembleDebugAndroidTest'], {
46    cwd: ANDROID_DIR,
47    env: {
48      ...process.env,
49      ...env,
50    },
51  });
52
53  return await runAndroidTestsAsync(
54    path.join(ANDROID_DIR, 'app/build/outputs/apk/debug/app-debug.apk'),
55    path.join(ANDROID_DIR, 'app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk')
56  );
57}
58