import { readFileSync } from 'node:fs';
|
import { resolve } from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { createGatewayConfig, createPluginEnvironment } from '../src/gateway.mjs';
|
import { parseRegistry } from '../src/registry.mjs';
|
|
const registry = parseRegistry(readFileSync(resolve(import.meta.dirname, '../../registry.yaml'), 'utf8'));
|
|
describe('ONLYOFFICE development gateway', () => {
|
it('creates plugin HTTP/WebSocket and SDK proxies without unused root HMR routes', () => {
|
const config = createGatewayConfig(registry, { host: '0.0.0.0', port: 4173 });
|
|
expect(config.server).toMatchObject({ host: '0.0.0.0', port: 4173, strictPort: true });
|
expect(config.server).toBeDefined();
|
expect(config.server!.proxy).toMatchObject({
|
'/onlyoffice-plugins/0.1.0-dev/eln-template-annotator': { target: 'http://127.0.0.1:4181', ws: true },
|
'/onlyoffice-plugins/0.1.0-dev/eln-template-filler': { target: 'http://127.0.0.1:4182', ws: true },
|
'/onlyoffice-sdk': { target: 'http://127.0.0.1:4181' },
|
});
|
expect(config.server!.proxy).not.toHaveProperty('/__hmr/eln-template-annotator');
|
expect(config.server!.proxy).not.toHaveProperty('/__hmr/eln-template-filler');
|
});
|
|
it('builds an internal-only plugin environment with gateway HMR coordinates', () => {
|
const plugin = registry.plugins[1]!;
|
|
expect(createPluginEnvironment(plugin, { gatewayPort: 4173, publicHost: 'localhost' })).toMatchObject({
|
ONLYOFFICE_PLUGIN_DEV_HOST: '127.0.0.1',
|
ONLYOFFICE_PLUGIN_DEV_PORT: '4182',
|
ONLYOFFICE_PLUGIN_HMR_CLIENT_PORT: '4173',
|
ONLYOFFICE_PLUGIN_HMR_HOST: 'localhost',
|
ONLYOFFICE_PLUGIN_HMR_PATH: '/__hmr/eln-template-filler',
|
ONLYOFFICE_PLUGIN_PUBLIC_HOST: 'localhost',
|
});
|
});
|
});
|