File size: 1,328 Bytes
755a930
 
 
 
 
 
7843436
755a930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * CSS Resolution Tests (Section 1.2.2 of TESTS.md)
 *
 * Tests that @custom-media rules are properly resolved for published HTML.
 */
import { describe, it, expect } from "vitest";
import { resolveCustomMedia } from "../src/publisher/index.js";

describe("1.2.2 CSS @custom-media resolution", () => {
  it("resolves custom media declarations", () => {
    const input = `
@custom-media --mobile (max-width: 640px);
@custom-media --desktop (min-width: 1024px);

@media (--mobile) { .foo { display: none; } }
@media (--desktop) { .bar { display: block; } }
    `.trim();

    const output = resolveCustomMedia(input);

    expect(output).not.toContain("@custom-media");
    expect(output).not.toContain("--mobile");
    expect(output).not.toContain("--desktop");
    expect(output).toContain("@media (max-width: 640px)");
    expect(output).toContain("@media (min-width: 1024px)");
  });

  it("leaves standard @media rules untouched", () => {
    const input = "@media (max-width: 768px) { .x { color: red; } }";
    const output = resolveCustomMedia(input);
    expect(output.trim()).toBe(input);
  });

  it("handles CSS with no custom media", () => {
    const input = ":root { --color: red; } body { color: var(--color); }";
    const output = resolveCustomMedia(input);
    expect(output.trim()).toBe(input);
  });
});