|
| 1 | +import { describe, it, expect } from "vitest" |
| 2 | +import { readFileSync } from "node:fs" |
| 3 | +import { resolve } from "node:path" |
| 4 | + |
| 5 | +// The CSS minifier collapses an identical-value vendor-prefix pair to the last |
| 6 | +// declaration, so `backdrop-filter` before `-webkit-backdrop-filter` ships as |
| 7 | +// webkit-only and the glass blur dies in Chrome/Firefox. This guards the order |
| 8 | +// in the hand-written CSS so it can't regress on a dependency bump. |
| 9 | + |
| 10 | +const REPO_ROOT = resolve(__dirname, "../../..") |
| 11 | + |
| 12 | +const CSS_FILES = [ |
| 13 | + "packages/ui/src/styles/components.css", |
| 14 | + "library/lib/styles/app.css", |
| 15 | +] |
| 16 | + |
| 17 | +// Matches the broken order: an unprefixed decl immediately followed by the |
| 18 | +// same-value -webkit- decl. `-webkit-` first, or a lone decl, is safe. |
| 19 | +const BROKEN_ORDER = |
| 20 | + /(?<![-\w])backdrop-filter:\s*([^;]+);\s*-webkit-backdrop-filter:\s*\1\s*;/g |
| 21 | + |
| 22 | +describe("backdrop-filter vendor-prefix ordering", () => { |
| 23 | + for (const file of CSS_FILES) { |
| 24 | + it(`${file} lists -webkit-backdrop-filter before the standard property`, () => { |
| 25 | + const css = readFileSync(resolve(REPO_ROOT, file), "utf-8") |
| 26 | + const offenders = [...css.matchAll(BROKEN_ORDER)].map((m) => |
| 27 | + m[0].replace(/\s+/g, " ").trim() |
| 28 | + ) |
| 29 | + expect( |
| 30 | + offenders, |
| 31 | + `Put -webkit-backdrop-filter BEFORE backdrop-filter in ${file}, or ` + |
| 32 | + `lightningcss drops the standard property and the blur breaks in ` + |
| 33 | + `Chrome/Firefox.` |
| 34 | + ).toEqual([]) |
| 35 | + }) |
| 36 | + } |
| 37 | +}) |
0 commit comments