Move the tests from scripts/ to tests/ by feature

Unit tests go to tests/unit/<area>/, browser smoke tests to
tests/smoke/<area>/, and tests against a running desktop app to
tests/native/. Files named after dates, work passes, or Kanban cards get
feature names, for example editorOctober12 -> editor/footnotes.

scripts/ keeps the build, release, and package tools. Plugin repositories
import scripts/packagePlugin.mjs, and the Terminal smoke test imports
scripts/pluginMocks.mjs, which now re-exports the harness copy.

The unit tests get their own type check (tests/tsconfig.json) with Node
types. pnpm check runs it after the app check. Add @types/node and fix
the three test mocks that it reported.
This commit is contained in:
Knotty Wyvern
2026-10-27 19:47:39 -07:00
parent 90d1940c73
commit e433bed28e
154 changed files with 269 additions and 227 deletions
+40
View File
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { CHARACTER_THEMES, SYNTAX_ROLES } from '../../../src/lib/theme/characterThemes.ts';
const rgb = (hex: string) => hex.match(/[0-9a-f]{2}/gi)!.map(channel => parseInt(channel, 16));
const luminance = (hex: string) => rgb(hex).map(channel => channel / 255)
.map(channel => channel <= .04045 ? channel / 12.92 : ((channel + .055) / 1.055) ** 2.4)
.reduce((sum, channel, index) => sum + channel * [.2126, .7152, .0722][index], 0);
const contrast = (a: string, b: string) => (Math.max(luminance(a), luminance(b)) + .05) / (Math.min(luminance(a), luminance(b)) + .05);
const mix = (a: string, b: string, ratio: number) => '#' + rgb(a)
.map((channel, index) => Math.round(channel * ratio + rgb(b)[index] * (1 - ratio)).toString(16).padStart(2, '0')).join('');
test('Silver Serpent text and syntax remain readable on opaque and image surfaces', () => {
const { surfaces, syntax, secondary } = CHARACTER_THEMES['silver-serpent'];
const [bg, elevated, active, , dim, text, strong, accent, selection] = surfaces;
const panelOnWhite = mix(elevated, '#ffffff', .82);
const editorOnWhite = mix(bg, '#ffffff', .9);
const backgrounds = {
bg, elevated, active, selection,
panelOnWhite,
editorOnWhite,
menuHoverOnWhite: mix(active, panelOnWhite, .82),
controlHoverOnWhite: mix(active, '#ffffff', .92),
codeBlockOnWhite: mix(elevated, editorOnWhite, .82),
};
const foregrounds = { dim, text, strong, accent, secondary,
...Object.fromEntries(SYNTAX_ROLES.map((role, index) => [`syntax-${role}`, syntax[index]])) };
for (const [backgroundName, background] of Object.entries(backgrounds)) {
for (const [foregroundName, foreground] of Object.entries(foregrounds)) {
assert(contrast(foreground, background) >= 4.5, `${foregroundName} on ${backgroundName}`);
}
}
});
test('Silver Serpent selection has a readable perimeter and a separate fill', () => {
const [bg, elevated, , , , , , accent, selection] = CHARACTER_THEMES['silver-serpent'].surfaces;
assert(contrast(accent, selection) >= 3, 'selection perimeter');
assert(contrast(selection, bg) >= 1.5, 'selection against the editor');
assert(contrast(selection, elevated) >= 1.5, 'selection against a panel');
});