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.
45 lines
2.3 KiB
TypeScript
45 lines
2.3 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { characterTheme, SYNTAX_ROLES } from '../../../src/lib/theme/characterThemes.ts';
|
|
|
|
const rgb = (color: string) => color.slice(1).match(/../g)!.map(value => parseInt(value, 16));
|
|
const mix = (foreground: string, background: string, opacity: number) => '#' + rgb(foreground)
|
|
.map((value, index) => Math.round(value * opacity + rgb(background)[index] * (1 - opacity)).toString(16).padStart(2, '0')).join('');
|
|
function luminance(color: string) {
|
|
return rgb(color).map(value => value / 255)
|
|
.map(value => value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4)
|
|
.reduce((sum, value, index) => sum + value * [0.2126, 0.7152, 0.0722][index], 0);
|
|
}
|
|
function contrast(foreground: string, background: string) {
|
|
const [high, low] = [luminance(foreground), luminance(background)].sort((a, b) => b - a);
|
|
return (high + 0.05) / (low + 0.05);
|
|
}
|
|
|
|
test('Crimson Pilot text and syntax remain readable in active and selected states', () => {
|
|
const palette = characterTheme('crimson-pilot')!;
|
|
const [background, elevated, active, , dim, text, strong, accent, selection] = palette.surfaces;
|
|
const foregrounds = { dim, text, strong, accent, secondary: palette.secondary,
|
|
...Object.fromEntries(SYNTAX_ROLES.map((role, index) => [`syntax-${role}`, palette.syntax[index]])) };
|
|
for (const [role, foreground] of Object.entries(foregrounds)) {
|
|
for (const surface of [background, elevated, active, selection]) {
|
|
assert(contrast(foreground, surface) >= 4.5, `${role} on ${surface} needs 4.5:1 contrast`);
|
|
}
|
|
}
|
|
});
|
|
|
|
test('Crimson Pilot text remains readable on image-tinted editor and panel surfaces', () => {
|
|
const palette = characterTheme('crimson-pilot')!;
|
|
const [background, elevated, , , dim, text, strong] = palette.surfaces;
|
|
const editor = mix(background, '#ffffff', 0.9);
|
|
const codeBlock = mix(elevated, editor, 0.82);
|
|
const panel = mix(elevated, '#ffffff', 0.82);
|
|
for (const foreground of palette.syntax) {
|
|
for (const surface of [editor, codeBlock]) {
|
|
assert(contrast(foreground, surface) >= 4.5, `${foreground} on ${surface} needs 4.5:1 contrast`);
|
|
}
|
|
}
|
|
for (const foreground of [dim, text, strong]) {
|
|
assert(contrast(foreground, panel) >= 4.5, `${foreground} on image panel ${panel} needs 4.5:1 contrast`);
|
|
}
|
|
});
|