Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132import { afterEach, describe, expect, test } from 'bun:test';import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';import { loadThemeFiles, parseThemeToml, resolveThemeDir } from '../src/daemon/theme-loader';
const roots: string[] = [];afterEach(async () => { await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true }))); });
describe('installed web themes', () => { test('resolves the XDG config theme directory', () => { expect(resolveThemeDir({ XDG_CONFIG_HOME: '/cfg' })).toBe(join('/cfg', 'shard', 'themes')); });
test('loads JSON and TOML files in stable order and skips malformed files', async () => { const root = await mkdtemp(join(tmpdir(), 'shard-themes-')); roots.push(root); await mkdir(root, { recursive: true }); await writeFile(join(root, 'a.json'), JSON.stringify({ id: 'a', name: 'A', light: {}, dark: {} })); await writeFile(join(root, 'b.toml'), 'id = "b"\nname = "B"\n[light]\ncanvas = "#ffffff"\n[dark]\ncanvas = "#000000"\n'); await writeFile(join(root, 'broken.toml'), '[unknown]\nx = "y"'); await writeFile(join(root, '.hidden.json'), '{}'); expect(await loadThemeFiles(root)).toEqual([ { id: 'a', name: 'A', light: {}, dark: {} }, { id: 'b', name: 'B', light: { canvas: '#ffffff' }, dark: { canvas: '#000000' } }, ]); });
test('TOML parser handles comments and escaped strings', () => { expect(parseThemeToml('name = "Nord \\"Snow\\"" # comment\n[light]\ncanvas = "#eceff4"')).toEqual({ name: 'Nord "Snow"', light: { canvas: '#eceff4' } }); });});