Make sure that limited top-level exports are exposed from flipper-plugin

Summary: This prefixes APIs of `flipper-plugin`, that are used by Flipper, but should not be used by plugins directly, with `_`. Also added tests to make sure we are always intentional when extending the exposed APIs

Reviewed By: passy

Differential Revision: D24991700

fbshipit-source-id: ed3700efa188fca7f5a14d5c68250598cf011e42
This commit is contained in:
Michel Weststrate
2020-11-16 13:08:05 -08:00
committed by Facebook GitHub Bot
parent cc438e60ad
commit 45db64f0d0
21 changed files with 156 additions and 90 deletions

View File

@@ -0,0 +1,53 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import * as FlipperPluginModule from '../index';
test('Correct top level API exposed', () => {
const exposedAPIs: string[] = [];
const exposedTypes: string[] = [];
Object.entries(FlipperPluginModule).forEach(([key, value]) => {
if (key[0] === '_') {
return;
}
if (value === undefined) {
exposedTypes.push(key);
} else {
exposedAPIs.push(key);
}
});
expect(exposedAPIs.sort()).toMatchInlineSnapshot(`
Array [
"Layout",
"NUX",
"TestUtils",
"createState",
"renderReactRoot",
"theme",
"usePlugin",
"useValue",
]
`);
expect(exposedTypes.sort()).toMatchInlineSnapshot(`
Array [
"Atom",
"DefaultKeyboardAction",
"Device",
"DeviceLogEntry",
"DeviceLogListener",
"DevicePluginClient",
"DeviceType",
"FlipperLib",
"LogLevel",
"MenuEntry",
"NormalizedMenuEntry",
"PluginClient",
]
`);
});