tobogganSe connecter

library

Prebuilt pebble components: drop-in custom elements, no compiler needed

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Dernier runAucun
0Étoiles
0Forks
2Issues
27 lignes · 1434 octetsBrut · Historique
1// A light-DOM element's styles are wrapped in `@scope (tag)` unless it says
2// `scoped: false`. Inside @scope, a selector is relative to the scoping root:
3// `pebble-x .card` then means a pebble-x *inside* pebble-x, and matches
4// nothing. happy-dom does not apply the cascade, so no DOM test sees it;
5// sequence 0.1.0 shipped unstyled that way. A stylesheet that prefixes its
6// selectors with its tag must be defined with `scoped: false`.
7import { describe, expect, test } from "bun:test";
8import { Glob } from "bun";
9
10const ROOT = `${import.meta.dir}/..`;
11
12describe("a light-DOM element's stylesheet", () => {
13 for (const css of new Glob("packages/*/*.css").scanSync(ROOT)) {
14 const name = css.split("/")[1];
15 const tag = `pebble-${name}`;
16 const source = Bun.file(`${ROOT}/packages/${name}/index.tsx`);
17 test(`${tag}: prefixed selectors are not scoped`, async () => {
18 if (!(await source.exists())) return;
19 const code = await source.text();
20 const definition = code.match(new RegExp(`define\\(\\s*"${tag}",\\s*\\{([^}]*)\\}`));
21 if (!definition || !/\bstyles\b/.test(definition[1]) || /shadow:\s*"/.test(definition[1])) return;
22 const sheet = await Bun.file(`${ROOT}/${css}`).text();
23 const prefixed = new RegExp(`(^|[},])\\s*${tag}[\\s.:\\[,{]`, "m").test(sheet.replace(/\/\*[\s\S]*?\*\//g, ""));
24 if (prefixed) expect(definition[1]).toMatch(/scoped:\s*false/);
25 });
26 }
27});