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

@@ -50,8 +50,8 @@ test('test shared data structure', () => {
expect(res.x).not.toBe(res.y);
// @ts-ignore
expect(console.warn.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[
[
"Duplicate value, object lives at path '.y', but also at path '.x': '[object Object]'. This might not behave correct after import and lead to unnecessary big exports.",
],
]
@@ -231,7 +231,7 @@ test.unix(
() => {
const date = new Date(2021, 1, 29, 10, 31, 7, 205);
expect(makeShallowSerializable(date)).toMatchInlineSnapshot(`
Object {
{
"__flipper_object_type__": "Date",
"data": 1614555067205,
}

View File

@@ -27,7 +27,7 @@ test('Correct top level API exposed', () => {
// Note, all `exposedAPIs` should be documented in `flipper-plugin.mdx`
expect(exposedAPIs.sort()).toMatchInlineSnapshot(`
Array [
[
"CodeBlock",
"DataDescription",
"DataFormatter",
@@ -83,7 +83,7 @@ test('Correct top level API exposed', () => {
`);
expect(exposedTypes.sort()).toMatchInlineSnapshot(`
Array [
[
"Atom",
"AtomPersistentStorage",
"CrashLog",

View File

@@ -180,8 +180,8 @@ test('a plugin can receive messages', async () => {
sendEvent('inc', {delta: 2});
expect(instance.state.get().count).toBe(2);
expect(exportState()).toMatchInlineSnapshot(`
Object {
"counter": Object {
{
"counter": {
"count": 2,
},
}
@@ -268,7 +268,7 @@ test('plugins cannot use a persist key twice', async () => {
},
});
}).toThrowErrorMatchingInlineSnapshot(
`"Some other state is already persisting with key \\"test\\""`,
`"Some other state is already persisting with key "test""`,
);
});
@@ -352,8 +352,8 @@ test('plugins can handle import errors', async () => {
).instance;
// @ts-ignore
expect(console.error.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[
[
"An error occurred when importing data for plugin 'TestPlugin': 'Error: Oops",
[Error: Oops],
],

View File

@@ -42,8 +42,8 @@ test('it can start a plugin and lifecycle events', () => {
expect(instance.x.get()).toEqual({x: 2});
expect(instance.y.get()).toEqual(true);
expect(getStorageSnapshot()).toMatchInlineSnapshot(`
Object {
"flipper:TestPlugin:atom:x": "{ \\"x\\": 2 }",
{
"flipper:TestPlugin:atom:x": "{ "x": 2 }",
}
`);
@@ -52,8 +52,8 @@ test('it can start a plugin and lifecycle events', () => {
});
instance.y.set(false);
expect(getStorageSnapshot()).toMatchInlineSnapshot(`
Object {
"flipper:TestPlugin:atom:x": "{\\"x\\":3}",
{
"flipper:TestPlugin:atom:x": "{"x":3}",
"flipper:TestPlugin:atom:y": "false",
}
`);

View File

@@ -25,13 +25,13 @@ test('default formatter', () => {
expect(DataFormatter.format({hello: 'world'})).toMatchInlineSnapshot(`
"{
\\"hello\\": \\"world\\"
"hello": "world"
}"
`);
expect(DataFormatter.format({hello: ['world']})).toMatchInlineSnapshot(`
"{
\\"hello\\": [
\\"world\\"
"hello": [
"world"
]
}"
`);
@@ -39,8 +39,8 @@ test('default formatter', () => {
.toMatchInlineSnapshot(`
"[
[
\\"hello\\",
\\"world\\"
"hello",
"world"
]
]"
`);
@@ -48,8 +48,8 @@ test('default formatter', () => {
.toMatchInlineSnapshot(`
"[
[
\\"hello\\",
\\"world\\"
"hello",
"world"
]
]"
`);
@@ -85,7 +85,7 @@ test('linkify formatter', () => {
// verify fallback
expect(linkify({hello: 'world'})).toMatchInlineSnapshot(`
"{
\\"hello\\": \\"world\\"
"hello": "world"
}"
`);
expect(linkify('hi there!')).toMatchInlineSnapshot(`"hi there!"`);
@@ -142,13 +142,13 @@ test('jsonify formatter', () => {
expect(jsonify({hello: 'world'})).toMatchInlineSnapshot(`
"{
\\"hello\\": \\"world\\"
"hello": "world"
}"
`);
expect(jsonify([{hello: 'world'}])).toMatchInlineSnapshot(`
"[
{
\\"hello\\": \\"world\\"
"hello": "world"
}
]"
`);
@@ -181,7 +181,7 @@ test("jsonify doesn't process react elements", () => {
expect(jsonify('{ a: 1 }')).toMatchInlineSnapshot(`"{ a: 1 }"`);
expect(jsonify({a: 1})).toMatchInlineSnapshot(`
"{
\\"a\\": 1
"a": 1
}"
`);
expect(jsonify(<span>hi</span>)).toMatchInlineSnapshot(`
@@ -197,7 +197,7 @@ test('truncate formatter', () => {
expect(truncate({test: true})).toMatchInlineSnapshot(`
"{
\\"test\\": true
"test": true
}"
`);
expect(truncate('abcde')).toEqual('abcde');

View File

@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`handles single point 1`] = `
Array [
Object {
[
{
"color": "var(--flipper-background-default)",
"isCut": false,
"markerKeys": Array [
"markerKeys": [
"1",
],
"markerNames": Array [
"markerNames": [
"single point",
],
"positionY": 0,
@@ -17,4 +17,4 @@ Array [
]
`;
exports[`no points 1`] = `Array []`;
exports[`no points 1`] = `[]`;

View File

@@ -66,7 +66,7 @@ test('it can store values', async () => {
expect((await res.findByTestId('value')).textContent).toEqual('2');
expect(storage).toMatchInlineSnapshot(`
Object {
{
"[useLocalStorage][Flipper]x": "2",
}
`);
@@ -83,7 +83,7 @@ test('it can read default from storage', async () => {
expect((await res.findByTestId('value')).textContent).toEqual('4');
expect(storage).toMatchInlineSnapshot(`
Object {
{
"[useLocalStorage][Flipper]x": "4",
}
`);

View File

@@ -26,7 +26,7 @@ test('createTablePlugin returns FlipperPlugin', () => {
const tablePlugin = createTablePlugin(PROPS);
const p = startPlugin(tablePlugin);
expect(Object.keys(p.instance)).toMatchInlineSnapshot(`
Array [
[
"selection",
"rows",
"isPaused",

View File

@@ -182,6 +182,8 @@ async function start() {
tcp: argv.tcp,
});
// maybe at this point we could open up, http server is running.
const flipperServer = await startFlipperServer(
rootPath,
staticPath,

View File

@@ -53,6 +53,7 @@
"devDependencies": {
"@testing-library/dom": "^8.20.0",
"@types/deep-equal": "^1.0.1",
"@types/jest": "^29.5.1",
"@types/lodash.memoize": "^4.1.7",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.12",

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);
@@ -84,8 +84,8 @@ ${changelog}
`);
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 {}`,
);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`{}`);
});
test('queue - events are NOT processed immediately if plugin is NOT selected (but enabled)', async () => {
@@ -139,36 +137,36 @@ 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 {
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {},
"params": {},
},
],
}
`);
client.flushMessageBuffer();
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": {},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 3,
},
},
@@ -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,12 +276,12 @@ 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 {
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
@@ -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 {
{
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {},
"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 {
{
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": [
{
"api": "StubPlugin",
"method": "log",
"params": Object {
"params": {
"line": "suff",
},
},
],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {},
"params": {},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 3,
},
},
],
}
`);
expect(client.messageBuffer).toMatchInlineSnapshot(`Object {}`);
expect(client.messageBuffer).toMatchInlineSnapshot(`{}`);
expect(StubPlugin.persistedStateReducer.mock.calls).toMatchInlineSnapshot(
`Array []`,
`[]`,
);
// tigger processing the queue
@@ -625,11 +621,11 @@ test('client - incoming messages are buffered and flushed together', async () =>
);
expect(StubPlugin.persistedStateReducer.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
[
[
undefined,
"log",
Object {
{
"line": "suff",
},
],
@@ -637,25 +633,25 @@ test('client - incoming messages are buffered and flushed together', async () =>
`);
expect(store.getState().pluginMessageQueue).toMatchInlineSnapshot(`
Object {
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": Array [],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": Array [
Object {
{
"TestApp#Android#MockAndroidDevice#serial#StubPlugin": [],
"TestApp#Android#MockAndroidDevice#serial#TestPlugin": [
{
"api": "TestPlugin",
"method": "inc",
"params": Object {},
"params": {},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 2,
},
},
Object {
{
"api": "TestPlugin",
"method": "inc",
"params": Object {
"params": {
"delta": 3,
},
},
@@ -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'});

View File

@@ -30,6 +30,6 @@ module.exports = {
...(process.env.COVERAGE_TEXT === 'detailed' ? ['text'] : []),
],
testMatch: ['**/**.(node|spec).(js|jsx|ts|tsx)'],
testEnvironment: 'jest-environment-jsdom-sixteen',
testEnvironment: 'jsdom',
resolver: '<rootDir>/jest.resolver.js',
};

View File

@@ -70,7 +70,7 @@
"@babel/eslint-parser": "^7.19.1",
"@jest-runner/electron": "^3.0.1",
"@testing-library/react": "^12.1.4",
"@types/jest": "^26.0.24",
"@types/jest": "^29.5.1",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.55.0",
"babel-eslint": "^10.1.0",
@@ -93,15 +93,14 @@
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.5.0",
"eslint-plugin-rulesdir": "^0.2.1",
"jest": "^26.6.3",
"jest-environment-jsdom-sixteen": "^2.0.0",
"jest": "^29.5.0",
"jest-fetch-mock": "^3.0.3",
"less": "^4.1.2",
"patch-package": "^6.4.7",
"prettier": "^2.8.7",
"pretty-format": "^27.5.0",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.6",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
@@ -116,6 +115,7 @@
"productName": "Flipper",
"resolutions": {
"@jest-runner/electron/electron": "18.2.0",
"jest-environment-jsdom": "29.5.0",
"minimist": "1.2.6",
"node-forge": "^1.0.6"
},

View File

@@ -104,7 +104,7 @@ describe('getWatchFolders', () => {
path.join(rootDir, 'local_module_2'),
);
expect(resolvedFolders.map(normalizePath)).toMatchInlineSnapshot(`
Array [
[
"/test/root/local_module_2",
"/test/root/node_modules",
"/test/root/plugins/fb/fb_plugin_module_1",

View File

@@ -66,11 +66,11 @@ test('$schema field is required', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
". should have required property \\"$schema\\" pointing to a supported schema URI, e.g.:
[
". should have required property "$schema" pointing to a supported schema URI, e.g.:
{
\\"$schema\\": \\"https://fbflipper.com/schemas/plugin-package/v2.json\\",
\\"name\\": \\"flipper-plugin-example\\",
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
"name": "flipper-plugin-example",
...
}",
]
@@ -85,7 +85,7 @@ test('supported schema is required', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
[
".$schema should point to a supported schema. Currently supported schemas:
- https://fbflipper.com/schemas/plugin-package/v2.json",
]
@@ -100,7 +100,7 @@ test('name is required', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
[
". should have required property 'name'",
]
`);
@@ -113,8 +113,8 @@ test('name must start with "flipper-plugin-"', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
"/name should start with \\"flipper-plugin-\\", e.g. \\"flipper-plugin-example\\"",
[
"/name should start with "flipper-plugin-", e.g. "flipper-plugin-example"",
]
`);
});
@@ -126,8 +126,8 @@ test('keywords must contain "flipper-plugin"', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
"/keywords should contain keyword \\"flipper-plugin\\"",
[
"/keywords should contain keyword "flipper-plugin"",
]
`);
});
@@ -144,7 +144,7 @@ test('flippeBundlerEntry must point to an existing file', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
[
"/flipperBundlerEntry should point to a valid file",
]
`);
@@ -159,9 +159,9 @@ test('multiple validation errors reported', async () => {
fs.readFile = jest.fn().mockResolvedValue(new Buffer(json));
const result = await runLint('dir');
expect(result).toMatchInlineSnapshot(`
Array [
[
". should have required property 'flipperBundlerEntry'",
"/keywords should contain keyword \\"flipper-plugin\\"",
"/keywords should contain keyword "flipper-plugin"",
]
`);
});

View File

@@ -72,31 +72,31 @@ test('converts package.json and adds dependencies', async () => {
expect(error).toBeUndefined();
expect(convertedPackageJsonString).toMatchInlineSnapshot(`
"{
\\"$schema\\": \\"https://fbflipper.com/schemas/plugin-package/v2.json\\",
\\"name\\": \\"flipper-plugin-fresco\\",
\\"id\\": \\"Fresco\\",
\\"version\\": \\"1.0.0\\",
\\"main\\": \\"dist/bundle.js\\",
\\"flipperBundlerEntry\\": \\"index.tsx\\",
\\"license\\": \\"MIT\\",
\\"keywords\\": [
\\"flipper-plugin\\",
\\"images\\"
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
"name": "flipper-plugin-fresco",
"id": "Fresco",
"version": "1.0.0",
"main": "dist/bundle.js",
"flipperBundlerEntry": "index.tsx",
"license": "MIT",
"keywords": [
"flipper-plugin",
"images"
],
\\"peerDependencies\\": {
\\"flipper\\": \\"latest\\"
"peerDependencies": {
"flipper": "latest"
},
\\"devDependencies\\": {
\\"flipper\\": \\"latest\\",
\\"flipper-pkg\\": \\"latest\\"
"devDependencies": {
"flipper": "latest",
"flipper-pkg": "latest"
},
\\"scripts\\": {
\\"prepack\\": \\"yarn reset && yarn build && flipper-pkg lint && flipper-pkg bundle\\"
"scripts": {
"prepack": "yarn reset && yarn build && flipper-pkg lint && flipper-pkg bundle"
},
\\"title\\": \\"Images\\",
\\"icon\\": \\"profile\\",
\\"bugs\\": {
\\"email\\": \\"example@test.com\\"
"title": "Images",
"icon": "profile",
"bugs": {
"email": "example@test.com"
}
}"
`);
@@ -107,27 +107,27 @@ test('converts package.json without changing dependencies', async () => {
expect(error).toBeUndefined();
expect(convertedPackageJsonString).toMatchInlineSnapshot(`
"{
\\"$schema\\": \\"https://fbflipper.com/schemas/plugin-package/v2.json\\",
\\"name\\": \\"flipper-plugin-fresco\\",
\\"id\\": \\"Fresco\\",
\\"version\\": \\"1.0.0\\",
\\"main\\": \\"dist/bundle.js\\",
\\"flipperBundlerEntry\\": \\"index.tsx\\",
\\"license\\": \\"MIT\\",
\\"keywords\\": [
\\"flipper-plugin\\",
\\"images\\"
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
"name": "flipper-plugin-fresco",
"id": "Fresco",
"version": "1.0.0",
"main": "dist/bundle.js",
"flipperBundlerEntry": "index.tsx",
"license": "MIT",
"keywords": [
"flipper-plugin",
"images"
],
\\"dependencies\\": {
\\"flipper\\": \\"latest\\"
"dependencies": {
"flipper": "latest"
},
\\"scripts\\": {
\\"prepack\\": \\"yarn reset && yarn build && flipper-pkg lint && flipper-pkg bundle\\"
"scripts": {
"prepack": "yarn reset && yarn build && flipper-pkg lint && flipper-pkg bundle"
},
\\"title\\": \\"Images\\",
\\"icon\\": \\"profile\\",
\\"bugs\\": {
\\"email\\": \\"example@test.com\\"
"title": "Images",
"icon": "profile",
"bugs": {
"email": "example@test.com"
}
}"
`);

View File

@@ -12,7 +12,6 @@ import path from 'path';
import {getInstalledPluginDetails} from '../getPluginDetails';
import {pluginInstallationDir} from '../pluginPaths';
import {normalizePath} from 'flipper-test-utils';
import {mocked} from 'ts-jest/utils';
jest.mock('fs-extra');
@@ -37,7 +36,7 @@ test('getPluginDetailsV1', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -80,7 +79,7 @@ test('getPluginDetailsV2', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -127,7 +126,7 @@ test('id used as title if the latter omited', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -173,7 +172,7 @@ test('name without "flipper-plugin-" prefix is used as title if the latter omite
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -222,7 +221,7 @@ test('flipper-plugin-version is parsed', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -275,7 +274,7 @@ test('plugin type and supported devices parsed', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -299,19 +298,19 @@ test('plugin type and supported devices parsed', async () => {
"source": "src/index.tsx",
"specVersion": 2,
"supportedApps": undefined,
"supportedDevices": Array [
Object {
"supportedDevices": [
{
"archived": false,
"os": "Android",
},
Object {
{
"os": "Android",
"specs": Array [
"specs": [
"KaiOS",
],
"type": "physical",
},
Object {
{
"os": "iOS",
"type": "emulator",
},
@@ -344,7 +343,7 @@ test('plugin type and supported apps parsed', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
{
"bugs": undefined,
"category": undefined,
"deprecated": undefined,
@@ -367,18 +366,18 @@ test('plugin type and supported apps parsed', async () => {
"serverAddOnSource": undefined,
"source": "src/index.tsx",
"specVersion": 2,
"supportedApps": Array [
Object {
"supportedApps": [
{
"appID": "Messenger",
"os": "Android",
"type": "emulator",
},
Object {
{
"appID": "Instagram",
"os": "Android",
"type": "physical",
},
Object {
{
"appID": "Facebook",
"os": "iOS",
"type": "emulator",
@@ -417,7 +416,7 @@ test('can merge two package.json files', async () => {
email: 'flippersupport@example.localhost',
},
};
const mockedFs = mocked(fs);
const mockedFs = jest.mocked(fs);
mockedFs.readJson.mockImplementation((file) => {
if (file === path.join(pluginPath, 'package.json')) {
return pluginBase;
@@ -430,8 +429,8 @@ test('can merge two package.json files', async () => {
details.dir = normalizePath(details.dir);
details.entry = normalizePath(details.entry);
expect(details).toMatchInlineSnapshot(`
Object {
"bugs": Object {
{
"bugs": {
"email": "flippersupport@example.localhost",
"url": "https://fb.com/groups/flippersupport",
},
@@ -450,7 +449,7 @@ test('can merge two package.json files', async () => {
"main": "dist/bundle.js",
"name": "flipper-plugin-test",
"pluginType": "device",
"publishedDocs": Object {
"publishedDocs": {
"overview": true,
"setup": true,
},
@@ -460,19 +459,19 @@ test('can merge two package.json files', async () => {
"source": "src/index.tsx",
"specVersion": 2,
"supportedApps": undefined,
"supportedDevices": Array [
Object {
"supportedDevices": [
{
"archived": false,
"os": "Android",
},
Object {
{
"os": "Android",
"specs": Array [
"specs": [
"KaiOS",
],
"type": "physical",
},
Object {
{
"os": "iOS",
"type": "emulator",
},

View File

@@ -16,7 +16,6 @@ import {
NpmPackageDescriptor,
} from '../getNpmHostedPlugins';
import {getInstalledPlugins} from '../pluginInstaller';
import {mocked} from 'ts-jest/utils';
import type {Package} from 'npm-api';
import {InstalledPluginDetails} from 'flipper-common';
@@ -91,10 +90,10 @@ const updates: NpmPackageDescriptor[] = [
];
test('annotatePluginsWithUpdates', async () => {
const getInstalledPluginsMock = mocked(getInstalledPlugins);
const getInstalledPluginsMock = jest.mocked(getInstalledPlugins);
getInstalledPluginsMock.mockReturnValue(Promise.resolve(installedPlugins));
const getNpmHostedPluginsMock = mocked(getNpmHostedPlugins);
const getNpmHostedPluginsMock = jest.mocked(getNpmHostedPlugins);
getNpmHostedPluginsMock.mockReturnValue(Promise.resolve(updates));
const res = await getUpdatablePlugins();
@@ -105,9 +104,9 @@ test('annotatePluginsWithUpdates', async () => {
version: res[0].version,
updateStatus: res[0].updateStatus,
}).toMatchInlineSnapshot(`
Object {
{
"name": "flipper-plugin-hello",
"updateStatus": Object {
"updateStatus": {
"kind": "up-to-date",
},
"version": "0.1.0",
@@ -119,9 +118,9 @@ test('annotatePluginsWithUpdates', async () => {
version: res[1].version,
updateStatus: res[1].updateStatus,
}).toMatchInlineSnapshot(`
Object {
{
"name": "flipper-plugin-world",
"updateStatus": Object {
"updateStatus": {
"kind": "update-available",
"version": "0.3.0",
},

View File

@@ -50,8 +50,8 @@ test('it will merge equal rows', () => {
sendLogEntry(entry3);
expect(instance.rows.records()).toMatchInlineSnapshot(`
Array [
Object {
[
{
"app": "X",
"count": 1,
"date": 2021-01-28T17:15:12.859Z,
@@ -61,7 +61,7 @@ test('it will merge equal rows', () => {
"tid": 1,
"type": "error",
},
Object {
{
"app": "Y",
"count": 2,
"date": 2021-01-28T17:15:17.859Z,
@@ -71,7 +71,7 @@ test('it will merge equal rows', () => {
"tid": 3,
"type": "warn",
},
Object {
{
"app": "X",
"count": 1,
"date": 2021-01-28T17:15:12.859Z,
@@ -130,9 +130,9 @@ test('export / import plugin does work', async () => {
const data = await exportStateAsync();
expect(data).toMatchInlineSnapshot(`
Object {
"logs": Array [
Object {
{
"logs": [
{
"app": "X",
"count": 1,
"date": 2021-01-28T17:15:12.859Z,
@@ -142,7 +142,7 @@ test('export / import plugin does work', async () => {
"tid": 1,
"type": "error",
},
Object {
{
"app": "Y",
"count": 1,
"date": 2021-01-28T17:15:17.859Z,

View File

@@ -47,11 +47,11 @@ test('Reducer correctly adds initial chunk', () => {
});
expect(instance.partialResponses.get()['1']).toMatchInlineSnapshot(`
Object {
"followupChunks": Object {},
"initialResponse": Object {
{
"followupChunks": {},
"initialResponse": {
"data": "hello",
"headers": Array [],
"headers": [],
"id": "1",
"index": 0,
"insights": null,
@@ -76,8 +76,8 @@ test('Reducer correctly adds followup chunk', () => {
data: 'hello',
});
expect(instance.partialResponses.get()['1']).toMatchInlineSnapshot(`
Object {
"followupChunks": Object {
{
"followupChunks": {
"1": "hello",
},
}
@@ -113,13 +113,13 @@ test('Reducer correctly combines initial response and followup chunk', () => {
totalChunks: 2,
});
expect(instance.partialResponses.get()).toMatchInlineSnapshot(`
Object {
"1": Object {
"followupChunks": Object {},
"initialResponse": Object {
{
"1": {
"followupChunks": {},
"initialResponse": {
"data": "aGVs",
"headers": Array [
Object {
"headers": [
{
"key": "Content-Type",
"value": "text/plain",
},

View File

@@ -75,13 +75,13 @@ test('Can handle custom headers', async () => {
// verify internal storage
expect(instance.columns.get().slice(-2)).toMatchInlineSnapshot(`
Array [
Object {
[
{
"key": "request_header_test-header",
"title": "test-header (request)",
"width": 200,
},
Object {
{
"key": "response_header_second-test-header",
"title": "second-test-header (response)",
"width": 200,
@@ -138,13 +138,13 @@ test('Can handle custom headers', async () => {
// verify internal storage
expect(instance2.columns.get().slice(-2)).toMatchInlineSnapshot(`
Array [
Object {
[
{
"key": "request_header_test-header",
"title": "test-header (request)",
"width": 200,
},
Object {
{
"key": "response_header_second-test-header",
"title": "second-test-header (response)",
"width": 200,

View File

@@ -28,13 +28,13 @@ test('It can store rows', () => {
});
expect(instance.rows.get()).toMatchInlineSnapshot(`
Object {
"1": Object {
{
"1": {
"id": 1,
"title": "Dolphin",
"url": "http://dolphin.png",
},
"2": Object {
"2": {
"id": 2,
"title": "Turtle",
"url": "http://turtle.png",

View File

@@ -37,16 +37,16 @@ test('general plugin logic testing', async () => {
await sleep(1000);
expect(onSend).toBeCalledWith('getAllSharedPreferences', {});
expect(instance.sharedPreferences.get()).toMatchInlineSnapshot(`
Object {
"other_sample": Object {
"changesList": Array [],
"preferences": Object {
{
"other_sample": {
"changesList": [],
"preferences": {
"SomeKey": 1337,
},
},
"sample": Object {
"changesList": Array [],
"preferences": Object {
"sample": {
"changesList": [],
"preferences": {
"Hello": "world",
},
},
@@ -77,16 +77,16 @@ test('general plugin logic testing', async () => {
5555,
);
expect(instance.sharedPreferences.get()).toMatchInlineSnapshot(`
Object {
"other_sample": Object {
"changesList": Array [],
"preferences": Object {
{
"other_sample": {
"changesList": [],
"preferences": {
"SomeKey": 5555,
},
},
"sample": Object {
"changesList": Array [
Object {
"sample": {
"changesList": [
{
"deleted": false,
"name": "SomeKey",
"preferences": "sample",
@@ -94,7 +94,7 @@ test('general plugin logic testing', async () => {
"value": 5555,
},
],
"preferences": Object {
"preferences": {
"Hello": "world",
"SomeKey": 5555,
},
@@ -120,20 +120,20 @@ test('general plugin logic testing', async () => {
instance.sharedPreferences.get().sample.preferences.SomeKey,
).toBeUndefined();
expect(instance.sharedPreferences.get()).toMatchInlineSnapshot(`
Object {
"other_sample": Object {
"changesList": Array [],
"preferences": Object {},
{
"other_sample": {
"changesList": [],
"preferences": {},
},
"sample": Object {
"changesList": Array [
Object {
"sample": {
"changesList": [
{
"deleted": true,
"name": "SomeKey",
"preferences": "sample",
"time": 2,
},
Object {
{
"deleted": false,
"name": "SomeKey",
"preferences": "sample",
@@ -141,7 +141,7 @@ test('general plugin logic testing', async () => {
"value": 5555,
},
],
"preferences": Object {
"preferences": {
"Hello": "world",
},
},

View File

@@ -63,17 +63,51 @@ console.debug = function () {
};
// make perf tools available in Node (it is available in Browser / Electron just fine)
const {PerformanceObserver, performance} = require('perf_hooks');
Object.freeze(performance);
Object.freeze(Object.getPrototypeOf(performance));
import {PerformanceObserver, performance} from 'perf_hooks';
// Object.freeze(performance);
// Object.freeze(Object.getPrototypeOf(performance));
// Something in our unit tests is messing with the performance global
// This fixes that.....
// This fixes that.
let _performance = performance;
Object.defineProperty(global, 'performance', {
get() {
return performance;
return _performance;
},
set() {
throw new Error('Attempt to overwrite global.performance');
set(value) {
_performance = value;
if (typeof _performance.mark === 'undefined') {
_performance.mark = (_markName: string, _markOptions?) => {
return {
name: '',
detail: '',
duration: 0,
entryType: '',
startTime: 0,
toJSON() {},
};
};
}
if (typeof _performance.clearMarks === 'undefined') {
_performance.clearMarks = () => {};
}
if (typeof _performance.measure === 'undefined') {
_performance.measure = (
_measureName: string,
_startOrMeasureOptions?,
_endMark?: string | undefined,
) => {
return {
name: '',
detail: '',
duration: 0,
entryType: '',
startTime: 0,
toJSON() {},
};
};
}
},
});

View File

@@ -18,11 +18,10 @@ process.env.FLIPPER_TEST_RUNNER = 'true';
const {transform} = require('../babel-transformer/lib/transform-jest');
module.exports = {
process(src, filename, config, options) {
process(src, filename, options) {
return transform({
src,
filename,
config,
options: {...options, isTestRunner: true},
});
},

File diff suppressed because it is too large Load Diff