Skip to content

Commit bda8e7b

Browse files
committed
Add option to use physical Android device for tests.
1 parent 589fd4b commit bda8e7b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/scripts/test.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ program
2424
'The virtual android device name (the adb device name will be fetched from this)',
2525
DEFAULT_AVD_NAME
2626
)
27+
.option('--device', 'Use a physical device instead of emulator')
2728
.option('--port', 'Port to run Express HTTP server for getting results on.', DEFAULT_PORT)
2829
.action(async (str, options) => {
2930
const opts = options.opts();
3031
const avdName = opts.avdName;
31-
const deviceName = await getADBDeviceName(avdName);
32+
const useDevice = opts.device;
33+
const deviceName = await getADBDeviceName(avdName, useDevice);
3234
if (!deviceName) {
3335
throw new Error(`Could not find adb device with AVD name ${avdName}`);
3436
}
@@ -38,7 +40,11 @@ program
3840
await spawnP('Reverse Port', `adb`, [`-s`, deviceName, `reverse`, `tcp:${port}`, `tcp:${port}`]);
3941

4042
/** Build and run the Expo app, don't await this, we will await a response. */
41-
spawnP('Build Expo App', `yarn`, [`android`, `-d`, avdName]);
43+
if (!useDevice) {
44+
spawnP('Build Expo App', `yarn`, [`android`, `-d`, avdName]);
45+
} else {
46+
spawnP('Build Expo App', `yarn`, [`android`]);
47+
}
4248

4349
const app = express();
4450
app.use(bodyParser.json());
@@ -107,7 +113,7 @@ async function spawnP(tag, cmd, args = []) {
107113
});
108114
}
109115

110-
async function getADBDeviceName(avdName) {
116+
async function getADBDeviceName(avdName, useDevice) {
111117
const tag = 'Get ADB Device';
112118
const devicesOutput = await spawnP(tag, 'adb', ['devices']);
113119
const deviceNames = _.chain(devicesOutput.split('\n'))
@@ -116,7 +122,9 @@ async function getADBDeviceName(avdName) {
116122
.map((line) => line.trim()) // Omit empty results
117123
.filter((line) => !!line)
118124
.value();
119-
125+
if (useDevice) {
126+
return deviceNames[0];
127+
}
120128
// Need to check all devices for their AVD name
121129
for (let deviceName of deviceNames) {
122130
try {

0 commit comments

Comments
 (0)