From cf9f4e0c5bf3e88e128979d577cc3c5c49b87733 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Fri, 13 Dec 2019 07:07:48 -0800 Subject: [PATCH] Document how to test JavaScript plugins Summary: It's not much, but at least more than nothing :) Reviewed By: nikoant Differential Revision: D18930725 fbshipit-source-id: b1e5fa203b0020de7b5f16d040808cbb247b8dd4 --- docs/extending/testing.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/extending/testing.md b/docs/extending/testing.md index 3440c89a1..aa30ffc63 100644 --- a/docs/extending/testing.md +++ b/docs/extending/testing.md @@ -93,3 +93,20 @@ TEST(MyFlipperPluginTests, testDummy) { EXPECT_EQ(successfulResponses.back(), expectedResponse); } ``` + +## Testing the Flipper Desktop Plugin + +Tests should be put in the `__tests__` directory of your plugin sources, and be created using Jest. +An example test suite can be found [here](https://github.com/facebook/flipper/blob/master/src/plugins/layout/__tests__/ProxyArchiveClient.node.tsx). + +Flipper exposes an API to generate unit tests that can verify _regressions_ and real life scenarios. +To generate a unit test: + +1. Start flipper. +2. Open your plugin. +3. Open the Developer Tools (`View > Open Developer Tools`). +4. In the console, call the function `flipperStartPluginRecording()`. +5. Interact with your application, in such a way that new events are created for your plugin. +6. Once you generated an interesting amount and diversity of events, call `flipperStopPluginRecording()` from the Flipper console. +7. This process will have generated a unit test and a snapshot file with the data (the console will report where). Move those files to your `__tests__` directory. +8. The unit test should succeed if it is run using Jest. Feel free to modify the unit test to your needs. In the future you might want to record new snapshot data files if the plugin changes.