Add archived device type

Summary:
This diff adds archived device type. This diff solves the following two problems.

- The Plugin which are device plugins and are device plugins will not show up. Look at the video, where the CPU plugin was showed, even though the imported file didn't have any information.
- An icon of 📦 will make much clearer which one is archived device and which isn't

Reviewed By: passy

Differential Revision: D14066399

fbshipit-source-id: 59b740d7fe9532e665d6b1ec6ad0124fb63ac45d
This commit is contained in:
Pritesh Nandgaonkar
2019-02-14 06:28:53 -08:00
committed by Facebook Github Bot
parent 9b6db1f482
commit b9db2411cf
5 changed files with 53 additions and 23 deletions

View File

@@ -70,14 +70,31 @@ class DevicesButton extends Component<Props> {
label: 'Running devices', label: 'Running devices',
enabled: false, enabled: false,
}, },
...devices.map((device: BaseDevice) => ({ ...devices.map((device: BaseDevice) => {
click: () => selectDevice(device), let label = '';
checked: device === selectedDevice, switch (device.deviceType) {
label: `${device.deviceType === 'physical' ? '📱 ' : ''}${ case 'emulator':
device.title label = '';
}`, break;
type: 'checkbox', case 'physical':
})), label = '📱 ';
break;
case 'archivedEmulator':
label = '📦 ';
break;
case 'archivedPhysical':
label = '📦 ';
break;
default:
label = '';
}
return {
click: () => selectDevice(device),
checked: device === selectedDevice,
label: `${label}${device.title}`,
type: 'checkbox',
};
}),
); );
} }
if (androidEmulators.length > 0) { if (androidEmulators.length > 0) {
@@ -91,7 +108,6 @@ class DevicesButton extends Component<Props> {
label: name, label: name,
click: () => this.launchEmulator(name), click: () => this.launchEmulator(name),
})); }));
if (emulators.length > 0) { if (emulators.length > 0) {
dropdown.push( dropdown.push(
{type: 'separator'}, {type: 'separator'},
@@ -116,5 +132,8 @@ export default connect<Props, {||}, _, _, _, _>(
androidEmulators, androidEmulators,
selectedDevice, selectedDevice,
}), }),
{selectDevice, preferDevice}, {
selectDevice,
preferDevice,
},
)(DevicesButton); )(DevicesButton);

View File

@@ -20,7 +20,13 @@ export default class ArchivedDevice extends BaseDevice {
os: OS, os: OS,
logEntries: Array<DeviceLogEntry>, logEntries: Array<DeviceLogEntry>,
) { ) {
super(serial, deviceType, title); let archivedDeviceType = deviceType;
if (archivedDeviceType === 'emulator') {
archivedDeviceType = 'archivedEmulator';
} else if (archivedDeviceType === 'physical') {
archivedDeviceType = 'archivedPhysical';
}
super(serial, archivedDeviceType, title);
this.os = os; this.os = os;
this.logs = logEntries; this.logs = logEntries;
} }

View File

@@ -34,7 +34,11 @@ export type DeviceShell = {
export type DeviceLogListener = (entry: DeviceLogEntry) => void; export type DeviceLogListener = (entry: DeviceLogEntry) => void;
export type DeviceType = 'emulator' | 'physical'; export type DeviceType =
| 'emulator'
| 'physical'
| 'archivedEmulator'
| 'archivedPhysical';
export type DeviceExport = {| export type DeviceExport = {|
os: string, os: string,

View File

@@ -5,13 +5,14 @@
* @format * @format
*/ */
import {promisify} from 'util'; import {promisify} from 'util';
import type {DeviceType} from '../devices/BaseDevice';
const exec = promisify(require('child_process').exec); const exec = promisify(require('child_process').exec);
const errorMessage = 'Physical iOS devices not yet supported'; const errorMessage = 'Physical iOS devices not yet supported';
export type DeviceTarget = { export type DeviceTarget = {
udid: string, udid: string,
type: 'physical' | 'emulator', type: DeviceType,
name: string, name: string,
}; };

View File

@@ -73,8 +73,8 @@ test('test generateClientIndentifierWithSalt helper function', () => {
); );
const identifier = generateClientIdentifier(device, 'app'); const identifier = generateClientIdentifier(device, 'app');
const saltIdentifier = generateClientIdentifierWithSalt(identifier, 'salt'); const saltIdentifier = generateClientIdentifierWithSalt(identifier, 'salt');
expect(saltIdentifier).toEqual('app#iOS#emulator#salt-serial'); expect(saltIdentifier).toEqual('app#iOS#archivedEmulator#salt-serial');
expect(identifier).toEqual('app#iOS#emulator#serial'); expect(identifier).toEqual('app#iOS#archivedEmulator#serial');
}); });
test('test generateClientFromClientWithSalt helper function', () => { test('test generateClientFromClientWithSalt helper function', () => {
@@ -88,20 +88,20 @@ test('test generateClientFromClientWithSalt helper function', () => {
const client = generateClientFromDevice(device, 'app'); const client = generateClientFromDevice(device, 'app');
const saltedClient = generateClientFromClientWithSalt(client, 'salt'); const saltedClient = generateClientFromClientWithSalt(client, 'salt');
expect(saltedClient).toEqual({ expect(saltedClient).toEqual({
id: 'app#iOS#emulator#salt-serial', id: 'app#iOS#archivedEmulator#salt-serial',
query: { query: {
app: 'app', app: 'app',
os: 'iOS', os: 'iOS',
device: 'emulator', device: 'archivedEmulator',
device_id: 'salt-serial', device_id: 'salt-serial',
}, },
}); });
expect(client).toEqual({ expect(client).toEqual({
id: 'app#iOS#emulator#serial', id: 'app#iOS#archivedEmulator#serial',
query: { query: {
app: 'app', app: 'app',
os: 'iOS', os: 'iOS',
device: 'emulator', device: 'archivedEmulator',
device_id: 'serial', device_id: 'serial',
}, },
}); });
@@ -117,11 +117,11 @@ test('test generateClientFromDevice helper function', () => {
); );
const client = generateClientFromDevice(device, 'app'); const client = generateClientFromDevice(device, 'app');
expect(client).toEqual({ expect(client).toEqual({
id: 'app#iOS#emulator#serial', id: 'app#iOS#archivedEmulator#serial',
query: { query: {
app: 'app', app: 'app',
os: 'iOS', os: 'iOS',
device: 'emulator', device: 'archivedEmulator',
device_id: 'serial', device_id: 'serial',
}, },
}); });
@@ -136,7 +136,7 @@ test('test generateClientIdentifier helper function', () => {
[], [],
); );
const identifier = generateClientIdentifier(device, 'app'); const identifier = generateClientIdentifier(device, 'app');
expect(identifier).toEqual('app#iOS#emulator#serial'); expect(identifier).toEqual('app#iOS#archivedEmulator#serial');
}); });
test('test generateNotifications helper function', () => { test('test generateNotifications helper function', () => {
@@ -171,7 +171,7 @@ test('test processStore function for an iOS device connected', () => {
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done //$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {serial, deviceType, title, os} = device; const {serial, deviceType, title, os} = device;
expect(serial).toEqual('salt-serial'); expect(serial).toEqual('salt-serial');
expect(deviceType).toEqual('emulator'); expect(deviceType).toEqual('archivedEmulator');
expect(title).toEqual('TestiPhone'); expect(title).toEqual('TestiPhone');
expect(os).toEqual('iOS'); expect(os).toEqual('iOS');
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done //$FlowFixMe Flow doesn't that its a test and the assertion for null is already done