Add unit tests for ServerAddOn
Reviewed By: mweststrate Differential Revision: D34303780 fbshipit-source-id: 03a4570a6e891d979b87caca14f51068d74df877
This commit is contained in:
committed by
Facebook GitHub Bot
parent
81d0057a8d
commit
d96cf8127f
@@ -12,42 +12,11 @@ import {assertNotNull} from '../comms/Utilities';
|
||||
import {
|
||||
FlipperServerForServerAddOn,
|
||||
ServerAddOnCleanup,
|
||||
ServerAddOn as ServerAddOnFn,
|
||||
ServerAddOnStartDetails,
|
||||
} from 'flipper-common';
|
||||
import {ServerAddOnDesktopToModuleConnection} from './ServerAddOnDesktopToModuleConnection';
|
||||
import {ServerAddOnModuleToDesktopConnection} from './ServerAddOnModuleToDesktopConnection';
|
||||
// @ts-ignore
|
||||
import defaultPlugins from '../defaultPlugins';
|
||||
|
||||
interface ServerAddOnModule {
|
||||
default: ServerAddOnFn;
|
||||
}
|
||||
|
||||
const loadPlugin = (
|
||||
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;
|
||||
};
|
||||
import {loadServerAddOn} from './loadServerAddOn';
|
||||
|
||||
export class ServerAddOn {
|
||||
private owners: Set<string>;
|
||||
@@ -69,7 +38,7 @@ export class ServerAddOn {
|
||||
): Promise<ServerAddOn> {
|
||||
console.info('ServerAddOn.start', pluginName, details);
|
||||
|
||||
const {default: serverAddOn} = loadPlugin(pluginName, details);
|
||||
const {default: serverAddOn} = loadServerAddOn(pluginName, details);
|
||||
assertNotNull(serverAddOn);
|
||||
assert(
|
||||
typeof serverAddOn === 'function',
|
||||
|
||||
Reference in New Issue
Block a user