Files
flipper/src/utils/__tests__/pluginUtils.node.js
Pascal Hartig c588b650ae Prefer const wherever possible
Summary:
Non-final identifiers make code harder to understand.
This is particularly true for JavaScript where even the *type*
can change as a value gets reassigned later.

This enforces to use `const` whereever possible, but doesn't
"outlaw" `let`. Mixed destructuring is also still allowed.

Used `eslint --fix` to change all existing cases.

Reviewed By: jknoxville

Differential Revision: D16131329

fbshipit-source-id: 2eceaca7c603b71b36e005be5d135e1849f2518d
2019-07-10 03:28:25 -07:00

63 lines
1.8 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {getActivePluginNames} from '../pluginUtils';
import type {State as PluginsState} from '../../reducers/plugins.js';
import type {PluginDefinition} from '../../dispatcher/plugins';
function mockPluginState(
gatekeepedPlugins: Array<PluginDefinition>,
disabledPlugins: Array<PluginDefinition>,
failedPlugins: Array<[PluginDefinition, string]>,
): PluginsState {
return {
devicePlugins: new Map([
//$FlowFixMe: Class instance won't be used in the test
['DevicePlugin1', undefined],
//$FlowFixMe: Class instance won't be used in the test
['DevicePlugin2', undefined],
]),
clientPlugins: new Map([
//$FlowFixMe: Class instance won't be used in the test
['ClientPlugin1', undefined],
//$FlowFixMe: Class instance won't be used in the test
['ClientPlugin2', undefined],
]),
gatekeepedPlugins,
disabledPlugins,
failedPlugins,
};
}
function mockPluginDefinition(name: string): PluginDefinition {
return {
name,
out: 'out',
};
}
test('getActivePluginNames with the plugins getting excluded', () => {
const state = mockPluginState(
[mockPluginDefinition('DevicePlugin1')],
[mockPluginDefinition('ClientPlugin1')],
[[mockPluginDefinition('DevicePlugin2'), 'DevicePlugin2']],
);
const list = getActivePluginNames(state);
expect(list).toEqual(['ClientPlugin2']);
});
test('getActivePluginNames with the no plugins getting excluded', () => {
const state = mockPluginState([], [], []);
const list = getActivePluginNames(state);
expect(list).toEqual([
'ClientPlugin1',
'ClientPlugin2',
'DevicePlugin1',
'DevicePlugin2',
]);
});