From 12c98955ab918f07b818e69bad692568e60723ee Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Tue, 27 Jan 2026 12:37:44 +0100 Subject: [PATCH] Add custom test for @media scan --- custom/css.json | 7 +++++++ custom/tests.yaml | 6 ++++++ test-builder/css.ts | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/custom/css.json b/custom/css.json index 76f88adb1..7e8254d58 100644 --- a/custom/css.json +++ b/custom/css.json @@ -1372,5 +1372,12 @@ "property": "background-image", "value": "url('https://mdn-bcd-collector.gooborg.com')" } + }, + "at-rules": { + "media": { + "scan": {}, + "scan.interlace": {}, + "scan.progressive": {} + } } } diff --git a/custom/tests.yaml b/custom/tests.yaml index b78209720..0faf9dd6f 100644 --- a/custom/tests.yaml +++ b/custom/tests.yaml @@ -6269,6 +6269,12 @@ css: first: "return {result: null, message: 'Testing :first is not yet implemented'};" left: "return {result: null, message: 'Testing :left is not yet implemented'};" right: "return {result: null, message: 'Testing :right is not yet implemented'};" + at-rules: + media: + scan: + __test: "return window.matchMedia('not (scan: interlace)').matches || window.matchMedia('not (scan: progressive)').matches;" + interlace: "return window.matchMedia('not (scan: interlace)').matches;" + progressive: "return window.matchMedia('not (scan: progressive)').matches;" html: # Features defined here also need to be in @webref/elements or custom/elements.json. diff --git a/test-builder/css.ts b/test-builder/css.ts index 9d31272b2..c3ad8805c 100644 --- a/test-builder/css.ts +++ b/test-builder/css.ts @@ -634,6 +634,35 @@ const buildTypeTests = async (customCSS) => { return tests; }; +/** + * Builds tests for CSS at-rules based on the provided customCSS. + * @param customCSS - The custom CSS data. + * @returns - The tests for CSS at-rules. + */ +const buildAtRuleTests = async (customCSS) => { + const tests = {}; + + for (const [atRule, atRuleData] of Object.entries( + customCSS["at-rules"] || {}, + ) as any[]) { + for (const [feature] of Object.entries(atRuleData) as any[]) { + const ident = `css.at-rules.${atRule}.${feature}`; + const customTest = await getCustomTest(ident, "css.at-rules", true); + + if (customTest.test) { + tests[ident] = compileTest({ + raw: { + code: customTest.test, + }, + exposure: ["Window"], + }); + } + } + } + + return tests; +}; + /** * Builds tests for CSS features based on the provided specCSS and customCSS. * @param specCSS - The specification CSS data. @@ -646,6 +675,7 @@ const build = async (specCSS, customCSS) => { Object.assign(tests, await buildPropertyTests(specCSS, customCSS)); Object.assign(tests, await buildSelectorTests(specCSS, customCSS)); Object.assign(tests, await buildTypeTests(customCSS)); + Object.assign(tests, await buildAtRuleTests(customCSS)); return tests; };