|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import postcss from 'postcss' |
| 5 | +import { describe, expect, it } from 'vitest' |
| 6 | +import embed from '../apps/sim/lib/postcss/platform-embed.cjs' |
| 7 | +import { findEntryEscapes, findModuleEscapes } from './check-platform-css' |
| 8 | + |
| 9 | +const ENTRY = '/repo/apps/sim/platform/design-system/styles/embedded.css' |
| 10 | + |
| 11 | +const scoped = async (css: string, from = ENTRY) => |
| 12 | + (await postcss([embed()]).process(css, { from })).css |
| 13 | + |
| 14 | +describe('findEntryEscapes', () => { |
| 15 | + it.each([ |
| 16 | + [':root { --spacing: 1px; }'], |
| 17 | + ['html { color: red; }'], |
| 18 | + ['[data-platform-ui] html { color: red; }'], |
| 19 | + ['.flex { display: flex; }'], |
| 20 | + ['[data-material="shell"] { color: red; }'], |
| 21 | + ['@layer utilities { [data-platform-ui] .flex { display: flex; } }'], |
| 22 | + ['@property --tw-shadow { syntax: "*"; inherits: false; }'], |
| 23 | + ['@keyframes spin { to { rotate: 1turn; } }'], |
| 24 | + ['@media (width > 1px) { .flex { display: flex; } }'], |
| 25 | + ])('flags %s', (css) => { |
| 26 | + expect(findEntryEscapes(css, '')).not.toEqual([]) |
| 27 | + }) |
| 28 | + |
| 29 | + it('flags a font family the host stylesheet names', () => { |
| 30 | + expect(findEntryEscapes('@font-face { font-family: "Geist"; }', 'font: "Geist"')).not.toEqual( |
| 31 | + [] |
| 32 | + ) |
| 33 | + }) |
| 34 | + |
| 35 | + it('passes what the embed plugin emits', async () => { |
| 36 | + const css = await scoped( |
| 37 | + '[data-platform-ui] { color: red; } [data-material="shell"] { color: red; } ' + |
| 38 | + '[data-platform-ui][data-theme="dark"] svg { color: red; } :focus, a { color: red; }' |
| 39 | + ) |
| 40 | + expect(findEntryEscapes(css, '')).toEqual([]) |
| 41 | + expect(css).toContain(':where([data-platform-ui]) [data-material="shell"]') |
| 42 | + expect(css).toContain(':where(html.dark) [data-platform-ui][data-theme="system"] svg') |
| 43 | + }) |
| 44 | + |
| 45 | + it('leaves any other stylesheet to the host', async () => { |
| 46 | + const css = '.flex { display: flex; }' |
| 47 | + expect(await scoped(css, '/repo/apps/sim/app/_styles/globals.css')).toBe(css) |
| 48 | + }) |
| 49 | +}) |
| 50 | + |
| 51 | +describe('findModuleEscapes', () => { |
| 52 | + it.each([ |
| 53 | + ['button { color: red; }'], |
| 54 | + ['[data-platform-ui] { color: red; }'], |
| 55 | + [':global(.flex) { display: flex; }'], |
| 56 | + ['.local, body { color: red; }'], |
| 57 | + ['@layer base { .local { color: red; } }'], |
| 58 | + ['@font-face { font-family: "X"; }'], |
| 59 | + ['@property --x { syntax: "*"; inherits: false; }'], |
| 60 | + ])('flags %s', (css) => { |
| 61 | + expect(findModuleEscapes(css, 'x.module.css')).not.toEqual([]) |
| 62 | + }) |
| 63 | + |
| 64 | + it('passes local classes and their keyframes', () => { |
| 65 | + const css = |
| 66 | + '.local:hover, textarea.input { color: red; } @media (width > 1px) { .local { color: red; } } ' + |
| 67 | + '@keyframes spin { from { rotate: 0; } to { rotate: 1turn; } }' |
| 68 | + expect(findModuleEscapes(css, 'x.module.css')).toEqual([]) |
| 69 | + }) |
| 70 | +}) |
0 commit comments