Import and export Logs
Summary: This diff adds import and export support for the logs plugin Reviewed By: danielbuechele Differential Revision: D13958713 fbshipit-source-id: a072de025f0b959302175ef0ccaf763ca41377e9
This commit is contained in:
committed by
Facebook Github Bot
parent
e5151b9994
commit
c28ef62f07
@@ -5,16 +5,30 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
import BaseDevice from './BaseDevice.js';
|
import BaseDevice from './BaseDevice.js';
|
||||||
import type {DeviceType, OS, DeviceShell} from './BaseDevice.js';
|
import type {
|
||||||
|
DeviceType,
|
||||||
|
OS,
|
||||||
|
DeviceShell,
|
||||||
|
DeviceLogEntry,
|
||||||
|
} from './BaseDevice.js';
|
||||||
|
|
||||||
export default class ArchivedDevice extends BaseDevice {
|
export default class ArchivedDevice extends BaseDevice {
|
||||||
constructor(serial: string, deviceType: DeviceType, title: string, os: OS) {
|
constructor(
|
||||||
|
serial: string,
|
||||||
|
deviceType: DeviceType,
|
||||||
|
title: string,
|
||||||
|
os: OS,
|
||||||
|
logEntries: Array<DeviceLogEntry>,
|
||||||
|
) {
|
||||||
super(serial, deviceType, title);
|
super(serial, deviceType, title);
|
||||||
this.os = os;
|
this.os = os;
|
||||||
|
this.logs = logEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logs: Array<DeviceLogEntry>;
|
||||||
|
|
||||||
getLogs() {
|
getLogs() {
|
||||||
return [];
|
return this.logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnShell(): ?DeviceShell {
|
spawnShell(): ?DeviceShell {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export type DeviceExport = {|
|
|||||||
title: string,
|
title: string,
|
||||||
deviceType: DeviceType,
|
deviceType: DeviceType,
|
||||||
serial: string,
|
serial: string,
|
||||||
|
logs: Array<DeviceLogEntry>,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export type OS = 'iOS' | 'Android' | 'Windows';
|
export type OS = 'iOS' | 'Android' | 'Windows';
|
||||||
@@ -80,6 +81,7 @@ export default class BaseDevice {
|
|||||||
title: this.title,
|
title: this.title,
|
||||||
deviceType: this.deviceType,
|
deviceType: this.deviceType,
|
||||||
serial: this.serial,
|
serial: this.serial,
|
||||||
|
logs: this.getLogs(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,13 @@ function generateClientFromDevice(
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('test generateClientIndentifierWithSalt helper function', () => {
|
test('test generateClientIndentifierWithSalt helper function', () => {
|
||||||
const device = new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS');
|
const device = new ArchivedDevice(
|
||||||
|
'serial',
|
||||||
|
'emulator',
|
||||||
|
'TestiPhone',
|
||||||
|
'iOS',
|
||||||
|
[],
|
||||||
|
);
|
||||||
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#emulator#salt-serial');
|
||||||
@@ -72,7 +78,13 @@ test('test generateClientIndentifierWithSalt helper function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('test generateClientFromClientWithSalt helper function', () => {
|
test('test generateClientFromClientWithSalt helper function', () => {
|
||||||
const device = new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS');
|
const device = new ArchivedDevice(
|
||||||
|
'serial',
|
||||||
|
'emulator',
|
||||||
|
'TestiPhone',
|
||||||
|
'iOS',
|
||||||
|
[],
|
||||||
|
);
|
||||||
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({
|
||||||
@@ -96,7 +108,13 @@ test('test generateClientFromClientWithSalt helper function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('test generateClientFromDevice helper function', () => {
|
test('test generateClientFromDevice helper function', () => {
|
||||||
const device = new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS');
|
const device = new ArchivedDevice(
|
||||||
|
'serial',
|
||||||
|
'emulator',
|
||||||
|
'TestiPhone',
|
||||||
|
'iOS',
|
||||||
|
[],
|
||||||
|
);
|
||||||
const client = generateClientFromDevice(device, 'app');
|
const client = generateClientFromDevice(device, 'app');
|
||||||
expect(client).toEqual({
|
expect(client).toEqual({
|
||||||
id: 'app#iOS#emulator#serial',
|
id: 'app#iOS#emulator#serial',
|
||||||
@@ -110,7 +128,13 @@ test('test generateClientFromDevice helper function', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('test generateClientIdentifier helper function', () => {
|
test('test generateClientIdentifier helper function', () => {
|
||||||
const device = new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS');
|
const device = new ArchivedDevice(
|
||||||
|
'serial',
|
||||||
|
'emulator',
|
||||||
|
'TestiPhone',
|
||||||
|
'iOS',
|
||||||
|
[],
|
||||||
|
);
|
||||||
const identifier = generateClientIdentifier(device, 'app');
|
const identifier = generateClientIdentifier(device, 'app');
|
||||||
expect(identifier).toEqual('app#iOS#emulator#serial');
|
expect(identifier).toEqual('app#iOS#emulator#serial');
|
||||||
});
|
});
|
||||||
@@ -133,7 +157,7 @@ test('test processStore function for empty state', () => {
|
|||||||
test('test processStore function for an iOS device connected', () => {
|
test('test processStore function for an iOS device connected', () => {
|
||||||
const json = processStore(
|
const json = processStore(
|
||||||
[],
|
[],
|
||||||
new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS'),
|
new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS', []),
|
||||||
{},
|
{},
|
||||||
[],
|
[],
|
||||||
new Map(),
|
new Map(),
|
||||||
@@ -157,7 +181,13 @@ test('test processStore function for an iOS device connected', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('test processStore function for an iOS device connected with client plugin data', () => {
|
test('test processStore function for an iOS device connected with client plugin data', () => {
|
||||||
const device = new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS');
|
const device = new ArchivedDevice(
|
||||||
|
'serial',
|
||||||
|
'emulator',
|
||||||
|
'TestiPhone',
|
||||||
|
'iOS',
|
||||||
|
[],
|
||||||
|
);
|
||||||
const clientIdentifier = generateClientIdentifier(device, 'testapp');
|
const clientIdentifier = generateClientIdentifier(device, 'testapp');
|
||||||
const json = processStore(
|
const json = processStore(
|
||||||
[],
|
[],
|
||||||
@@ -184,12 +214,14 @@ test('test processStore function to have only the client for the selected device
|
|||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
const unselectedDevice = new ArchivedDevice(
|
const unselectedDevice = new ArchivedDevice(
|
||||||
'identifier',
|
'identifier',
|
||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const unselectedDeviceClientIdentifier = generateClientIdentifier(
|
const unselectedDeviceClientIdentifier = generateClientIdentifier(
|
||||||
@@ -247,6 +279,7 @@ test('test processStore function to have multiple clients for the selected devic
|
|||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const clientIdentifierApp1 = generateClientIdentifier(
|
const clientIdentifierApp1 = generateClientIdentifier(
|
||||||
@@ -308,6 +341,7 @@ test('test processStore function for device plugin state and no clients', () =>
|
|||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
const json = processStore(
|
const json = processStore(
|
||||||
[],
|
[],
|
||||||
@@ -340,6 +374,7 @@ test('test processStore function for unselected device plugin state and no clien
|
|||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
const json = processStore(
|
const json = processStore(
|
||||||
[],
|
[],
|
||||||
@@ -369,6 +404,7 @@ test('test processStore function for notifications for selected device', () => {
|
|||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
const client = generateClientFromDevice(selectedDevice, 'testapp1');
|
const client = generateClientFromDevice(selectedDevice, 'testapp1');
|
||||||
const notification = generateNotifications(
|
const notification = generateNotifications(
|
||||||
@@ -416,12 +452,14 @@ test('test processStore function for notifications for unselected device', () =>
|
|||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
const unselectedDevice = new ArchivedDevice(
|
const unselectedDevice = new ArchivedDevice(
|
||||||
'identifier',
|
'identifier',
|
||||||
'emulator',
|
'emulator',
|
||||||
'TestiPhone',
|
'TestiPhone',
|
||||||
'iOS',
|
'iOS',
|
||||||
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const client = generateClientFromDevice(selectedDevice, 'testapp1');
|
const client = generateClientFromDevice(selectedDevice, 'testapp1');
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ const addSaltToDeviceSerial = (
|
|||||||
device.deviceType,
|
device.deviceType,
|
||||||
device.title,
|
device.title,
|
||||||
device.os,
|
device.os,
|
||||||
|
device.getLogs(),
|
||||||
);
|
);
|
||||||
const updatedClients = clients.map((client: ClientExport) => {
|
const updatedClients = clients.map((client: ClientExport) => {
|
||||||
return {
|
return {
|
||||||
@@ -215,11 +216,16 @@ export const importFileToStore = (file: string, store: Store) => {
|
|||||||
}
|
}
|
||||||
const json = JSON.parse(data);
|
const json = JSON.parse(data);
|
||||||
const {device, clients} = json;
|
const {device, clients} = json;
|
||||||
|
const updatedLogs = device.logs.map(log => {
|
||||||
|
// During the export, Date is exported as string
|
||||||
|
return {...log, date: new Date(log.date)};
|
||||||
|
});
|
||||||
const archivedDevice = new ArchivedDevice(
|
const archivedDevice = new ArchivedDevice(
|
||||||
device.serial,
|
device.serial,
|
||||||
device.deviceType,
|
device.deviceType,
|
||||||
device.title,
|
device.title,
|
||||||
device.os,
|
device.os,
|
||||||
|
updatedLogs,
|
||||||
);
|
);
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'REGISTER_DEVICE',
|
type: 'REGISTER_DEVICE',
|
||||||
|
|||||||
Reference in New Issue
Block a user