Fix bug causing archived devices trying to connect
Reviewed By: nikoant Differential Revision: D28064540 fbshipit-source-id: 43f05c4348a33e9633751bb9f69cd8d17ddd13c4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8a3ba8615d
commit
699343a9ca
@@ -11,7 +11,7 @@ import {createStore} from 'redux';
|
||||
import BaseDevice from '../devices/BaseDevice';
|
||||
import {rootReducer} from '../store';
|
||||
import {Store} from '../reducers/index';
|
||||
import Client, {ClientQuery} from '../Client';
|
||||
import Client, {ClientQuery, FlipperClientConnection} from '../Client';
|
||||
import {buildClientId} from '../utils/clientUtils';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
import {PluginDefinition} from '../plugin';
|
||||
@@ -20,6 +20,7 @@ import {getInstance} from '../fb-stubs/Logger';
|
||||
import {initializeFlipperLibImplementation} from '../utils/flipperLibImplementation';
|
||||
import pluginManager from '../dispatcher/pluginManager';
|
||||
import {PluginDetails} from 'flipper-plugin-lib';
|
||||
import ArchivedDevice from '../devices/ArchivedDevice';
|
||||
|
||||
export interface AppOptions {
|
||||
plugins?: PluginDefinition[];
|
||||
@@ -37,6 +38,7 @@ export interface ClientOptions {
|
||||
export interface DeviceOptions {
|
||||
serial?: string;
|
||||
isSupportedByPlugin?: (p: PluginDetails) => boolean;
|
||||
archived?: boolean;
|
||||
}
|
||||
|
||||
export default class MockFlipper {
|
||||
@@ -110,13 +112,17 @@ export default class MockFlipper {
|
||||
public createDevice({
|
||||
serial,
|
||||
isSupportedByPlugin,
|
||||
archived,
|
||||
}: DeviceOptions = {}): BaseDevice {
|
||||
const device = new BaseDevice(
|
||||
serial ?? `serial_${++this._deviceCounter}`,
|
||||
'physical',
|
||||
'MockAndroidDevice',
|
||||
'Android',
|
||||
);
|
||||
const s = serial ?? `serial_${++this._deviceCounter}`;
|
||||
const device = archived
|
||||
? new ArchivedDevice({
|
||||
serial: s,
|
||||
deviceType: 'emulator',
|
||||
title: 'archived device',
|
||||
os: 'Android',
|
||||
})
|
||||
: new BaseDevice(s, 'physical', 'MockAndroidDevice', 'Android');
|
||||
device.supportsPlugin = !isSupportedByPlugin
|
||||
? () => true
|
||||
: isSupportedByPlugin;
|
||||
@@ -172,13 +178,12 @@ export default class MockFlipper {
|
||||
const client = new Client(
|
||||
id,
|
||||
query,
|
||||
null, // create a stub connection to avoid this plugin to be archived?
|
||||
device.isArchived ? null : createStubConnection(),
|
||||
this._logger,
|
||||
this._store,
|
||||
supportedPlugins,
|
||||
device,
|
||||
);
|
||||
|
||||
// yikes
|
||||
client.device = {
|
||||
then() {
|
||||
@@ -212,7 +217,9 @@ export default class MockFlipper {
|
||||
};
|
||||
client.rawSend = jest.fn();
|
||||
|
||||
await client.init();
|
||||
if (!device.isArchived) {
|
||||
await client.init();
|
||||
}
|
||||
|
||||
// As convenience, by default we select the new client, star the plugin, and select it
|
||||
if (!skipRegister) {
|
||||
@@ -227,3 +234,33 @@ export default class MockFlipper {
|
||||
return client;
|
||||
}
|
||||
}
|
||||
function createStubConnection():
|
||||
| FlipperClientConnection<any, any>
|
||||
| null
|
||||
| undefined {
|
||||
return {
|
||||
close() {
|
||||
throw new Error('Should not be called in test');
|
||||
},
|
||||
fireAndForget() {
|
||||
throw new Error('Should not be called in test');
|
||||
},
|
||||
requestResponse() {
|
||||
throw new Error('Should not be called in test');
|
||||
},
|
||||
connectionStatus() {
|
||||
return {
|
||||
subscribe() {},
|
||||
lift() {
|
||||
throw new Error('Should not be called in test');
|
||||
},
|
||||
map() {
|
||||
throw new Error('Should not be called in test');
|
||||
},
|
||||
take() {
|
||||
throw new Error('Should not be called in test');
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ type MockOptions = Partial<{
|
||||
asBackgroundPlugin?: true;
|
||||
supportedPlugins?: string[];
|
||||
device?: BaseDevice;
|
||||
archivedDevice?: boolean;
|
||||
}>;
|
||||
|
||||
function isPluginEnabled(
|
||||
@@ -90,7 +91,8 @@ export async function createMockFlipperWithPlugin(
|
||||
const logger = mockFlipper.logger;
|
||||
const store = mockFlipper.store;
|
||||
|
||||
const createDevice = (serial: string) => mockFlipper.createDevice({serial});
|
||||
const createDevice = (serial: string, archived?: boolean) =>
|
||||
mockFlipper.createDevice({serial, archived});
|
||||
const createClient = async (
|
||||
device: BaseDevice,
|
||||
name: string,
|
||||
@@ -131,7 +133,7 @@ export async function createMockFlipperWithPlugin(
|
||||
|
||||
const device = options?.device
|
||||
? mockFlipper.loadDevice(options?.device)
|
||||
: createDevice('serial');
|
||||
: createDevice('serial', options?.archivedDevice);
|
||||
const client = await createClient(device, 'TestApp');
|
||||
|
||||
store.dispatch(selectDevice(device));
|
||||
|
||||
Reference in New Issue
Block a user