刘光辉
11 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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',
    });
  });
});