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
+55 -15
View File
@@ -1,17 +1,44 @@
import { describe, expect, it } from 'vitest';
import { betaSelectionHref, canTest, mapLabel, parseBetaSelection, scriptStatus, type LibraryScript } from '../../src/lib/script-library.js';
import {
betaSelectionHref,
canTest,
mapLabel,
parseBetaSelection,
scriptStatus,
type LibraryScript
} from '../../src/lib/script-library.js';
const script: LibraryScript = {
id: 1, name: 'HUD', target_rel_path: 'hud.gsc', scope_type: null, scope_value: null,
current_version_id: null, currentVersion: null, versionCount: 1, servers: [], runningBetaId: null,
latestVersion: { id: 10, version: 1, sha256: 'abc', size: 12, state: 'untested', uploaded_at: '2026-09-18' }
id: 1,
name: 'HUD',
target_rel_path: 'hud.gsc',
scope_type: null,
scope_value: null,
current_version_id: null,
currentVersion: null,
versionCount: 1,
servers: [],
runningBetaId: null,
latestVersion: {
id: 10,
version: 1,
sha256: 'abc',
size: 12,
state: 'untested',
uploaded_at: '2026-09-18'
}
};
describe('script library state', () => {
it.each([['untested', 'untested'], ['tested', 'tested'], ['test-failed', 'failed']] as const)(
'preserves %s for a never-promoted version', (state, expected) => {
expect(scriptStatus({ ...script, latestVersion: { ...script.latestVersion!, state } })).toBe(expected);
});
it.each([
['untested', 'untested'],
['tested', 'tested'],
['test-failed', 'failed']
] as const)('preserves %s for a never-promoted version', (state, expected) => {
expect(
scriptStatus({ ...script, latestVersion: { ...script.latestVersion!, state } })
).toBe(expected);
});
it('distinguishes an active beta, a promoted release, and a newer upload', () => {
expect(scriptStatus({ ...script, runningBetaId: 5 })).toBe('testing');
expect(canTest({ ...script, runningBetaId: 5 })).toBe(false);
@@ -30,14 +57,27 @@ describe('script library state', () => {
describe('beta selection links', () => {
it('round-trips exact versions in a multi-script selection', () => {
const picks = [{ scriptId: 4, versionId: 20 }, { scriptId: 7, versionId: 25 }];
expect(parseBetaSelection(new URL(betaSelectionHref(picks), 'http://localhost').searchParams)).toEqual(picks);
const picks = [
{ scriptId: 4, versionId: 20 },
{ scriptId: 7, versionId: 25 }
];
expect(
parseBetaSelection(new URL(betaSelectionHref(picks), 'http://localhost').searchParams)
).toEqual(picks);
});
it('preserves existing plugin import links', () => {
expect(parseBetaSelection(new URLSearchParams('pluginId=8&versionId=32'))).toEqual([{ scriptId: 8, versionId: 32 }]);
expect(parseBetaSelection(new URLSearchParams('pluginId=8&versionId=32'))).toEqual([
{ scriptId: 8, versionId: 32 }
]);
});
it.each([
'artifact=0:1',
'artifact=1:NaN',
'artifact=1:2junk',
'artifact=1:2&artifact=1:3',
'artifact=9007199254740992:1',
'pluginId=8'
])('rejects malformed or ambiguous selections: %s', (query) => {
expect(() => parseBetaSelection(new URLSearchParams(query))).toThrow();
});
it.each(['artifact=0:1', 'artifact=1:NaN', 'artifact=1:2junk', 'artifact=1:2&artifact=1:3', 'artifact=9007199254740992:1', 'pluginId=8'])(
'rejects malformed or ambiguous selections: %s', query => {
expect(() => parseBetaSelection(new URLSearchParams(query))).toThrow();
});
});