Add unit tests for ServerAddOn

Reviewed By: mweststrate

Differential Revision: D34303780

fbshipit-source-id: 03a4570a6e891d979b87caca14f51068d74df877
This commit is contained in:
Andrey Goncharov
2022-02-28 03:50:34 -08:00
committed by Facebook GitHub Bot
parent 81d0057a8d
commit d96cf8127f
3 changed files with 205 additions and 33 deletions

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) Meta Platforms, Inc. and 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 {
ServerAddOn as ServerAddOnFn,
ServerAddOnStartDetails,
} from 'flipper-common';
import {assertNotNull} from '../comms/Utilities';
// The file is generated automatically by "prepareDefaultPlugins" in "scripts"
// @ts-ignore
import defaultPlugins from '../defaultPlugins';
interface ServerAddOnModule {
default: ServerAddOnFn;
}
export const loadServerAddOn = (
pluginName: string,
details: ServerAddOnStartDetails,
): ServerAddOnModule => {
console.debug('loadPlugin', pluginName, details);
if (details.isBundled) {
const bundledPlugin = defaultPlugins[pluginName];
assertNotNull(
bundledPlugin,
`loadPlugin (isBundled = true) -> plugin ${pluginName} not found.`,
);
return bundledPlugin;
}
assertNotNull(
details.path,
`loadPlugin (isBundled = false) -> server add-on path is empty plugin ${pluginName}.`,
);
// eslint-disable-next-line no-eval
const serverAddOnModule = eval(`require("${details.path}")`);
return serverAddOnModule;
};