Add revision information in the exported file

Summary: Adds revision information which is used to build the flipper app. for more context follow the [discussion](https://fb.workplace.com/groups/1489943347777350/permalink/2046366362135043/)

Reviewed By: danielbuechele

Differential Revision: D14458169

fbshipit-source-id: 71860f1e78c042f76d0e220dd3be96f2adaf609e
This commit is contained in:
Pritesh Nandgaonkar
2019-03-15 09:54:17 -07:00
committed by Facebook Github Bot
parent e184af7f2a
commit 51139500f4
2 changed files with 26 additions and 32 deletions

View File

@@ -151,11 +151,11 @@ test('test generateNotifications helper function', () => {
test('test processStore function for empty state', () => { test('test processStore function for empty state', () => {
const json = processStore([], null, {}, [], new Map(), 'salt'); const json = processStore([], null, {}, [], new Map(), 'salt');
expect(json).toBeNull(); expect(json).resolves.toBeNull();
}); });
test('test processStore function for an iOS device connected', () => { test('test processStore function for an iOS device connected', async () => {
const json = processStore( const json = await processStore(
[], [],
new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS', []), new ArchivedDevice('serial', 'emulator', 'TestiPhone', 'iOS', []),
{}, {},
@@ -168,19 +168,17 @@ test('test processStore function for an iOS device connected', () => {
const {device, clients} = json; const {device, clients} = json;
expect(device).toBeDefined(); expect(device).toBeDefined();
expect(clients).toEqual([]); expect(clients).toEqual([]);
//$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('archivedEmulator'); 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
const {pluginStates, activeNotifications} = json.store; const {pluginStates, activeNotifications} = json.store;
expect(pluginStates).toEqual({}); expect(pluginStates).toEqual({});
expect(activeNotifications).toEqual([]); expect(activeNotifications).toEqual([]);
}); });
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', async () => {
const device = new ArchivedDevice( const device = new ArchivedDevice(
'serial', 'serial',
'emulator', 'emulator',
@@ -189,7 +187,7 @@ test('test processStore function for an iOS device connected with client plugin
[], [],
); );
const clientIdentifier = generateClientIdentifier(device, 'testapp'); const clientIdentifier = generateClientIdentifier(device, 'testapp');
const json = processStore( const json = await processStore(
[], [],
device, device,
{[clientIdentifier]: {msg: 'Test plugin'}}, {[clientIdentifier]: {msg: 'Test plugin'}},
@@ -208,7 +206,7 @@ test('test processStore function for an iOS device connected with client plugin
expect(pluginStates).toEqual(expectedPluginState); expect(pluginStates).toEqual(expectedPluginState);
}); });
test('test processStore function to have only the client for the selected device', () => { test('test processStore function to have only the client for the selected device', async () => {
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice(
'serial', 'serial',
'emulator', 'emulator',
@@ -237,7 +235,7 @@ test('test processStore function to have only the client for the selected device
'testapp', 'testapp',
); );
const json = processStore( const json = await processStore(
[], [],
selectedDevice, selectedDevice,
{ {
@@ -273,7 +271,7 @@ test('test processStore function to have only the client for the selected device
expect(pluginStates).toEqual(expectedPluginState); expect(pluginStates).toEqual(expectedPluginState);
}); });
test('test processStore function to have multiple clients for the selected device', () => { test('test processStore function to have multiple clients for the selected device', async () => {
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice(
'serial', 'serial',
'emulator', 'emulator',
@@ -294,7 +292,7 @@ test('test processStore function to have multiple clients for the selected devic
const client1 = generateClientFromDevice(selectedDevice, 'testapp1'); const client1 = generateClientFromDevice(selectedDevice, 'testapp1');
const client2 = generateClientFromDevice(selectedDevice, 'testapp2'); const client2 = generateClientFromDevice(selectedDevice, 'testapp2');
const json = processStore( const json = await processStore(
[], [],
selectedDevice, selectedDevice,
{ {
@@ -315,7 +313,6 @@ test('test processStore function to have multiple clients for the selected devic
expect(json).toBeDefined(); expect(json).toBeDefined();
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added //$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
const {clients} = json; const {clients} = json;
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
const {pluginStates} = json.store; const {pluginStates} = json.store;
let expectedPluginState = { let expectedPluginState = {
[generateClientIdentifierWithSalt(clientIdentifierApp1, 'salt') + [generateClientIdentifierWithSalt(clientIdentifierApp1, 'salt') +
@@ -334,7 +331,7 @@ test('test processStore function to have multiple clients for the selected devic
expect(pluginStates).toEqual(expectedPluginState); expect(pluginStates).toEqual(expectedPluginState);
}); });
test('test processStore function for device plugin state and no clients', () => { test('test processStore function for device plugin state and no clients', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice(
'serial', 'serial',
@@ -343,7 +340,7 @@ test('test processStore function for device plugin state and no clients', () =>
'iOS', 'iOS',
[], [],
); );
const json = processStore( const json = await processStore(
[], [],
selectedDevice, selectedDevice,
{ {
@@ -358,7 +355,6 @@ test('test processStore function for device plugin state and no clients', () =>
expect(json).toBeDefined(); expect(json).toBeDefined();
//$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 {pluginStates} = json.store; const {pluginStates} = json.store;
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {clients} = json; const {clients} = json;
let expectedPluginState = { let expectedPluginState = {
'salt-serial#TestDevicePlugin': {msg: 'Test Device plugin'}, 'salt-serial#TestDevicePlugin': {msg: 'Test Device plugin'},
@@ -367,7 +363,7 @@ test('test processStore function for device plugin state and no clients', () =>
expect(clients).toEqual([]); expect(clients).toEqual([]);
}); });
test('test processStore function for unselected device plugin state and no clients', () => { test('test processStore function for unselected device plugin state and no clients', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice(
'serial', 'serial',
@@ -376,7 +372,7 @@ test('test processStore function for unselected device plugin state and no clien
'iOS', 'iOS',
[], [],
); );
const json = processStore( const json = await processStore(
[], [],
selectedDevice, selectedDevice,
{ {
@@ -391,13 +387,12 @@ test('test processStore function for unselected device plugin state and no clien
expect(json).toBeDefined(); expect(json).toBeDefined();
//$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 {pluginStates} = json.store; const {pluginStates} = json.store;
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {clients} = json; const {clients} = json;
expect(pluginStates).toEqual({}); expect(pluginStates).toEqual({});
expect(clients).toEqual([]); expect(clients).toEqual([]);
}); });
test('test processStore function for notifications for selected device', () => { test('test processStore function for notifications for selected device', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice(
'serial', 'serial',
@@ -419,7 +414,7 @@ test('test processStore function for notifications for selected device', () => {
client: client.id, client: client.id,
}; };
const json = processStore( const json = await processStore(
[activeNotification], [activeNotification],
selectedDevice, selectedDevice,
{}, {},
@@ -431,11 +426,9 @@ test('test processStore function for notifications for selected device', () => {
expect(json).toBeDefined(); expect(json).toBeDefined();
//$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 {pluginStates} = json.store; const {pluginStates} = json.store;
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {clients} = json; const {clients} = json;
expect(pluginStates).toEqual({}); expect(pluginStates).toEqual({});
expect(clients).toEqual([generateClientFromClientWithSalt(client, 'salt')]); expect(clients).toEqual([generateClientFromClientWithSalt(client, 'salt')]);
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {activeNotifications} = json.store; const {activeNotifications} = json.store;
const expectedActiveNotification = { const expectedActiveNotification = {
pluginId: 'TestNotification', pluginId: 'TestNotification',
@@ -445,7 +438,7 @@ test('test processStore function for notifications for selected device', () => {
expect(activeNotifications).toEqual([expectedActiveNotification]); expect(activeNotifications).toEqual([expectedActiveNotification]);
}); });
test('test processStore function for notifications for unselected device', () => { test('test processStore function for notifications for unselected device', async () => {
// Test case to verify that device plugin data is exported even if there are no clients // Test case to verify that device plugin data is exported even if there are no clients
const selectedDevice = new ArchivedDevice( const selectedDevice = new ArchivedDevice(
'serial', 'serial',
@@ -478,7 +471,7 @@ test('test processStore function for notifications for unselected device', () =>
notification, notification,
client: unselectedclient.id, client: unselectedclient.id,
}; };
const json = processStore( const json = await processStore(
[activeNotification], [activeNotification],
selectedDevice, selectedDevice,
{}, {},
@@ -489,11 +482,9 @@ test('test processStore function for notifications for unselected device', () =>
expect(json).toBeDefined(); expect(json).toBeDefined();
//$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 {pluginStates} = json.store; const {pluginStates} = json.store;
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {clients} = json; const {clients} = json;
expect(pluginStates).toEqual({}); expect(pluginStates).toEqual({});
expect(clients).toEqual([generateClientFromClientWithSalt(client, 'salt')]); expect(clients).toEqual([generateClientFromClientWithSalt(client, 'salt')]);
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
const {activeNotifications} = json.store; const {activeNotifications} = json.store;
expect(activeNotifications).toEqual([]); expect(activeNotifications).toEqual([]);
}); });

View File

@@ -21,12 +21,13 @@ import fs from 'fs';
import uuid from 'uuid'; import uuid from 'uuid';
import {remote} from 'electron'; import {remote} from 'electron';
import {serialize, deserialize} from './serialization'; import {serialize, deserialize} from './serialization';
import {readCurrentRevision} from './packageMetadata.js';
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace'; export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';
export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace'; export const EXPORT_FLIPPER_TRACE_EVENT = 'export-flipper-trace';
export type ExportType = {| export type ExportType = {|
fileVersion: string, fileVersion: string,
flipperReleaseRevision: ?string,
clients: Array<ClientExport>, clients: Array<ClientExport>,
device: ?DeviceExport, device: ?DeviceExport,
store: { store: {
@@ -85,13 +86,13 @@ export function processNotificationStates(
return activeNotifications; return activeNotifications;
} }
const addSaltToDeviceSerial = ( const addSaltToDeviceSerial = async (
salt: string, salt: string,
device: BaseDevice, device: BaseDevice,
clients: Array<ClientExport>, clients: Array<ClientExport>,
pluginStates: PluginStatesState, pluginStates: PluginStatesState,
pluginNotification: Array<PluginNotification>, pluginNotification: Array<PluginNotification>,
): ExportType => { ): Promise<ExportType> => {
const {serial} = device; const {serial} = device;
const newSerial = salt + '-' + serial; const newSerial = salt + '-' + serial;
const newDevice = new ArchivedDevice( const newDevice = new ArchivedDevice(
@@ -131,8 +132,10 @@ const addSaltToDeviceSerial = (
} }
return {...notif, client: notif.client.replace(serial, newSerial)}; return {...notif, client: notif.client.replace(serial, newSerial)};
}); });
const revision: ?string = await readCurrentRevision();
return { return {
fileVersion: remote.app.getVersion(), fileVersion: remote.app.getVersion(),
flipperReleaseRevision: revision,
clients: updatedClients, clients: updatedClients,
device: newDevice.toJSON(), device: newDevice.toJSON(),
store: { store: {
@@ -142,14 +145,14 @@ const addSaltToDeviceSerial = (
}; };
}; };
export const processStore = ( export const processStore = async (
activeNotifications: Array<PluginNotification>, activeNotifications: Array<PluginNotification>,
device: ?BaseDevice, device: ?BaseDevice,
pluginStates: PluginStatesState, pluginStates: PluginStatesState,
clients: Array<ClientExport>, clients: Array<ClientExport>,
devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>, devicePlugins: Map<string, Class<FlipperDevicePlugin<>>>,
salt: string, salt: string,
): ?ExportType => { ): Promise<?ExportType> => {
if (device) { if (device) {
const {serial} = device; const {serial} = device;
const processedClients = processClients(clients, serial); const processedClients = processClients(clients, serial);
@@ -166,7 +169,7 @@ export const processStore = (
devicePlugins, devicePlugins,
); );
// Adding salt to the device id, so that the device_id in the device list is unique. // Adding salt to the device id, so that the device_id in the device list is unique.
const exportFlipperData = addSaltToDeviceSerial( const exportFlipperData = await addSaltToDeviceSerial(
salt, salt,
device, device,
processedClients, processedClients,