Use AbstractClient from flipper-frontend-core in fliper-ui-core
Summary: This stack attempts to start using flipper-frontend-core from flipper-ui-core. Currently, flipper-frontend-core contains lots of copy-pasted code from flipper-ui-core. Reviewed By: lblasa Differential Revision: D37139198 fbshipit-source-id: 042db7492c550e10ea72c32fd15001c141bf53f9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c2e3c4eb50
commit
ef5fa275a3
@@ -171,7 +171,9 @@ test.skip('PluginContainer can render Sandy plugins', async () => {
|
||||
const {renderer, act, sendMessage, client, store} =
|
||||
await renderMockFlipperWithPlugin(definition);
|
||||
|
||||
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
|
||||
expect((client as any).rawSend).toBeCalledWith('init', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
<body>
|
||||
@@ -260,7 +262,9 @@ test.skip('PluginContainer can render Sandy plugins', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
expect(client.rawSend).toBeCalledWith('deinit', {plugin: 'TestPlugin'});
|
||||
expect((client as any).rawSend).toBeCalledWith('deinit', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
<body>
|
||||
@@ -326,7 +330,9 @@ test.skip('PluginContainer can render Sandy plugins', async () => {
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(1);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(1);
|
||||
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
|
||||
expect((client as any).rawSend).toBeCalledWith('init', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
|
||||
// disable
|
||||
act(() => {
|
||||
@@ -341,7 +347,9 @@ test.skip('PluginContainer can render Sandy plugins', async () => {
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(2);
|
||||
expect(client.rawSend).toBeCalledWith('deinit', {plugin: 'TestPlugin'});
|
||||
expect((client as any).rawSend).toBeCalledWith('deinit', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
|
||||
// re-enable
|
||||
act(() => {
|
||||
@@ -365,7 +373,9 @@ test.skip('PluginContainer can render Sandy plugins', async () => {
|
||||
client.sandyPluginStates.get('TestPlugin')!.instanceApi;
|
||||
expect(newPluginInstance).not.toBe(pluginInstance);
|
||||
expect(newPluginInstance.connectedStub).toBeCalledTimes(1);
|
||||
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
|
||||
expect((client as any).rawSend).toBeCalledWith('init', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
expect(newPluginInstance.count.get()).toBe(0);
|
||||
});
|
||||
|
||||
@@ -401,8 +411,10 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
},
|
||||
});
|
||||
|
||||
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
|
||||
(client.rawSend as jest.Mock).mockClear();
|
||||
expect((client as any).rawSend).toBeCalledWith('init', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
((client as any).rawSend as jest.Mock).mockClear();
|
||||
// make sure the plugin gets connected
|
||||
const pluginInstance: ReturnType<typeof plugin> =
|
||||
client.sandyPluginStates.get(definition.id)!.instanceApi;
|
||||
@@ -423,8 +435,8 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
);
|
||||
});
|
||||
// bg plugin!
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
(client.rawSend as jest.Mock).mockClear();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
((client as any).rawSend as jest.Mock).mockClear();
|
||||
expect(pluginInstance.connectedStub).toBeCalledTimes(1);
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(1);
|
||||
@@ -445,8 +457,8 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(1);
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
(client.rawSend as jest.Mock).mockClear();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
((client as any).rawSend as jest.Mock).mockClear();
|
||||
|
||||
// disable
|
||||
act(() => {
|
||||
@@ -461,8 +473,10 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(1);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(2);
|
||||
expect(client.rawSend).toBeCalledWith('deinit', {plugin: 'TestPlugin'});
|
||||
(client.rawSend as jest.Mock).mockClear();
|
||||
expect((client as any).rawSend).toBeCalledWith('deinit', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
((client as any).rawSend as jest.Mock).mockClear();
|
||||
|
||||
// select something else
|
||||
act(() => {
|
||||
@@ -499,8 +513,10 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
expect(newPluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(newPluginInstance.activatedStub).toBeCalledTimes(0);
|
||||
expect(newPluginInstance.deactivatedStub).toBeCalledTimes(0);
|
||||
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
|
||||
(client.rawSend as jest.Mock).mockClear();
|
||||
expect((client as any).rawSend).toBeCalledWith('init', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
((client as any).rawSend as jest.Mock).mockClear();
|
||||
|
||||
// select new plugin
|
||||
act(() => {
|
||||
@@ -517,8 +533,8 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
expect(newPluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(newPluginInstance.activatedStub).toBeCalledTimes(1);
|
||||
expect(newPluginInstance.deactivatedStub).toBeCalledTimes(0);
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
(client.rawSend as jest.Mock).mockClear();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
((client as any).rawSend as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
test('PluginContainer + Sandy plugin supports deeplink', async () => {
|
||||
@@ -555,7 +571,9 @@ test('PluginContainer + Sandy plugin supports deeplink', async () => {
|
||||
definition,
|
||||
);
|
||||
|
||||
expect(client.rawSend).toBeCalledWith('init', {plugin: 'TestPlugin'});
|
||||
expect((client as any).rawSend).toBeCalledWith('init', {
|
||||
plugin: 'TestPlugin',
|
||||
});
|
||||
|
||||
expect(linksSeen).toEqual([]);
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
@@ -1242,7 +1260,7 @@ test('PluginContainer can render Sandy plugins for archived devices', async () =
|
||||
{archivedDevice: true},
|
||||
);
|
||||
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
<body>
|
||||
@@ -1296,7 +1314,7 @@ test('PluginContainer can render Sandy plugins for archived devices', async () =
|
||||
);
|
||||
});
|
||||
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
<body>
|
||||
@@ -1359,7 +1377,7 @@ test('PluginContainer can render Sandy plugins for archived devices', async () =
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(1);
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
});
|
||||
|
||||
test('PluginContainer triggers correct lifecycles for background plugin', async () => {
|
||||
@@ -1397,7 +1415,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
},
|
||||
});
|
||||
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
// make sure the plugin gets connected
|
||||
const pluginInstance: ReturnType<typeof plugin> =
|
||||
client.sandyPluginStates.get(definition.id)!.instanceApi;
|
||||
@@ -1418,7 +1436,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
);
|
||||
});
|
||||
// bg plugin!
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
expect(pluginInstance.connectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(1);
|
||||
@@ -1439,7 +1457,7 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(2);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(1);
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
|
||||
// select something else
|
||||
act(() => {
|
||||
@@ -1466,5 +1484,5 @@ test('PluginContainer triggers correct lifecycles for background plugin', async
|
||||
expect(pluginInstance.disconnectedStub).toBeCalledTimes(0);
|
||||
expect(pluginInstance.activatedStub).toBeCalledTimes(3);
|
||||
expect(pluginInstance.deactivatedStub).toBeCalledTimes(2);
|
||||
expect(client.rawSend).not.toBeCalled();
|
||||
expect((client as any).rawSend).not.toBeCalled();
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ import {createStore} from 'redux';
|
||||
import BaseDevice from '../../devices/BaseDevice';
|
||||
import {createRootReducer} from '../../reducers';
|
||||
import {Store} from '../../reducers/index';
|
||||
import Client, {ClientConnection} from '../../Client';
|
||||
import Client from '../../Client';
|
||||
import {
|
||||
Logger,
|
||||
buildClientId,
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import {PluginDefinition} from '../../plugin';
|
||||
import {pluginsInitialized, registerPlugins} from '../../reducers/plugins';
|
||||
import {getLogger} from 'flipper-common';
|
||||
import {ClientConnection} from 'flipper-frontend-core';
|
||||
import {initializeFlipperLibImplementation} from '../../utils/flipperLibImplementation';
|
||||
import pluginManager from '../../dispatcher/pluginManager';
|
||||
import {PluginDetails} from 'flipper-common';
|
||||
@@ -197,6 +198,8 @@ export default class MockFlipper {
|
||||
this._logger,
|
||||
this._store,
|
||||
new Set(supportedPlugins),
|
||||
// TODO: Remove after migration
|
||||
// @ts-expect-error
|
||||
device,
|
||||
this.flipperServer,
|
||||
);
|
||||
@@ -225,7 +228,7 @@ export default class MockFlipper {
|
||||
);
|
||||
}
|
||||
};
|
||||
client.rawSend = jest.fn();
|
||||
(client as any).rawSend = jest.fn();
|
||||
if (!device.isArchived) {
|
||||
await client.init();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user