Files
markdown-converter/tests/format-registry.test.js
T
amitwh d6baa2daf7 feat(plugins): add export-format registration hook to plugin API
Add context.formats.registerExportFormat(id, opts) to PluginContext,
backed by a new FormatRegistry (mirrors PluginRegistry's Map-based
shape). Plugins register namespaced (${pluginId}:${id}) export
formats with a label/extension/handler; the writing-studio built-in
plugin registers a trivial "sprint-summary" .txt export as a
worked example.

The plugin system lives entirely in the renderer process while the
Export menu is built in main.js, so wiring formats into the menu
required a small IPC round-trip: renderer sends format metadata to
main after plugin load (main rebuilds the menu via the already-
idempotent createMenu()), and a menu click sends the resolved save
path back to the renderer, which is the only process holding the
plugin's handler function.

Amit Haridas
2026-08-23 19:31:33 +05:30

40 lines
1.4 KiB
JavaScript

const { FormatRegistry } = require('../src/plugins/format-registry');
describe('FormatRegistry', () => {
let registry;
beforeEach(() => {
registry = new FormatRegistry();
});
test('register — stores an entry retrievable by id', () => {
const handler = jest.fn();
registry.register('plugin-a:fmt', { label: 'Format A', extension: 'txt', handler });
const entry = registry.get('plugin-a:fmt');
expect(entry).toEqual({ label: 'Format A', extension: 'txt', handler });
});
test('get — returns undefined for unknown id', () => {
expect(registry.get('nope')).toBeUndefined();
});
test('register — overwrites an existing id', () => {
registry.register('plugin-a:fmt', { label: 'First' });
registry.register('plugin-a:fmt', { label: 'Second' });
expect(registry.get('plugin-a:fmt').label).toBe('Second');
});
test('getAll — returns all entries with id merged in', () => {
registry.register('plugin-a:fmt', { label: 'Format A', extension: 'txt' });
registry.register('plugin-b:fmt', { label: 'Format B', extension: 'csv' });
const all = registry.getAll();
expect(all).toHaveLength(2);
expect(all).toContainEqual({ id: 'plugin-a:fmt', label: 'Format A', extension: 'txt' });
expect(all).toContainEqual({ id: 'plugin-b:fmt', label: 'Format B', extension: 'csv' });
});
test('getAll — returns empty array when nothing registered', () => {
expect(registry.getAll()).toEqual([]);
});
});