stream.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /// <reference types="vite/client" />
  2. import { describe, expect, it } from 'vitest';
  3. import { NetworkSettingsSchema } from '@/schemas/protocols';
  4. const streamFixtures = import.meta.glob<unknown>(
  5. './golden/fixtures/stream/*.json',
  6. { eager: true, import: 'default' },
  7. );
  8. function fixtureName(path: string): string {
  9. const file = path.split('/').pop() ?? path;
  10. return file.replace(/\.json$/, '');
  11. }
  12. describe('NetworkSettingsSchema fixtures', () => {
  13. const entries = Object.entries(streamFixtures).sort(([a], [b]) => a.localeCompare(b));
  14. expect(entries.length, 'expected at least one fixture under golden/fixtures/stream').toBeGreaterThan(0);
  15. for (const [path, raw] of entries) {
  16. it(`parses ${fixtureName(path)} byte-stably`, () => {
  17. const parsed = NetworkSettingsSchema.parse(raw);
  18. expect(parsed).toMatchSnapshot();
  19. });
  20. }
  21. });
  22. describe('NetworkSettingsSchema method alias', () => {
  23. it('folds xray-core v26.7.11 method alias back into network', () => {
  24. const parsed = NetworkSettingsSchema.parse({ method: 'ws', wsSettings: {} });
  25. expect((parsed as { network?: string }).network).toBe('ws');
  26. expect((parsed as Record<string, unknown>).method).toBeUndefined();
  27. });
  28. it('prefers method over network when both are present', () => {
  29. const parsed = NetworkSettingsSchema.parse({ method: 'grpc', network: 'tcp', grpcSettings: {} });
  30. expect((parsed as { network?: string }).network).toBe('grpc');
  31. });
  32. });