From fce8715a3b7fc82149324a74169eb1e5976dc9d4 Mon Sep 17 00:00:00 2001 From: Anton Kastritskiy Date: Tue, 6 Feb 2024 08:57:41 -0800 Subject: [PATCH] test number of consoler logs on plugin render Summary: the number of logs in the console is out of hand. Lets not make it worse Reviewed By: lblasa Differential Revision: D53476216 fbshipit-source-id: 06e4fe21ba09c3a11c292706c66fa3a16528afd6 --- .../src/__tests__/PluginContainer.node.tsx | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/desktop/flipper-ui/src/__tests__/PluginContainer.node.tsx b/desktop/flipper-ui/src/__tests__/PluginContainer.node.tsx index 76ac4fd4922..bffb3489f89 100644 --- a/desktop/flipper-ui/src/__tests__/PluginContainer.node.tsx +++ b/desktop/flipper-ui/src/__tests__/PluginContainer.node.tsx @@ -66,6 +66,20 @@ class TestPlugin extends FlipperPlugin { } } +let errorSpy: any, warnSpy: any, infoSpy: any; + +beforeAll(() => { + errorSpy = jest.spyOn(console, 'error'); + warnSpy = jest.spyOn(console, 'warn'); + infoSpy = jest.spyOn(console, 'info'); +}); + +afterAll(() => { + errorSpy.mockRestore(); + warnSpy.mockRestore(); + infoSpy.mockRestore(); +}); + test('Plugin container can render plugin and receive updates', async () => { const {renderer, sendMessage, act} = await renderMockFlipperWithPlugin(TestPlugin); @@ -110,6 +124,23 @@ test('Plugin container can render plugin and receive updates', async () => { expect((await renderer.findByTestId('counter')).textContent).toBe('2'); }); +test('Number of times console errors/warning during plugin render', async () => { + await renderMockFlipperWithPlugin(TestPlugin); + + expect(errorSpy.mock.calls).toEqual([ + [ + "Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot", + ], + ]); + expect(warnSpy.mock.calls).toEqual([]); + expect(infoSpy.mock.calls).toEqual([ + [ + "Received plugins from 'TestApp' on device 'MockAndroidDevice'", + ['TestPlugin'], + ], + ]); +}); + // TODO(T119353406): Disabled due to flakiness. test.skip('PluginContainer can render Sandy plugins', async () => { let renders = 0;