test: Count Derived Scrim Tokens as Theme-Owned (#16512)

The stylesheet-ownership check added in #16480 required every declared
color token to be a theme key of its own, so the scrim tokens from #16492,
which compose the surface-overlay role with a scrim opacity role, failed it
once both landed on canary. A token is now owned when a variable its value
reads is one a theme can set.
This commit is contained in:
Marco Beretta 2026-09-29 18:18:49 +02:00 • committed by GitHub
parent 364bf27210
commit 75bb1899fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,11 +11,15 @@ globalThis.structuredClone ??= <T>(value: T): T => deserialize(serialize(value))
const tokensPath = path.resolve(__dirname, 'tokens.css');
const tokens = fs.readFileSync(tokensPath, 'utf8');
const declared = new Set(
Array.from(tokens.matchAll(/--color-([\w-]+):/g), (match) => match[1]).filter(
(name) => !name.endsWith('*'),
),
/** Each declared color token, mapped to the custom properties its value reads. */
const declarations = new Map(
Array.from(
tokens.matchAll(/--color-([\w-]+):([^;]+);/g),
([, name, value]) =>
[name, Array.from(value.matchAll(/var\(--([\w-]+)/g), (match) => match[1])] as const,
).filter(([name]) => !name.endsWith('*')),
);
const declared = new Set(declarations.keys());
/**
* Theme properties consumed by stylesheets rather than by utilities: the shimmer animation and
@ -70,7 +74,9 @@ describe('theme color tokens', () => {
it('lets a theme set every color token the stylesheet declares', () => {
const registered = new Set(Object.keys(defaultTheme).map((key) => key.replace(/^rgb-/, '')));
const unowned = [...declared].filter((token) => !registered.has(token));
const unowned = [...declarations]
.filter(([, reads]) => !reads.some((property) => registered.has(property)))
.map(([token]) => token);
expect(unowned).toEqual([]);
});