-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Plugin loader should prioritize new plugin format, when availab…
…le (#1846) We should be able to use both new and legacy plugin format in the same module, and plugin loader should prioritize the new format.
- Loading branch information
Showing
4 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { LegacyPlugin, Plugin, PluginType } from '@deephaven/plugin'; | ||
import { getPluginModuleValue } from './PluginUtils'; | ||
|
||
describe('getPluginModuleValue', () => { | ||
const legacyPlugins: [type: string, moduleValue: LegacyPlugin][] = [ | ||
[ | ||
'dashboard', | ||
{ | ||
DashboardPlugin: () => null, | ||
}, | ||
], | ||
[ | ||
'auth', | ||
{ | ||
AuthPlugin: { | ||
Component: () => null, | ||
isAvailable: () => true, | ||
}, | ||
}, | ||
], | ||
[ | ||
'table', | ||
{ | ||
TablePlugin: () => null, | ||
}, | ||
], | ||
]; | ||
|
||
const newPlugins: [type: string, moduleValue: Plugin][] = Object.keys( | ||
PluginType | ||
).map(type => [type, { name: `${type}`, type: PluginType[type] }]); | ||
|
||
const newPluginsWithNamedExports: [ | ||
type: string, | ||
moduleValue: { default: Plugin; [key: string]: unknown }, | ||
][] = Object.keys(PluginType).map(type => [ | ||
type, | ||
{ | ||
default: { name: `${type}Plugin`, type: PluginType[type] }, | ||
NamedExport: 'NamedExportValue', | ||
}, | ||
]); | ||
|
||
const combinedPlugins: [ | ||
type: string, | ||
moduleValue: { | ||
default: Plugin; | ||
} & LegacyPlugin, | ||
][] = [ | ||
[ | ||
'dashboard', | ||
{ | ||
default: { | ||
name: 'combinedFormat1', | ||
type: PluginType.DASHBOARD_PLUGIN, | ||
}, | ||
DashboardPlugin: () => null, | ||
}, | ||
], | ||
[ | ||
'auth', | ||
{ | ||
default: { | ||
name: 'combinedFormat2', | ||
type: PluginType.AUTH_PLUGIN, | ||
}, | ||
AuthPlugin: { | ||
Component: () => null, | ||
isAvailable: () => true, | ||
}, | ||
}, | ||
], | ||
[ | ||
'table', | ||
{ | ||
default: { | ||
name: 'combinedFormat3', | ||
type: PluginType.TABLE_PLUGIN, | ||
}, | ||
TablePlugin: () => null, | ||
}, | ||
], | ||
[ | ||
// Should be able to combine different plugin types | ||
'multiple', | ||
{ | ||
default: { | ||
name: 'widgetPlugin', | ||
type: PluginType.WIDGET_PLUGIN, | ||
}, | ||
DashboardPlugin: () => null, | ||
}, | ||
], | ||
]; | ||
|
||
it.each(legacyPlugins)( | ||
'supports legacy %s plugin format', | ||
(type, legacyPlugin) => { | ||
const moduleValue = getPluginModuleValue(legacyPlugin); | ||
expect(moduleValue).toBe(legacyPlugin); | ||
} | ||
); | ||
|
||
it.each(newPlugins)('supports new %s format', (type, plugin) => { | ||
const moduleValue = getPluginModuleValue(plugin); | ||
expect(moduleValue).toBe(plugin); | ||
}); | ||
|
||
it.each(newPluginsWithNamedExports)( | ||
'supports new %s format with named exports', | ||
(type, plugin) => { | ||
const moduleValue = getPluginModuleValue(plugin); | ||
expect(moduleValue).toBe(plugin.default); | ||
} | ||
); | ||
|
||
it.each(combinedPlugins)( | ||
'prioritizes new %s plugin if the module contains both legacy and new format', | ||
(type, plugin) => { | ||
const moduleValue = getPluginModuleValue(plugin); | ||
expect(moduleValue).toBe(plugin.default); | ||
} | ||
); | ||
|
||
it('returns null if the module value is not a plugin', () => { | ||
const moduleValue = getPluginModuleValue({} as Plugin); | ||
expect(moduleValue).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters