Adding test converage for plugin loading
Summary: Adds test for the plugin reducer and dispatcher Reviewed By: jknoxville, passy Differential Revision: D13082652 fbshipit-source-id: 4af2c7721c4d88abbd332d610ff71d5db78e721c
This commit is contained in:
committed by
Facebook Github Bot
parent
1edc91512d
commit
0b43d219c3
71
src/reducers/__tests__/plugins.node.js
Normal file
71
src/reducers/__tests__/plugins.node.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* 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 {default as reducer, registerPlugins} from '../plugins';
|
||||
import {
|
||||
FlipperBasePlugin,
|
||||
FlipperPlugin,
|
||||
FlipperDevicePlugin,
|
||||
} from '../../plugin.js';
|
||||
|
||||
const testBasePlugin = class extends FlipperBasePlugin {
|
||||
static id = 'TestPlugin';
|
||||
};
|
||||
|
||||
const testPlugin = class extends FlipperPlugin {
|
||||
static id = 'TestPlugin';
|
||||
};
|
||||
|
||||
const testDevicePlugin = class extends FlipperDevicePlugin {
|
||||
static id = 'TestDevicePlugin';
|
||||
};
|
||||
|
||||
test('add clientPlugin', () => {
|
||||
const res = reducer(
|
||||
{
|
||||
devicePlugins: new Map(),
|
||||
clientPlugins: new Map(),
|
||||
},
|
||||
registerPlugins([testPlugin]),
|
||||
);
|
||||
expect(res.clientPlugins.get(testPlugin.id)).toBe(testPlugin);
|
||||
});
|
||||
|
||||
test('add devicePlugin', () => {
|
||||
const res = reducer(
|
||||
{
|
||||
devicePlugins: new Map(),
|
||||
clientPlugins: new Map(),
|
||||
},
|
||||
registerPlugins([testDevicePlugin]),
|
||||
);
|
||||
expect(res.devicePlugins.get(testDevicePlugin.id)).toBe(testDevicePlugin);
|
||||
});
|
||||
|
||||
test('do not add plugin twice', () => {
|
||||
const res = reducer(
|
||||
{
|
||||
devicePlugins: new Map(),
|
||||
clientPlugins: new Map(),
|
||||
},
|
||||
registerPlugins([testPlugin, testPlugin]),
|
||||
);
|
||||
expect(res.clientPlugins.size).toEqual(1);
|
||||
});
|
||||
|
||||
test('do not add other classes', () => {
|
||||
const res = reducer(
|
||||
{
|
||||
devicePlugins: new Map(),
|
||||
clientPlugins: new Map(),
|
||||
},
|
||||
// $FlowFixMe testing wrong classes on purpose here
|
||||
registerPlugins([testBasePlugin]),
|
||||
);
|
||||
expect(res.devicePlugins.size).toEqual(0);
|
||||
expect(res.devicePlugins.size).toEqual(0);
|
||||
});
|
||||
Reference in New Issue
Block a user