stream.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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>('./golden/fixtures/stream/*.json', {
  5. eager: true,
  6. 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(
  15. entries.length,
  16. 'expected at least one fixture under golden/fixtures/stream',
  17. ).toBeGreaterThan(0);
  18. for (const [path, raw] of entries) {
  19. it(`parses ${fixtureName(path)} byte-stably`, () => {
  20. const parsed = NetworkSettingsSchema.parse(raw);
  21. expect(parsed).toMatchSnapshot();
  22. });
  23. }
  24. });
  25. describe('NetworkSettingsSchema method alias', () => {
  26. it('folds xray-core v26.7.11 method alias back into network', () => {
  27. const parsed = NetworkSettingsSchema.parse({ method: 'ws', wsSettings: {} });
  28. expect((parsed as { network?: string }).network).toBe('ws');
  29. expect((parsed as Record<string, unknown>).method).toBeUndefined();
  30. });
  31. it('prefers method over network when both are present', () => {
  32. const parsed = NetworkSettingsSchema.parse({
  33. method: 'grpc',
  34. network: 'tcp',
  35. grpcSettings: {},
  36. });
  37. expect((parsed as { network?: string }).network).toBe('grpc');
  38. });
  39. });