Fix mock export file format (#1872)

Summary:
Provide a more robust technique for exporting the mocks to a file.

The current technique for exporting mocks to a file seems to fail under some scenarios.  The correct format is an array of objects:

```
[
  {
    "requestUrl": "https://api.github.com/repos/facebook/yoga",
    "requestMethod": "GET",
```
However, the following format is sometimes exported instead:

```
{
  "10": {
    "requestUrl": "https://demo9512366.mockable.io/SonarPost",
```

Using `Object.values` provides a more robust technique that has been successful during subsequent testing.

## Changelog

Network Plugin - new technique for exporting mocks

Pull Request resolved: https://github.com/facebook/flipper/pull/1872

Test Plan:
Create mocks in the network plugin
Export mocks
Manually examine file for correct format
Import mocks and verify that the file has been imported correctly

Reviewed By: nikoant

Differential Revision: D26172954

Pulled By: mweststrate

fbshipit-source-id: bdfa3ba7dfe656f30ef17df001fc83dd8ea18ece
This commit is contained in:
bizzguy
2021-02-01 10:21:21 -08:00
committed by Facebook GitHub Bot
parent 340a29c1d5
commit 5320015776

View File

@@ -445,7 +445,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
}
fs.writeFile(
file,
JSON.stringify(routes.get(), null, 2),
JSON.stringify(Object.values(routes.get()), null, 2),
'utf8',
(err) => {
if (err) {