import { describe, expect, test } from 'bun:test'; function findUndefinedReads(files: [string, string][]) { const defined = new Set(); const required = new Map(); for (const [path, source] of files) { const definitions = /\.s?css$/.test(path) ? [/(? !defined.has(name)); } describe('CSS custom properties', () => { test('allows optional properties but checks required reads inside fallbacks', () => { expect( findUndefinedReads([ [ 'a.css', 'a { color: var(--optional, currentColor); background: var(--bg, var(--missing)); }', ], ]) ).toEqual([['--missing', 'a.css']]); }); test('counts runtime writes but not reads or removals as definitions', () => { expect( findUndefinedReads([ [ 'a.scss', 'a { --local: red; color: var(--local); padding: var(--inline); top: var(--set); left: var(--typo); }', ], [ 'a.tsx', `const style = { '--inline': 1 }; el.style.setProperty('--set', '0'); el.style.getPropertyValue('--typo'); el.style.removeProperty('--typo');`, ], ]) ).toEqual([['--typo', 'a.scss']]); }); test('required var() reads in src have definitions', async () => { const files: [string, string][] = []; for await (const path of new Bun.Glob('src/**/*.{scss,css,ts,tsx}').scan('.')) { files.push([path, await Bun.file(path).text()]); } expect(findUndefinedReads(files)).toEqual([]); }); });