Selectors
You can obtain information about plugins.
{
"name": "...",
"orion": {
"selectorsHelper": {
"selectorFactories": {
"consumes": {
"@orion/core": [
"existsPlugin",
"getAllPluginsName",
"getPlugin",
"getPluginProperty",
"isPluginOn",
"isPluginPrefersOn",
"getAllPluginsByPriority"
]
}
}
}
}
}
existsPlugin
Returns true if a plugin exists. It does not need to exist (is not added), returns false.
Usage
const existsPlugin = selectorsHelper.make('existsPlugin');
const result = existsPlugin(storeHelper.getState(), { pluginName });
-
pluginName: String
The name of the string to verify existence.
Returns
-
boolean
It returns true if the plugin exists, or false if not.

existsPlugin returns true if exists, false if not.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginExistsPlugin } from './PluginExistsPlugin.js';
test('existsPlugin returns true if exists, false if not', () => {
const example = addPluginExistsPlugin();
addPluginLog('plugin-log');
addPluginLog('plugin-stopped', { isOn: false });
expect(example.existsPlugin('plugin-log')).toBe(true);
expect(example.existsPlugin('plugin-stopped')).toBe(true);
expect(example.existsPlugin('plugin-existsplugin')).toBe(true);
expect(example.existsPlugin('plugin-fake')).toBe(false);
});
PluginExistsPlugin.js
import { addPlugin } from '@orion/core/test-utils';
const PluginExistsPluginPkg = {
name: 'plugin-existsplugin',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['existsPlugin'],
},
},
},
},
};
class PluginExistsPlugin {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._existsPlugin = selectorsHelper.make('existsPlugin');
}
existsPlugin(pluginName) {
return this._existsPlugin(this._storeHelper.getState(), { pluginName });
}
}
export function addPluginExistsPlugin() {
return addPlugin(PluginExistsPluginPkg, PluginExistsPlugin);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}
getAllPluginsName
Returns a list with the name of all plugins.
Usage
const getAllPluginsName = selectorsHelper.make('getAllPluginsName');
const result = getAllPluginsName(storeHelper.getState());
Returns
-
[string]
The list of all plugin names.

getAllPluginsName returns the list of plugin names.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginSelect } from './PluginSelect.js';
test('getAllPluginsName returns the list of plugin names', () => {
const example = addPluginSelect();
addPluginLog('plugin-log');
addPluginLog('plugin-stopped', { isOn: false });
expect(example.getAllPluginsName()).toEqual(['plugin-select', 'plugin-log', 'plugin-stopped']);
});
PluginSelect.js
import { addPlugin } from '@orion/core/test-utils';
const PluginSelectPkg = {
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['getAllPluginsName'],
},
},
},
},
};
class PluginSelect {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._getAllPluginsName = selectorsHelper.make('getAllPluginsName');
}
getAllPluginsName() {
return this._getAllPluginsName(this._storeHelper.getState());
}
}
export function addPluginSelect() {
return addPlugin(PluginSelectPkg, PluginSelect);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}
getPlugin
Returns the plugin metadata for a given plugin name.
Usage
const getPlugin = selectorsHelper.make('getPlugin');
const result = getPlugin(storeHelper.getState(), { pluginName });
-
pluginName: String
The name of the plugin to obtain the metadata
Returns
-
PluginMetadata | undefined
The object with the available plugin metadata.

getPlugin returns the plugin metadata or undefined if does not exist.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginSelect } from './PluginSelect.js';
test('getPlugin returns the plugin metadata or undefined if does not exists', () => {
const example = addPluginSelect();
addPluginLog('plugin-log');
addPluginLog('plugin-stopped', { isOn: false });
addPluginLog('plugin-withmeta', { path: './my-path/plugin.js' });
expect(example.getPlugin('plugin-log')).toMatchObject({
name: 'plugin-log',
version: '1.0.0',
isOn: true,
});
expect(example.getPlugin('plugin-stopped')).toMatchObject({
name: 'plugin-stopped',
version: '1.0.0',
isOn: false,
});
expect(example.getPlugin('plugin-log')).toMatchObject({
name: 'plugin-log',
version: '1.0.0',
isOn: true,
});
expect(example.getPlugin('plugin-withmeta')).toMatchObject({
name: 'plugin-withmeta',
path: './my-path/plugin.js',
});
expect(example.getPlugin('plugin-select')).toMatchObject({
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['getPlugin'],
},
},
},
},
});
expect(example.getPlugin('plugin-fake')).toBeUndefined();
});
PluginSelect.js
import { addPlugin } from '@orion/core/test-utils';
const PluginSelectPkg = {
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['getPlugin'],
},
},
},
},
};
class PluginSelect {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._getPlugin = selectorsHelper.make('getPlugin');
}
getPlugin(pluginName) {
return this._getPlugin(this._storeHelper.getState(), { pluginName });
}
}
export function addPluginSelect() {
return addPlugin(PluginSelectPkg, PluginSelect);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}
getPluginProperty
Returns a property of a plugin.
Usage
const getPluginProperty = selectorsHelper.make('getPluginProperty');
const result = getPluginProperty(storeHelper.getState(), { pluginName, property });
-
pluginName: String
The name of the plugin to obtain data
-
property: String
The name of the field to read
Returns
-
any
The corresponding value of the metadata property

getPluginProperty returns the plugin metadata property or undefined.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginSelect } from './PluginSelect.js';
test('getPluginProperty returns the plugin metadata property or undefined', () => {
const example = addPluginSelect();
addPluginLog('plugin-log');
addPluginLog('plugin-stopped', { isOn: false });
addPluginLog('plugin-withmeta', { path: './my-path/plugin.js' });
expect(example.getPluginProperty('plugin-log', 'name')).toBe('plugin-log');
expect(example.getPluginProperty('plugin-log', 'isOn')).toBe(true);
expect(example.getPluginProperty('plugin-stopped', 'isOn')).toBe(false);
expect(example.getPluginProperty('plugin-withmeta', 'path')).toBe('./my-path/plugin.js');
expect(example.getPluginProperty('plugin-fake', 'name')).toBeUndefined();
});
PluginSelect.js
import { addPlugin } from '@orion/core/test-utils';
const PluginSelectPkg = {
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['getPluginProperty'],
},
},
},
},
};
class PluginSelect {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._getPluginProperty = selectorsHelper.make('getPluginProperty');
}
getPluginProperty(pluginName, property) {
return this._getPluginProperty(this._storeHelper.getState(), { pluginName, property });
}
}
export function addPluginSelect() {
return addPlugin(PluginSelectPkg, PluginSelect);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}
isPluginOn
Returns if the given plugin is running.
Usage
const isPluginOn = selectorsHelper.make('isPluginOn');
const result = isPluginOn(storeHelper.getState(), { pluginName });
-
pluginName: String
The name of the plugin to query
Returns
-
boolean
It returns true if the plugin is running, false otherwise.

isPluginOn returns true if the plugin is running.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginSelect } from './PluginSelect.js';
test('isPluginOn returns true if the plugin is running', () => {
const example = addPluginSelect();
addPluginLog('plugin-log');
addPluginLog('plugin-stopped', { isOn: false });
expect(example.isPluginOn('plugin-log')).toBe(true);
expect(example.isPluginOn('plugin-stopped')).toBe(false);
expect(example.isPluginOn('plugin-select')).toBe(true);
expect(example.isPluginOn('plugin-fake')).toBe(false);
});
PluginSelect.js
import { addPlugin } from '@orion/core/test-utils';
const PluginSelectPkg = {
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['isPluginOn'],
},
},
},
},
};
class PluginSelect {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._isPluginOn = selectorsHelper.make('isPluginOn');
}
isPluginOn(pluginName) {
return this._isPluginOn(this._storeHelper.getState(), { pluginName });
}
}
export function addPluginSelect() {
return addPlugin(PluginSelectPkg, PluginSelect);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}
isPluginPrefersOn
It queries if a plugin prefers to be running or not, independently if it is running or not.
Usage
const isPluginPrefersOn = selectorsHelper.make('isPluginPrefersOn');
const result = isPluginPrefersOn(storeHelper.getState(), { pluginName });
-
pluginName: String
The name of the plugin to query
Returns
-
boolean
It returns true if the plugin prefers to be running, false otherwise

isPluginPrefersOn returns true if the plugin wants to be running.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginSelect } from './PluginSelect.js';
test('isPluginPrefersOn returns true if the plugin wants to be running', () => {
const example = addPluginSelect();
addPluginLog('plugin-stopped', { isOn: false });
addPluginLog('plugin-log', { pluginDependencies: { 'plugin-stopped': '^1.0.0' } });
expect(example.isPluginOn('plugin-stopped')).toBe(true);
expect(example.isPluginPrefersOn('plugin-stopped')).toBe(false);
expect(example.isPluginOn('plugin-log')).toBe(true);
expect(example.isPluginPrefersOn('plugin-log')).toBe(true);
expect(example.isPluginOn('plugin-select')).toBe(true);
expect(example.isPluginPrefersOn('plugin-select')).toBe(true);
expect(example.isPluginPrefersOn('plugin-fake')).toBe(false);
});
PluginSelect.js
import { addPlugin } from '@orion/core/test-utils';
const PluginSelectPkg = {
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['isPluginPrefersOn', 'isPluginOn'],
},
},
},
},
};
class PluginSelect {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._isPluginOn = selectorsHelper.make('isPluginOn');
this._isPluginPrefersOn = selectorsHelper.make('isPluginPrefersOn');
}
isPluginPrefersOn(pluginName) {
return this._isPluginPrefersOn(this._storeHelper.getState(), { pluginName });
}
isPluginOn(pluginName) {
return this._isPluginOn(this._storeHelper.getState(), { pluginName });
}
}
export function addPluginSelect() {
return addPlugin(PluginSelectPkg, PluginSelect);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}
getAllPluginsByPriority
Returns a list of all plugins metadata sorted by priority.
Usage
const getAllPluginsByPriority = selectorsHelper.make('getAllPluginsByPriority');
const result = getAllPluginsByPriority(storeHelper.getState());
Returns
-
[Metadata]
The list of all plugin metadata.

getAllPluginsByPriority returns the list of plugin metadata in priority order.
spec.js
import { addPluginLog } from './makePluginLog.js';
import { addPluginSelect } from './PluginSelect.js';
test('getAllPluginsByPriority returns the list of plugin metadata in priority order', () => {
const example = addPluginSelect();
addPluginLog('plugin-stopped', { isOn: false });
addPluginLog('plugin-log', { pluginDependencies: { 'plugin-stopped': '^1.0.0' } });
expect(example.getAllPluginsByPriority()).toMatchObject([
{ name: 'plugin-select', version: '1.0.0', isOn: true, priority: 1 },
{ name: 'plugin-stopped', version: '1.0.0', isOn: true, priority: 1 },
{ name: 'plugin-log', version: '1.0.0', isOn: true, priority: 2 },
]);
});
PluginSelect.js
import { addPlugin } from '@orion/core/test-utils';
const PluginSelectPkg = {
name: 'plugin-select',
version: '1.0.0',
orion: {
selectorsHelper: {
selectorFactories: {
consumes: {
'@orion/core': ['getAllPluginsByPriority'],
},
},
},
},
};
class PluginSelect {
constructor({ storeHelper, selectorsHelper }) {
this._storeHelper = storeHelper;
this._getAllPluginsByPriority = selectorsHelper.make('getAllPluginsByPriority');
}
getAllPluginsByPriority() {
return this._getAllPluginsByPriority(this._storeHelper.getState());
}
}
export function addPluginSelect() {
return addPlugin(PluginSelectPkg, PluginSelect);
}
makePluginLog.js
import { addPlugin } from '@orion/core/test-utils';
export const log = [];
function makePluginLog(name) {
return class PluginLog {
constructor() {
log.push(`Plugin ${name} started`);
}
onShutdown() {
log.push(`Plugin ${name} shutdown`);
}
};
}
export function addPluginLog(name, metadata) {
return addPlugin({ name, version: '1.0.0', ...metadata }, makePluginLog(name));
}