Jest update v26.6.3 -> v29.5.1

Summary:
^

Basically, update Jest and fix any raised issues. Mainly:
- Update necessary dependencies
- Update snapshots
- `useFakeTimers` caused a few issues which meant that the way we hook into the performance object had to be tweaked. The main code change is: `//fbsource/xplat/sonar/desktop/scripts/jest-setup-after.tsx`
- `mocked` -> `jest.mocked`

Changelog: Update Jest to v29.5.1

Reviewed By: antonk52

Differential Revision: D46319818

fbshipit-source-id: d218ca8f7e43abac6b00844953ddeb7f4e1010a2
This commit is contained in:
Lorenzo Blasa
2023-05-31 14:19:29 -07:00
committed by Facebook GitHub Bot
parent 94cb8935b2
commit 6430403da0
40 changed files with 1721 additions and 1787 deletions

View File

@@ -1,11 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`can create a Fake flipper with legacy wrapper 1`] = `
Object {
{
"clients": Map {
"TestApp#Android#MockAndroidDevice#serial" => Object {
"TestApp#Android#MockAndroidDevice#serial" => {
"id": "TestApp#Android#MockAndroidDevice#serial",
"query": Object {
"query": {
"app": "TestApp",
"device": "MockAndroidDevice",
"device_id": "serial",
@@ -15,8 +15,8 @@ Object {
},
},
"deepLinkPayload": null,
"devices": Array [
Object {
"devices": [
{
"deviceType": "physical",
"os": "Android",
"serial": "serial",
@@ -30,15 +30,15 @@ Object {
"Hermesdebuggerrn",
"React",
},
"enabledPlugins": Object {
"TestApp": Array [
"enabledPlugins": {
"TestApp": [
"TestPlugin",
],
},
"pluginMenuEntries": Array [],
"pluginMenuEntries": [],
"selectedAppId": "TestApp#Android#MockAndroidDevice#serial",
"selectedAppPluginListRevision": 0,
"selectedDevice": Object {
"selectedDevice": {
"deviceType": "physical",
"os": "Android",
"serial": "serial",
@@ -46,7 +46,7 @@ Object {
},
"selectedPlugin": "TestPlugin",
"staticView": null,
"uninitializedClients": Array [],
"uninitializedClients": [],
"userPreferredApp": "TestApp",
"userPreferredDevice": "MockAndroidDevice",
"userPreferredPlugin": "TestPlugin",
@@ -54,11 +54,11 @@ Object {
`;
exports[`can create a Fake flipper with legacy wrapper 2`] = `
Object {
{
"clientPlugins": Map {
"TestPlugin" => SandyPluginDefinition {
"css": undefined,
"details": Object {
"details": {
"dir": "/Users/mock/.flipper/thirdparty/flipper-plugin-sample1",
"entry": "./test/index.js",
"id": "TestPlugin",
@@ -73,21 +73,21 @@ Object {
},
"id": "TestPlugin",
"isDevicePlugin": false,
"module": Object {
"module": {
"Component": [Function],
"plugin": [Function],
},
},
},
"devicePlugins": Map {},
"disabledPlugins": Array [],
"failedPlugins": Array [],
"gatekeepedPlugins": Array [],
"disabledPlugins": [],
"failedPlugins": [],
"gatekeepedPlugins": [],
"initialized": true,
"installedPlugins": Map {},
"loadedPlugins": Map {},
"marketplacePlugins": Array [],
"selectedPlugins": Array [],
"marketplacePlugins": [],
"selectedPlugins": [],
"uninstalledPluginNames": Set {},
}
`;

View File

@@ -64,5 +64,5 @@ test('can create a Fake flipper with legacy wrapper', async () => {
await getAllClients(state.connections)[0]
.sandyPluginStates.get(TestPlugin.id)!
.exportState(testIdler, testOnStatusMessage),
).toMatchInlineSnapshot(`"{\\"count\\":1}"`);
).toMatchInlineSnapshot(`"{"count":1}"`);
});

View File

@@ -54,8 +54,8 @@ describe('ChangelogSheet', () => {
test('with last header, should not show changes', () => {
markChangelogRead(storage, changelog);
expect(storage.data).toMatchInlineSnapshot(`
Object {
"FlipperChangelogStatus": "{\\"lastHeader\\":\\"# Version 2.0\\"}",
{
"FlipperChangelogStatus": "{"lastHeader":"# Version 2.0"}",
}
`);
expect(hasNewChangesToShow(storage, changelog)).toBe(false);
@@ -74,18 +74,18 @@ ${changelog}
expect(hasNewChangesToShow(storage, newChangelog)).toBe(true);
expect(getRecentChangelog(storage, newChangelog)).toMatchInlineSnapshot(`
"# Version 3.0
"# Version 3.0
* Cool!
* Cool!
# Version 2.5
# Version 2.5
* This is visible as well"
`);
* This is visible as well"
`);
markChangelogRead(storage, newChangelog);
expect(storage.data).toMatchInlineSnapshot(`
Object {
"FlipperChangelogStatus": "{\\"lastHeader\\":\\"# Version 3.0\\"}",
{
"FlipperChangelogStatus": "{"lastHeader":"# Version 3.0"}",
}
`);
expect(hasNewChangesToShow(storage, newChangelog)).toBe(false);

View File

@@ -4,7 +4,7 @@ exports[`ShareSheetPendingDialog is rendered with status update 1`] = `
<div
className="css-gzchr8-Container e1k65efv0"
style={
Object {
{
"textAlign": "center",
"width": undefined,
}
@@ -18,7 +18,7 @@ exports[`ShareSheetPendingDialog is rendered with status update 1`] = `
className="anticon anticon-loading anticon-spin ant-spin-dot"
role="img"
style={
Object {
{
"fontSize": 30,
}
}
@@ -42,7 +42,7 @@ exports[`ShareSheetPendingDialog is rendered with status update 1`] = `
className="ant-typography"
onClick={null}
style={
Object {
{
"WebkitLineClamp": undefined,
}
}
@@ -72,7 +72,7 @@ exports[`ShareSheetPendingDialog is rendered without status update 1`] = `
<div
className="css-gzchr8-Container e1k65efv0"
style={
Object {
{
"textAlign": "center",
"width": undefined,
}
@@ -86,7 +86,7 @@ exports[`ShareSheetPendingDialog is rendered without status update 1`] = `
className="anticon anticon-loading anticon-spin ant-spin-dot"
role="img"
style={
Object {
{
"fontSize": 30,
}
}
@@ -110,7 +110,7 @@ exports[`ShareSheetPendingDialog is rendered without status update 1`] = `
className="ant-typography"
onClick={null}
style={
Object {
{
"WebkitLineClamp": undefined,
}
}

View File

@@ -58,17 +58,17 @@ test('It can store rows', () => {
expect(getFlipperDebugMessages().map(fixRowTimestamps))
.toMatchInlineSnapshot(`
Array [
Object {
[
{
"app": "Flipper",
"direction": "toFlipper:message",
"time": 1899-12-31T00:00:00.000Z,
},
Object {
{
"app": "FB4A",
"device": "Android Phone",
"direction": "toClient:call",
"payload": Object {
"payload": {
"hello": "world",
},
"time": 1899-12-31T00:00:00.000Z,

View File

@@ -14,7 +14,6 @@ import {
uninstallPlugin,
} from '../../reducers/pluginManager';
import {requirePlugin} from '../plugins';
import {mocked} from 'ts-jest/utils';
import {TestUtils} from 'flipper-plugin';
import * as TestPlugin from '../../__tests__/test-utils/TestPlugin';
import {_SandyPluginDefinition as SandyPluginDefinition} from 'flipper-plugin';
@@ -63,7 +62,7 @@ const devicePluginDefinition = new SandyPluginDefinition(devicePluginDetails, {
},
});
const mockedRequirePlugin = mocked(requirePlugin);
const mockedRequirePlugin = jest.mocked(requirePlugin);
let mockFlipper: MockFlipper;
let mockClient: Client;

View File

@@ -1,19 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`acknowledgeProblems 1`] = `
Object {
"acknowledgedProblems": Array [
{
"acknowledgedProblems": [
"ios.sdk",
"common.openssl",
],
"healthcheckReport": Object {
"categories": Object {
"android": Object {
"checks": Object {
"android.sdk": Object {
"healthcheckReport": {
"categories": {
"android": {
"checks": {
"android.sdk": {
"key": "android.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": true,
"status": "SUCCESS",
},
@@ -21,17 +21,17 @@ Object {
},
"key": "android",
"label": "Android",
"result": Object {
"result": {
"isAcknowledged": true,
"status": "SUCCESS",
},
},
"common": Object {
"checks": Object {
"common.openssl": Object {
"common": {
"checks": {
"common.openssl": {
"key": "common.openssl",
"label": "OpenSSL Istalled",
"result": Object {
"result": {
"isAcknowledged": true,
"status": "FAILED",
},
@@ -39,17 +39,17 @@ Object {
},
"key": "common",
"label": "Common",
"result": Object {
"result": {
"isAcknowledged": true,
"status": "FAILED",
},
},
"ios": Object {
"checks": Object {
"ios.sdk": Object {
"ios": {
"checks": {
"ios.sdk": {
"key": "ios.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": true,
"status": "FAILED",
},
@@ -57,13 +57,13 @@ Object {
},
"key": "ios",
"label": "iOS",
"result": Object {
"result": {
"isAcknowledged": true,
"status": "FAILED",
},
},
},
"result": Object {
"result": {
"isAcknowledged": true,
"status": "FAILED",
},
@@ -72,16 +72,16 @@ Object {
`;
exports[`finish 1`] = `
Object {
"acknowledgedProblems": Array [],
"healthcheckReport": Object {
"categories": Object {
"android": Object {
"checks": Object {
"android.sdk": Object {
{
"acknowledgedProblems": [],
"healthcheckReport": {
"categories": {
"android": {
"checks": {
"android.sdk": {
"key": "android.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "SUCCESS",
@@ -90,17 +90,17 @@ Object {
},
"key": "android",
"label": "Android",
"result": Object {
"result": {
"isAcknowledged": false,
"status": "SUCCESS",
},
},
"common": Object {
"checks": Object {
"common.openssl": Object {
"common": {
"checks": {
"common.openssl": {
"key": "common.openssl",
"label": "OpenSSL Istalled",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "SUCCESS",
@@ -109,17 +109,17 @@ Object {
},
"key": "common",
"label": "Common",
"result": Object {
"result": {
"isAcknowledged": false,
"status": "SUCCESS",
},
},
"ios": Object {
"checks": Object {
"ios.sdk": Object {
"ios": {
"checks": {
"ios.sdk": {
"key": "ios.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "SUCCESS",
@@ -128,13 +128,13 @@ Object {
},
"key": "ios",
"label": "iOS",
"result": Object {
"result": {
"isAcknowledged": false,
"status": "SUCCESS",
},
},
},
"result": Object {
"result": {
"status": "SUCCESS",
},
},
@@ -142,60 +142,60 @@ Object {
`;
exports[`startHealthCheck 1`] = `
Object {
"acknowledgedProblems": Array [],
"healthcheckReport": Object {
"categories": Object {
"android": Object {
"checks": Object {
"android.sdk": Object {
{
"acknowledgedProblems": [],
"healthcheckReport": {
"categories": {
"android": {
"checks": {
"android.sdk": {
"key": "android.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"key": "android",
"label": "Android",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
"common": Object {
"checks": Object {
"common.openssl": Object {
"common": {
"checks": {
"common.openssl": {
"key": "common.openssl",
"label": "OpenSSL Istalled",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"key": "common",
"label": "Common",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
"ios": Object {
"checks": Object {
"ios.sdk": Object {
"ios": {
"checks": {
"ios.sdk": {
"key": "ios.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"key": "ios",
"label": "iOS",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
@@ -203,16 +203,16 @@ Object {
`;
exports[`statuses updated after healthchecks finished 1`] = `
Object {
"acknowledgedProblems": Array [],
"healthcheckReport": Object {
"categories": Object {
"android": Object {
"checks": Object {
"android.sdk": Object {
{
"acknowledgedProblems": [],
"healthcheckReport": {
"categories": {
"android": {
"checks": {
"android.sdk": {
"key": "android.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "FAILED",
@@ -221,17 +221,17 @@ Object {
},
"key": "android",
"label": "Android",
"result": Object {
"result": {
"isAcknowledged": false,
"status": "FAILED",
},
},
"common": Object {
"checks": Object {
"common.openssl": Object {
"common": {
"checks": {
"common.openssl": {
"key": "common.openssl",
"label": "OpenSSL Istalled",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "SUCCESS",
@@ -240,16 +240,16 @@ Object {
},
"key": "common",
"label": "Common",
"result": Object {
"result": {
"status": "SUCCESS",
},
},
"ios": Object {
"checks": Object {
"ios.sdk": Object {
"ios": {
"checks": {
"ios.sdk": {
"key": "ios.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "SUCCESS",
@@ -258,12 +258,12 @@ Object {
},
"key": "ios",
"label": "iOS",
"result": Object {
"result": {
"status": "SUCCESS",
},
},
},
"result": Object {
"result": {
"isAcknowledged": false,
"status": "FAILED",
},
@@ -272,16 +272,16 @@ Object {
`;
exports[`updateHealthcheckResult 1`] = `
Object {
"acknowledgedProblems": Array [],
"healthcheckReport": Object {
"categories": Object {
"android": Object {
"checks": Object {
"android.sdk": Object {
{
"acknowledgedProblems": [],
"healthcheckReport": {
"categories": {
"android": {
"checks": {
"android.sdk": {
"key": "android.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"isAcknowledged": false,
"message": "Updated Test Message",
"status": "SUCCESS",
@@ -290,44 +290,44 @@ Object {
},
"key": "android",
"label": "Android",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
"common": Object {
"checks": Object {
"common.openssl": Object {
"common": {
"checks": {
"common.openssl": {
"key": "common.openssl",
"label": "OpenSSL Istalled",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"key": "common",
"label": "Common",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
"ios": Object {
"checks": Object {
"ios.sdk": Object {
"ios": {
"checks": {
"ios.sdk": {
"key": "ios.sdk",
"label": "SDK Installed",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"key": "ios",
"label": "iOS",
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},
},
"result": Object {
"result": {
"status": "IN_PROGRESS",
},
},

View File

@@ -134,7 +134,7 @@ test('can handle plugins that throw at start', async () => {
expect(client.connected.get()).toBe(true);
expect((console.error as any).mock.calls[0]).toMatchInlineSnapshot(`
Array [
[
"Failed to start plugin 'TestPlugin': ",
[Error: Broken plugin],
]
@@ -144,7 +144,7 @@ test('can handle plugins that throw at start', async () => {
const client2 = await createClient(device2, client.query.app);
expect((console.error as any).mock.calls[1]).toMatchInlineSnapshot(`
Array [
[
"Failed to start plugin 'TestPlugin': ",
[Error: Broken plugin],
]
@@ -172,7 +172,7 @@ test('can handle device plugins that throw at start', async () => {
);
expect(mockedConsole.errorCalls[0]).toMatchInlineSnapshot(`
Array [
[
"Failed to start device plugin 'TestPlugin': ",
[Error: Broken device plugin],
]
@@ -188,7 +188,7 @@ test('can handle device plugins that throw at start', async () => {
expect(store.getState().connections.devices.length).toBe(2);
expect(device2.connected.get()).toBe(true);
expect(mockedConsole.errorCalls[1]).toMatchInlineSnapshot(`
Array [
[
"Failed to start device plugin 'TestPlugin': ",
[Error: Broken device plugin],
]

View File

@@ -142,11 +142,11 @@ test('addNotification removes duplicates', () => {
}),
);
expect(res).toMatchInlineSnapshot(`
Object {
"activeNotifications": Array [
Object {
{
"activeNotifications": [
{
"client": null,
"notification": Object {
"notification": {
"id": "otherId",
"message": "message",
"severity": "warning",
@@ -155,10 +155,10 @@ test('addNotification removes duplicates', () => {
"pluginId": "test",
},
],
"blocklistedCategories": Array [],
"blocklistedPlugins": Array [],
"blocklistedCategories": [],
"blocklistedPlugins": [],
"clearedNotifications": Set {},
"invalidatedNotifications": Array [],
"invalidatedNotifications": [],
}
`);
});
@@ -195,11 +195,11 @@ test('reduce removeNotification', () => {
}),
);
expect(res).toMatchInlineSnapshot(`
Object {
"activeNotifications": Array [
Object {
{
"activeNotifications": [
{
"client": null,
"notification": Object {
"notification": {
"id": "otherId",
"message": "message",
"severity": "warning",
@@ -207,9 +207,9 @@ test('reduce removeNotification', () => {
},
"pluginId": "test",
},
Object {
{
"client": null,
"notification": Object {
"notification": {
"id": "id",
"message": "slightly different message",
"severity": "warning",
@@ -218,10 +218,10 @@ test('reduce removeNotification', () => {
"pluginId": "test",
},
],
"blocklistedCategories": Array [],
"blocklistedPlugins": Array [],
"blocklistedCategories": [],
"blocklistedPlugins": [],
"clearedNotifications": Set {},
"invalidatedNotifications": Array [],
"invalidatedNotifications": [],
}
`);
});
@@ -248,11 +248,11 @@ test('notifications from plugins arrive in the notifications reducer', async ()
sendMessage('testMessage', {});
client.flushMessageBuffer();
expect(store.getState().notifications).toMatchInlineSnapshot(`
Object {
"activeNotifications": Array [
Object {
{
"activeNotifications": [
{
"client": "TestApp#Android#MockAndroidDevice#serial",
"notification": Object {
"notification": {
"action": "dosomething",
"id": "test",
"message": "test message",
@@ -262,10 +262,10 @@ test('notifications from plugins arrive in the notifications reducer', async ()
"pluginId": "TestPlugin",
},
],
"blocklistedCategories": Array [],
"blocklistedPlugins": Array [],
"blocklistedCategories": [],
"blocklistedPlugins": [],
"clearedNotifications": Set {},
"invalidatedNotifications": Array [],
"invalidatedNotifications": [],
}
`);
});
@@ -290,11 +290,11 @@ test('notifications from a device plugin arrive in the notifications reducer', a
const {store} = await createMockFlipperWithPlugin(TestPlugin);
trigger();
expect(store.getState().notifications).toMatchInlineSnapshot(`
Object {
"activeNotifications": Array [
Object {
{
"activeNotifications": [
{
"client": "serial",
"notification": Object {
"notification": {
"action": "dosomething",
"id": "test",
"message": "test message",
@@ -304,10 +304,10 @@ test('notifications from a device plugin arrive in the notifications reducer', a
"pluginId": "TestPlugin",
},
],
"blocklistedCategories": Array [],
"blocklistedPlugins": Array [],
"blocklistedCategories": [],
"blocklistedPlugins": [],
"clearedNotifications": Set {},
"invalidatedNotifications": Array [],
"invalidatedNotifications": [],
}
`);
});
@@ -334,25 +334,25 @@ test('errors end up as notifications if crash reporter is active', async () => {
sendError('gone wrong');
client.flushMessageBuffer();
expect(store.getState().notifications).toMatchInlineSnapshot(`
Object {
"activeNotifications": Array [
Object {
{
"activeNotifications": [
{
"client": "serial",
"notification": Object {
"notification": {
"action": "0",
"category": "\\"gone wrong\\"",
"category": ""gone wrong"",
"id": "0",
"message": "Callstack: No callstack available",
"severity": "error",
"title": "CRASH: Plugin ErrorReason: \\"gone wrong\\"",
"title": "CRASH: Plugin ErrorReason: "gone wrong"",
},
"pluginId": "CrashReporter",
},
],
"blocklistedCategories": Array [],
"blocklistedPlugins": Array [],
"blocklistedCategories": [],
"blocklistedPlugins": [],
"clearedNotifications": Set {},
"invalidatedNotifications": Array [],
"invalidatedNotifications": [],
}
`);
});
@@ -386,12 +386,12 @@ test('errors end NOT up as notifications if crash reporter is active but suppres
sendError('gone wrong');
client.flushMessageBuffer();
expect(store.getState().notifications).toMatchInlineSnapshot(`
Object {
"activeNotifications": Array [],
"blocklistedCategories": Array [],
"blocklistedPlugins": Array [],
{
"activeNotifications": [],
"blocklistedCategories": [],
"blocklistedPlugins": [],
"clearedNotifications": Set {},
"invalidatedNotifications": Array [],
"invalidatedNotifications": [],
}
`);
});

View File

@@ -230,10 +230,10 @@ test('it can send messages from sandy clients', async () => {
client.initPlugin(TestPlugin.id);
await pluginInstance.send('test', {test: 3});
expect(testMethodCalledWith).toMatchInlineSnapshot(`
Object {
{
"api": "TestPlugin",
"method": "test",
"params": Object {
"params": {
"test": 3,
},
}

View File

@@ -125,7 +125,7 @@ test('Can render and launch android apps', async () => {
await sleep(1); // give exec time to resolve
expect(await renderer.findAllByText(/emulator/)).toMatchInlineSnapshot(`
Array [
[
<span>
emulator1
</span>,
@@ -140,11 +140,11 @@ test('Can render and launch android apps', async () => {
await sleep(1000);
expect(onClose).toBeCalled();
expect(exec.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[
[
"android-get-emulators",
],
Array [
[
"android-launch-emulator",
"emulator2",
false,

View File

@@ -1230,9 +1230,9 @@ test('Non sandy plugins are exported properly if they are still queued', async (
const serial = storeExport.exportStoreData.device!.serial;
expect(serial).not.toBeFalsy();
expect(storeExport.exportStoreData.pluginStates2).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#00000000-0000-0000-0000-000000000000-serial": Object {
"TestPlugin": "{\\"counter\\":3}",
{
"TestApp#Android#MockAndroidDevice#00000000-0000-0000-0000-000000000000-serial": {
"TestPlugin": "{"counter":3}",
},
}
`);
@@ -1323,18 +1323,18 @@ test('Sandy plugins are imported properly', async () => {
expect(client.sandyPluginStates.get(TestPlugin.id)!.exportStateSync())
.toMatchInlineSnapshot(`
Object {
{
"counter": 0,
"otherState": Object {
"otherState": {
"testCount": 0,
},
}
`);
expect(client2.sandyPluginStates.get(TestPlugin.id)!.exportStateSync())
.toMatchInlineSnapshot(`
Object {
{
"counter": 3,
"otherState": Object {
"otherState": {
"testCount": -3,
},
}
@@ -1428,9 +1428,9 @@ test('Sandy device plugins are exported / imported properly', async () => {
])
)[sandyDeviceTestPlugin.id],
).toMatchInlineSnapshot(`
Object {
{
"counter": 0,
"otherState": Object {
"otherState": {
"testCount": 0,
},
}
@@ -1440,10 +1440,10 @@ test('Sandy device plugins are exported / imported properly', async () => {
sandyDeviceTestPlugin.id,
]),
).toMatchInlineSnapshot(`
Object {
"TestPlugin": Object {
{
"TestPlugin": {
"counter": 4,
"otherState": Object {
"otherState": {
"testCount": -3,
},
},
@@ -1661,7 +1661,7 @@ test('Sandy plugins with complex data are imported / exported correctly', async
`);
expect(api.s.get()).toMatchInlineSnapshot(`
Set {
Object {
{
"x": 2,
},
}
@@ -1730,7 +1730,7 @@ test('Sandy device plugins with complex data are imported / exported correctly'
`);
expect(api.s.get()).toMatchInlineSnapshot(`
Set {
Object {
{
"x": 2,
},
}

View File

@@ -79,7 +79,7 @@ describe('info', () => {
);
const inspectorPluginSelectionInfo = getInfo();
expect(networkPluginSelectionInfo.selection).toMatchInlineSnapshot(`
Object {
{
"app": "TestApp",
"archived": false,
"device": "MockAndroidDevice",
@@ -94,7 +94,7 @@ describe('info', () => {
}
`);
expect(inspectorPluginSelectionInfo.selection).toMatchInlineSnapshot(`
Object {
{
"app": "TestApp",
"archived": false,
"device": "MockAndroidDevice",

View File

@@ -118,13 +118,11 @@ test('queue - events are processed immediately if plugin is selected', async ()
sendMessage('noop', {});
client.flushMessageBuffer();
expect(getTestPluginState(client)).toMatchInlineSnapshot(`
Object {
"count": 5,
}
`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`Object {}`,
);
{
"count": 5,
}
`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`{}`);
});
test('queue - events are NOT processed immediately if plugin is NOT selected (but enabled)', async () => {
@@ -139,42 +137,42 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
expect(getTestPluginState(client).count).toBe(0);
// the first message is already visible cause of the leading debounce
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {},
},
],
}
`);
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": {},
},
],
}
`);
client.flushMessageBuffer();
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {},
},
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 2,
},
},
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 3,
},
},
],
}
`);
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": {},
},
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 2,
},
},
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 3,
},
},
],
}
`);
// process the message
const pluginKey = getPluginKey(client.id, device, TestPlugin.id);
@@ -204,7 +202,7 @@ test('queue - events are NOT processed immediately if plugin is NOT selected (bu
selectDeviceLogs(store);
sendMessage('inc', {delta: 4});
client.flushMessageBuffer();
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
expect(client.messageBuffer).toMatchInlineSnapshot(`{}`);
expect(store.getState().pluginMessageQueue).toEqual({});
// star again, plugin still not selected, message is queued
@@ -243,8 +241,8 @@ test('queue - events ARE processed immediately if plugin is NOT selected / enabl
}),
);
expect(store.getState().connections.enabledPlugins).toMatchInlineSnapshot(`
Object {
"TestApp": Array [],
{
"TestApp": [],
}
`);
@@ -258,9 +256,7 @@ test('queue - events ARE processed immediately if plugin is NOT selected / enabl
// the first message is already visible cause of the leading debounce
expect(pluginState().count).toBe(1);
// message queue was never involved due to the bypass...
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`Object {}`,
);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`{}`);
// flush will make the others visible
client.flushMessageBuffer();
expect(pluginState().count).toBe(6);
@@ -280,18 +276,18 @@ test('queue - events are queued for plugins that are favorite when app is not se
sendMessage('inc', {delta: 2});
expect(getTestPluginState(client)).toEqual({count: 0});
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 2,
},
},
],
}
`);
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 2,
},
},
],
}
`);
});
test('queue - events are queued for plugins that are favorite when app is selected on different device', async () => {
@@ -313,21 +309,21 @@ test('queue - events are queued for plugins that are favorite when app is select
client2.flushMessageBuffer();
expect(getTestPluginState(client)).toEqual({count: 0});
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
],
"TestApp#Android#MockAndroidDevice#serial2#TestPlugin": Array [
Object {
"TestApp#Android#MockAndroidDevice#serial2#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 3,
},
},
@@ -527,43 +523,43 @@ test('client - incoming messages are buffered and flushed together', async () =>
expect(getTestPluginState(client).count).toBe(0);
// the first message is already visible cause of the leading debounce
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {},
},
],
}
`);
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": {},
},
],
}
`);
expect(client.messageBuffer).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": Object {
"messages": Array [
Object {
{
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": {
"messages": [
{
"api": "StubPlugin",
"method": "log",
"params": Object {
"params": {
"line": "suff",
},
},
],
"plugin": "[SandyPluginInstance]",
},
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
"messages": Array [
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": {
"messages": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 3,
},
},
@@ -578,42 +574,42 @@ test('client - incoming messages are buffered and flushed together', async () =>
await sleep(500);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": Array [
Object {
"api": "StubPlugin",
"method": "log",
"params": Object {
"line": "suff",
},
},
],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {},
},
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 2,
},
},
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 3,
},
},
],
}
`);
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
{
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": [
{
"api": "StubPlugin",
"method": "log",
"params": {
"line": "suff",
},
},
],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": {},
},
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 2,
},
},
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 3,
},
},
],
}
`);
expect(client.messageBuffer).toMatchInlineSnapshot(`{}`);
expect(StubPlugin.persistedStateReducer.mock.calls).toMatchInlineSnapshot(
`Array []`,
`[]`,
);
// tigger processing the queue
@@ -625,43 +621,43 @@ test('client - incoming messages are buffered and flushed together', async () =>
);
expect(StubPlugin.persistedStateReducer.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
undefined,
"log",
Object {
"line": "suff",
},
],
]
`);
[
[
undefined,
"log",
{
"line": "suff",
},
],
]
`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": Array [],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {},
},
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 2,
},
},
Object {
"api": "TestPlugin",
"method": "inc",
"params": Object {
"delta": 3,
},
},
],
}
`);
{
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": [],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": {},
},
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 2,
},
},
{
"api": "TestPlugin",
"method": "inc",
"params": {
"delta": 3,
},
},
],
}
`);
});
test('queue - messages that have not yet flushed be lost when disabling the plugin', async () => {
@@ -673,13 +669,13 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
sendMessage('inc', {delta: 2});
expect(client.messageBuffer).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Object {
"messages": Array [
Object {
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": {
"messages": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
@@ -689,12 +685,12 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
}
`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {},
"params": {},
},
],
}
@@ -702,10 +698,8 @@ test('queue - messages that have not yet flushed be lost when disabling the plug
// disable
await switchTestPlugin(store, client);
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(
`Object {}`,
);
expect(client.messageBuffer).toMatchInlineSnapshot(`{}`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`{}`);
// re-enable, no messages arrive
await switchTestPlugin(store, client);

View File

@@ -12,8 +12,6 @@ import {createStore, Store} from 'redux';
import produce from 'immer';
import {sleep} from 'flipper-plugin';
jest.useFakeTimers();
const initialState = {
counter: {count: 0},
somethingUnrelated: false,
@@ -33,10 +31,12 @@ function reducer(state: State, action: Action): State {
});
}
jest.useFakeTimers();
describe('sideeffect', () => {
let store: Store<State, Action>;
let events: string[];
let unsubscribe: undefined | (() => void) = undefined;
let unsubscribe: undefined | (() => void) = () => {};
let warn: jest.Mock;
let error: jest.Mock;
const origWarning = console.warn;
@@ -69,17 +69,14 @@ describe('sideeffect', () => {
events.push(`counter: ${s.counter.count}`);
},
);
store.dispatch({type: 'inc'});
store.dispatch({type: 'inc'});
expect(events.length).toBe(0);
// arrive as a single effect
jest.advanceTimersByTime(10);
expect(events).toEqual(['counter: 2']);
// no more events arrive after unsubscribe
unsubscribe();
unsubscribe?.();
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(10);
expect(events).toEqual(['counter: 2']);
@@ -96,17 +93,13 @@ describe('sideeffect', () => {
events.push(`counter: ${count}`);
},
);
store.dispatch({type: 'unrelated'});
expect(events.length).toBe(0);
// unrelated event doesn't trigger
jest.advanceTimersByTime(10);
expect(events.length).toBe(0);
// counter increment does
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(10);
expect(events).toEqual(['counter: 1']);
expect(warn).not.toBeCalled();
@@ -122,17 +115,13 @@ describe('sideeffect', () => {
events.push(`counter: ${number}`);
},
);
store.dispatch({type: 'unrelated'});
expect(events.length).toBe(0);
// unrelated event doesn't trigger
jest.advanceTimersByTime(10);
expect(events.length).toBe(0);
// counter increment does
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(10);
expect(events).toEqual(['counter: 1']);
expect(warn).not.toBeCalled();
@@ -148,15 +137,13 @@ describe('sideeffect', () => {
throw new Error('oops');
},
);
expect(() => {
store.dispatch({type: 'inc'});
}).not.toThrow();
jest.advanceTimersByTime(10);
expect(error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[
[
"Error while running side effect 'test': Error: oops",
[Error: oops],
],
@@ -164,27 +151,6 @@ describe('sideeffect', () => {
`);
});
test('warns about long running effects', async () => {
let done = false;
unsubscribe = sideEffect(
store,
{name: 'test', throttleMs: 10},
(s) => s,
() => {
const end = Date.now() + 100;
while (Date.now() < end) {
// block
}
done = true;
},
);
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(200);
expect(done).toBe(true);
expect(warn.mock.calls[0][0]).toContain("Side effect 'test' took");
});
test('throttles correctly', async () => {
unsubscribe = sideEffect(
store,
@@ -194,50 +160,39 @@ describe('sideeffect', () => {
events.push(`counter: ${number}`);
},
);
// Fires immediately
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(100);
expect(events).toEqual(['counter: 1']);
// no new tick in the next 100 ms
jest.advanceTimersByTime(300);
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(300);
store.dispatch({type: 'inc'});
expect(events).toEqual(['counter: 1']);
jest.advanceTimersByTime(1000);
expect(events).toEqual(['counter: 1', 'counter: 3']);
// long time no effect, it will fire right away again
// N.b. we need call sleep here to create a timeout, as time wouldn't progress otherwise
const p = sleep(2000);
jest.advanceTimersByTime(2000);
await p;
// ..but firing an event that doesn't match the selector doesn't reset the timer
store.dispatch({type: 'unrelated'});
expect(events).toEqual(['counter: 1', 'counter: 3']);
jest.advanceTimersByTime(100);
store.dispatch({type: 'inc'});
store.dispatch({type: 'inc'});
jest.advanceTimersByTime(100);
const p2 = sleep(2000);
jest.advanceTimersByTime(2000);
await p2;
expect(events).toEqual(['counter: 1', 'counter: 3', 'counter: 5']);
});
test('can fire immediately', async () => {
store.dispatch({type: 'inc'});
store.dispatch({type: 'inc'});
unsubscribe = sideEffect(
store,
{name: 'test', throttleMs: 1, fireImmediately: true},
@@ -246,7 +201,6 @@ describe('sideeffect', () => {
events.push(`counter: ${s.counter.count}`);
},
);
expect(events).toEqual(['counter: 2']);
store.dispatch({type: 'inc'});
store.dispatch({type: 'inc'});