import { describe, expect, test } from 'vitest'; import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; import { findCss, findRawText, findTailwind, scan } from './check-tint-contrast.js'; const web = resolve(dirname(fileURLToPath(import.meta.url)), '..'); describe('hue-on-own-tint check (#3150)', () => { test('no source paints a hue as text on a tint of itself', () => { expect(scan(resolve(web, 'src'), web)).toEqual([]); }); describe('Tailwind', () => { test('finds text-X on bg-X-tint and bg-X/NN in one class string', () => { expect(findTailwind(`class="rounded bg-accent-tint px-2 text-accent"`)).toHaveLength(1); expect(findTailwind(`'bg-error/15 text-error'`)).toHaveLength(1); expect(findTailwind("`bg-moss/10 text-moss`")[0].fix).toBe('text-success-fg'); }); test('a class string spanning lines is one string', () => { expect(findTailwind(`class="bg-accent-tint\n text-accent"`)).toHaveLength(1); }); test('an apostrophe earlier in the file does not hide a pair', () => { expect( findTailwind(`
Couldn't add
\n`) ).toHaveLength(1); }); test('passes the -fg partner, another hue, and a tint with no hue text', () => { expect(findTailwind(`"bg-accent-tint text-accent-fg"`)).toEqual([]); expect(findTailwind(`"bg-accent-tint text-error"`)).toEqual([]); expect(findTailwind(`"bg-accent-tint text-text-primary"`)).toEqual([]); expect(findTailwind(`"text-accent"`)).toEqual([]); }); }); describe('raw error text, on any surface', () => { test('finds text-error, class:text-error and color: var(--fs-error)', () => { expect(findRawText(`x
`)).toHaveLength(1); expect(findRawText(`x
`)).toEqual([]); expect(findRawText(`