dns.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /// <reference types="vite/client" />
  2. import { describe, expect, it } from 'vitest';
  3. import { DnsObjectSchema, DnsServerObjectSchema } from '@/schemas/dns';
  4. function fixtureName(path: string): string {
  5. const file = path.split('/').pop() ?? path;
  6. return file.replace(/\.json$/, '');
  7. }
  8. const dnsFixtures = import.meta.glob<unknown>(
  9. './golden/fixtures/dns/*.json',
  10. { eager: true, import: 'default' },
  11. );
  12. const serverFixtures = import.meta.glob<unknown>(
  13. './golden/fixtures/dns-server/*.json',
  14. { eager: true, import: 'default' },
  15. );
  16. describe('DnsObjectSchema fixtures', () => {
  17. const entries = Object.entries(dnsFixtures).sort(([a], [b]) => a.localeCompare(b));
  18. expect(entries.length, 'expected at least one fixture under golden/fixtures/dns').toBeGreaterThan(0);
  19. for (const [path, raw] of entries) {
  20. it(`parses ${fixtureName(path)} byte-stably`, () => {
  21. const parsed = DnsObjectSchema.parse(raw);
  22. expect(parsed).toMatchSnapshot();
  23. });
  24. }
  25. });
  26. describe('DnsServerObjectSchema fixtures', () => {
  27. const entries = Object.entries(serverFixtures).sort(([a], [b]) => a.localeCompare(b));
  28. expect(entries.length, 'expected at least one fixture under golden/fixtures/dns-server').toBeGreaterThan(0);
  29. for (const [path, raw] of entries) {
  30. it(`parses ${fixtureName(path)} byte-stably`, () => {
  31. const parsed = DnsServerObjectSchema.parse(raw);
  32. expect(parsed).toMatchSnapshot();
  33. });
  34. }
  35. });