|
| 1 | +/** |
| 2 | + * @jest-environment node |
| 3 | + * |
| 4 | + */ |
| 5 | + |
| 6 | +import fetch from 'cross-fetch'; |
| 7 | +(global as any).fetch = fetch; |
| 8 | +import fs from 'fs/promises'; |
| 9 | + |
| 10 | +const BENCHMARKS_URL = process.env.BENCHMARKS_URL || 'https://roll20.github.io/detect-gpu'; |
| 11 | +const TEST_FILE = 'd-apple.json'; |
| 12 | + |
| 13 | +interface ScreenEntry extends Array<number> { |
| 14 | + 0: number; |
| 15 | + 1: number; |
| 16 | + 2: number; |
| 17 | +} |
| 18 | + |
| 19 | +describe('Live benchmark data shape', () => { |
| 20 | + let data: unknown; |
| 21 | + |
| 22 | + beforeAll(async () => { |
| 23 | + const base = BENCHMARKS_URL.replace(/\/$/, ''); |
| 24 | + if (base.startsWith('file://')) { |
| 25 | + const dirPath = base.replace(/^file:\/\//, ''); |
| 26 | + const raw = await fs.readFile(`${dirPath}/${TEST_FILE}`, 'utf8'); |
| 27 | + data = JSON.parse(raw); |
| 28 | + } else { |
| 29 | + const res = await fetch(`${base}/${TEST_FILE}`); |
| 30 | + expect(res.ok).toBe(true); |
| 31 | + data = await res.json(); |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + it('is an array with a version string at index 0', () => { |
| 36 | + expect(Array.isArray(data)).toBe(true); |
| 37 | + expect(typeof (data as any)[0]).toBe('string'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('each entry has the correct tuple shape', () => { |
| 41 | + const entries = (data as any).slice(1); |
| 42 | + expect(entries.length).toBeGreaterThan(0); |
| 43 | + |
| 44 | + for (const entry of entries) { |
| 45 | + expect(Array.isArray(entry)).toBe(true); |
| 46 | + expect([4, 5]).toContain(entry.length); |
| 47 | + |
| 48 | + const screens = entry[entry.length - 1]; |
| 49 | + expect(Array.isArray(screens)).toBe(true); |
| 50 | + expect(screens.length).toBeGreaterThan(0); |
| 51 | + |
| 52 | + for (const screen of screens) { |
| 53 | + expect(Array.isArray(screen)).toBe(true); |
| 54 | + expect((screen as ScreenEntry).length).toBe(3); |
| 55 | + |
| 56 | + const [w, h, fps] = screen as ScreenEntry; |
| 57 | + expect(typeof w).toBe('number'); |
| 58 | + expect(typeof h).toBe('number'); |
| 59 | + expect(typeof fps).toBe('number'); |
| 60 | + } |
| 61 | + } |
| 62 | + }); |
| 63 | +}); |
0 commit comments