Add Prettier and ESLint tooling (Refs #77)

This commit is contained in:
2026-10-09 15:56:13 -04:00
parent 8ed059b8d3
commit 16469e2d43
711 changed files with 99737 additions and 28286 deletions
+48 -18
View File
@@ -6,25 +6,44 @@ import ServerCard from '../../src/lib/ui/components/ServerCard.svelte';
import { telemetryByServer, uiNow } from '../../src/lib/ui/stores/servers.js';
import { gameEvent } from '../helpers/telemetry.js';
vi.mock('$app/stores', () => ({ page: writable({ url: new URL('http://localhost/?filter=occupied') }) }));
vi.mock('$app/stores', () => ({
page: writable({ url: new URL('http://localhost/?filter=occupied') })
}));
const name = 't5_zombie_theater_1';
const at = (age: number) => new Date(get(uiNow) - age).toISOString();
const telemetry = (round = 31, age = 1000) => ({ ...gameEvent('heartbeat', round, 4, name), receivedAt: at(age) });
const telemetry = (round = 31, age = 1000) => ({
...gameEvent('heartbeat', round, 4, name),
receivedAt: at(age)
});
function html(props: Partial<ComponentProps<typeof ServerCard>> = {}) {
return render(ServerCard, { props: { name, health: 'online', players: 4, capacity: 4,
telemetry: telemetry(), gameStartedAt: at(6_000_000), ...props } }).body.replaceAll(/<!--.*?-->/g, '');
return render(ServerCard, {
props: {
name,
health: 'online',
players: 4,
capacity: 4,
telemetry: telemetry(),
gameStartedAt: at(6_000_000),
...props
}
}).body.replaceAll(/<!--.*?-->/g, '');
}
afterEach(() => telemetryByServer.set(new Map()));
describe('compact server cards', () => {
it('leads with identity and three labelled metrics, without healthy freshness or duplicate activity clocks', () => {
const body = html({ gametype: 'zom', activeSince: at(6_120_000), lastSeenAt: at(1000), longestMatch: true });
const body = html({
gametype: 'zom',
activeSince: at(6_120_000),
lastSeenAt: at(1000),
longestMatch: true
});
expect(body).toContain('Kino Der Toten');
expect(body).toContain('Lobby 1');
expect(body).toContain('BO1');
expect(body).toMatch(/<dt[^>]*>Players<\/dt><dd[^>]*>4<span[^>]*>\/4<\/span><\/dd>/);
expect(body).toMatch(/<dt[^>]*>Round<\/dt><dd[^>]*>31<\/dd>/);
expect(body).toMatch(/<dt[^>]*>Match time<\/dt><dd[^>]*>1h 40m<\/dd>/);
expect(body).toMatch(/<dt[^>]*>Players<\/dt>\s*<dd[^>]*>4<span[^>]*>\/4<\/span><\/dd>/);
expect(body).toMatch(/<dt[^>]*>Round<\/dt>\s*<dd[^>]*>31<\/dd>/);
expect(body).toMatch(/<dt[^>]*>Match time<\/dt>\s*<dd[^>]*>1h 40m<\/dd>/);
expect(body).toContain('Longest match');
expect(body).not.toMatch(/Last seen|Last reported|Zombies Classic|>Active</);
});
@@ -41,21 +60,27 @@ describe('compact server cards', () => {
it('uses the newest fresh report while respecting explicit round data and match boundaries', () => {
telemetryByServer.set(new Map([[name, telemetry(35, 1000)]]));
expect(html({ telemetry: telemetry(31, 10_000) })).toMatch(/<dt[^>]*>Round<\/dt><dd[^>]*>35<\/dd>/);
expect(html({ round: 40 })).toMatch(/<dt[^>]*>Round<\/dt><dd[^>]*>40<\/dd>/);
expect(html({ round: null })).toMatch(/<dt[^>]*>Round<\/dt><dd[^>]*>—<\/dd>/);
expect(html({ gameStartedAt: at(0) })).toMatch(/<dt[^>]*>Round<\/dt><dd[^>]*>—<\/dd>/);
expect(html({ telemetry: telemetry(31, 10_000) })).toMatch(
/<dt[^>]*>Round<\/dt>\s*<dd[^>]*>35<\/dd>/
);
expect(html({ round: 40 })).toMatch(/<dt[^>]*>Round<\/dt>\s*<dd[^>]*>40<\/dd>/);
expect(html({ round: null })).toMatch(/<dt[^>]*>Round<\/dt>\s*<dd[^>]*>—<\/dd>/);
expect(html({ gameStartedAt: at(0) })).toMatch(/<dt[^>]*>Round<\/dt>\s*<dd[^>]*>—<\/dd>/);
telemetryByServer.set(new Map());
expect(html({ telemetry: telemetry(31, 100_000) })).toMatch(/<dt[^>]*>Round<\/dt><dd[^>]*>—<\/dd>/);
expect(html({ telemetry: telemetry(31, 100_000) })).toMatch(
/<dt[^>]*>Round<\/dt>\s*<dd[^>]*>—<\/dd>/
);
expect(html({ gameEndedAt: at(1000), round: 40 })).toContain('Match ended');
expect(html({ gameEndedAt: at(1000), round: 40 })).not.toMatch(/<dd[^>]*>40<\/dd>/);
});
it('gives the roster real column headers and formatted scores without repeating ping units', () => {
const body = html({ roster: [
{ num: 0, guid: 'one', name: 'Vexx', score: 99170, ping: 36 },
{ num: 1, guid: 'two', name: 'Connecting player', score: null, ping: 999 }
] });
const body = html({
roster: [
{ num: 0, guid: 'one', name: 'Vexx', score: 99170, ping: 36 },
{ num: 1, guid: 'two', name: 'Connecting player', score: null, ping: 999 }
]
});
expect(body).toContain('aria-label="Current players"');
expect(body).toMatch(/<th[^>]*scope="col"[^>]*>Player<\/th>/);
expect(body).toContain('99,170');
@@ -73,7 +98,12 @@ describe('compact server cards', () => {
});
it('collapses empty healthy lobbies to readiness and empty duration', () => {
const body = html({ players: 0, inactiveSince: at(9 * 60_000), roster: [], compactEmpty: true });
const body = html({
players: 0,
inactiveSince: at(9 * 60_000),
roster: [],
compactEmpty: true
});
expect(body).toContain('Ready');
expect(body).toContain('Empty for 9m 00s');
expect(body).not.toContain('<dl');