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
This commit is contained in:
committed by
Facebook Github Bot
parent
8da2c8868b
commit
cf9f4e0c5b
@@ -93,3 +93,20 @@ TEST(MyFlipperPluginTests, testDummy) {
|
|||||||
EXPECT_EQ(successfulResponses.back(), expectedResponse);
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user