Update tests to use the sandyLegacy wrapper by default

Summary: Changed unit test infra to wrap legacy plugins by default in Sandy, and adapted tests where needed.

Reviewed By: nikoant

Differential Revision: D29264660

fbshipit-source-id: fe7cbc8af826afac5f945103586b3cb9647e7fbd
This commit is contained in:
Michel Weststrate
2021-06-21 08:35:52 -07:00
committed by Facebook GitHub Bot
parent 00e2c803ef
commit 640e06f130
13 changed files with 309 additions and 71 deletions

View File

@@ -1208,24 +1208,16 @@ test('Non sandy plugins are exported properly if they are still queued', async (
sendMessage('inc', {});
sendMessage('inc', {});
// not flushed
expect(store.getState().pluginStates).toMatchInlineSnapshot(`Object {}`);
// store export will cause flush
const storeExport = await exportStore(store);
// flushed
expect(store.getState().pluginStates).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
"counter": 3,
},
}
`);
const serial = storeExport.exportStoreData.device!.serial;
expect(serial).not.toBeFalsy();
expect(storeExport.exportStoreData.store.pluginStates).toMatchInlineSnapshot(`
expect(storeExport.exportStoreData.pluginStates2).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#${serial}#TestPlugin": "{\\"counter\\":3}",
"TestApp#Android#MockAndroidDevice#00000000-0000-0000-0000-000000000000-serial": Object {
"TestPlugin": "{\\"counter\\":3}",
},
}
`);
});

View File

@@ -88,6 +88,9 @@ function selectTestPlugin(store: Store, client: Client) {
test('queue - events are processed immediately if plugin is selected', async () => {
const {store, client, sendMessage} = await createMockFlipperWithPlugin(
TestPlugin,
{
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
},
);
expect(store.getState().connections.selectedPlugin).toBe('TestPlugin');
sendMessage('noop', {});
@@ -110,7 +113,9 @@ test('queue - events are processed immediately if plugin is selected', async ()
test('queue - events are NOT processed immediately if plugin is NOT selected (but enabled)', async () => {
const {store, client, sendMessage, device} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
expect(store.getState().connections.selectedPlugin).not.toBe('TestPlugin');
@@ -200,7 +205,9 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
test('queue - events are queued for plugins that are favorite when app is not selected', async () => {
const {device, store, sendMessage, createClient} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
expect(store.getState().connections.selectedPlugin).not.toBe('TestPlugin');
@@ -228,7 +235,9 @@ test('queue - events are queued for plugins that are favorite when app is not se
test('queue - events are queued for plugins that are favorite when app is selected on different device', async () => {
const {client, store, sendMessage, createDevice, createClient} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
expect(store.getState().connections.selectedPlugin).not.toBe('TestPlugin');
@@ -270,7 +279,9 @@ test('queue - events are queued for plugins that are favorite when app is select
test('queue - events processing will be paused', async () => {
const {client, device, store, sendMessage} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
sendMessage('inc', {});
@@ -314,7 +325,9 @@ test('queue - events processing will be paused', async () => {
test('queue - messages that arrive during processing will be queued', async () => {
const {client, device, store, sendMessage} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
sendMessage('inc', {});
@@ -360,7 +373,9 @@ test('queue - messages that arrive during processing will be queued', async () =
test('queue - processing can be cancelled', async () => {
const {client, device, store, sendMessage} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
sendMessage('inc', {});
@@ -391,7 +406,9 @@ test('queue - processing can be cancelled', async () => {
test('queue - make sure resetting plugin state clears the message queue', async () => {
const {client, device, store, sendMessage} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
sendMessage('inc', {});
@@ -458,7 +475,9 @@ test('client - incoming messages are buffered and flushed together', async () =>
}
const {client, store, device, sendMessage} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
store.dispatch(registerPlugins([StubDeviceLogs]));
@@ -614,7 +633,9 @@ test('client - incoming messages are buffered and flushed together', async () =>
test('queue - messages that have not yet flushed be lost when disabling the plugin', async () => {
const {client, store, sendMessage, pluginKey} =
await createMockFlipperWithPlugin(TestPlugin);
await createMockFlipperWithPlugin(TestPlugin, {
disableLegacyWrapper: true, // Sandy is already tested in messageQueueSandy.node.tsx
});
selectDeviceLogs(store);
sendMessage('inc', {});

View File

@@ -99,10 +99,10 @@ test('getActivePersistentPlugins, where the non persistent plugins getting exclu
id: 'ClientPlugin4',
label: 'ClientPlugin4',
},
{
id: 'ClientPlugin5',
label: 'ClientPlugin5',
},
// { Never activated, and no data received
// id: 'ClientPlugin5',
// label: 'ClientPlugin5',
// },
]);
});
@@ -140,5 +140,11 @@ test('getActivePersistentPlugins, where the plugins not in pluginState or queue
id: 'ClientPlugin3', // queued
label: 'ClientPlugin3',
},
{
// in Sandy wrapper, a plugin is either persistable or not, but it doesn't depend on the current state.
// So this plugin will show up, even though its state is still the default
id: 'Plugin1',
label: 'Plugin1',
},
]);
});

View File

@@ -37,11 +37,13 @@ export function createSandyPluginWrapper<S, A extends BaseAction, P>(
Plugin: typeof FlipperPlugin | typeof FlipperDevicePlugin,
): SandyPluginModule {
const isDevicePlugin = Plugin.prototype instanceof FlipperDevicePlugin;
console.warn(
`Loading ${isDevicePlugin ? 'device' : 'client'} plugin ${
Plugin.id
} in legacy mode. Please visit https://fbflipper.com/docs/extending/sandy-migration to learn how to migrate this plugin to the new Sandy architecture`,
);
if (process.env.NODE_ENV !== 'test') {
console.warn(
`Loading ${isDevicePlugin ? 'device' : 'client'} plugin ${
Plugin.id
} in legacy mode. Please visit https://fbflipper.com/docs/extending/sandy-migration to learn how to migrate this plugin to the new Sandy architecture`,
);
}
function legacyPluginWrapper(client: PluginClient | DevicePluginClient) {
const store = getStore();

View File

@@ -7,7 +7,10 @@
* @format
*/
import {DownloadablePluginDetails} from 'flipper-plugin-lib';
import {
ActivatablePluginDetails,
DownloadablePluginDetails,
} from 'flipper-plugin-lib';
export function createMockDownloadablePluginDetails(
params: {
@@ -58,3 +61,23 @@ export function createMockDownloadablePluginDetails(
};
return details;
}
export function createMockActivatablePluginDetails(
base: Partial<ActivatablePluginDetails>,
): ActivatablePluginDetails {
return {
id: 'Hello',
specVersion: 2,
isBundled: false,
isActivatable: true,
dir: '/Users/mock/.flipper/thirdparty/flipper-plugin-sample1',
entry: './test/index.js',
name: 'flipper-plugin-hello',
version: '0.1.0',
pluginType: 'client',
source: 'src/index.js',
main: 'dist/bundle.js',
title: 'Hello',
...base,
};
}