// A light-DOM element's styles are wrapped in `@scope (tag)` unless it says // `scoped: false`. Inside @scope, a selector is relative to the scoping root: // `pebble-x .card` then means a pebble-x *inside* pebble-x, and matches // nothing. happy-dom does not apply the cascade, so no DOM test sees it; // sequence 0.1.0 shipped unstyled that way. A stylesheet that prefixes its // selectors with its tag must be defined with `scoped: false`. import { describe, expect, test } from "bun:test"; import { Glob } from "bun"; const ROOT = `${import.meta.dir}/..`; describe("a light-DOM element's stylesheet", () => { for (const css of new Glob("packages/*/*.css").scanSync(ROOT)) { const name = css.split("/")[1]; const tag = `pebble-${name}`; const source = Bun.file(`${ROOT}/packages/${name}/index.tsx`); test(`${tag}: prefixed selectors are not scoped`, async () => { if (!(await source.exists())) return; const code = await source.text(); const definition = code.match(new RegExp(`define\\(\\s*"${tag}",\\s*\\{([^}]*)\\}`)); if (!definition || !/\bstyles\b/.test(definition[1]) || /shadow:\s*"/.test(definition[1])) return; const sheet = await Bun.file(`${ROOT}/${css}`).text(); const prefixed = new RegExp(`(^|[},])\\s*${tag}[\\s.:\\[,{]`, "m").test(sheet.replace(/\/\*[\s\S]*?\*\//g, "")); if (prefixed) expect(definition[1]).toMatch(/scoped:\s*false/); }); } });