Skip to content

test(docs): check documented examples against the emitted CSS - #954

Open
owjs3901 wants to merge 1 commit into
mainfrom
test/docs-conformance
Open

owjs3901 wants to merge 1 commit into
mainfrom
test/docs-conformance

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

DOC-25 / DOC-26: 문서 예제가 실제 빌드 결과와 어긋나지 않도록 conformance 검사를 추가하고, 이 검사로 찾은 불일치를 고쳤습니다.

검사 (packages/__tests__/docs-conformance.test.ts)

bun test로 실행되며, 실제 WASM codeExtract(singleCss, 비 debug)를 사용합니다. CI에서는 WASM 빌드가 있는 publish 검사 job의 bun run test에서 그대로 돕니다.

  1. opt-in 예제: tsx fence 바로 앞에 MDX 주석 {/* conformance */}(또는 바로 위 json fence의 theme을 쓰는 {/* conformance: theme */})을 둔 예제만 검사합니다.
    • 다음 css fence의 규칙과 실제 CSS가 순서 무관하게 정확히 일치해야 합니다. theme layer(@layer t)는 문서가 보여줄 때만 비교합니다.
    • 그 사이에 렌더 결과 tsx fence가 있으면 className 목록도 비교합니다.
    • import가 없는 조각은 사용한 컴포넌트 import를 자동으로 붙이고, <로 시작하면 fragment로 감쌉니다.
    • 대상 페이지 목록을 고정해 두어 마커가 사라지거나 목록 밖 페이지에 마커가 생기면 실패합니다.
  2. 표 기반 검사 (DOC-25): Style Props 표의 모든 행(alias 포함 340여 개)이 문서의 CSS 속성을 내는지, Selector 표의 모든 행이 문서의 pseudo-class / media query를 내는지 확인합니다.
  3. standalone 파싱 (DOC-26): 모든 docs 페이지의 js/jsx/ts/tsx fence가 단독 모듈로 파싱되는지 확인합니다.

첫 대상 페이지와 수정한 불일치

대상 페이지: box, center, css, flex, grid, group-selector, input, text, v-stack, breakpoints(responsive), colors, length, shadow(theme token)

  • Flex / Grid / Center / VStack: 컴포넌트 기본 스타일은 실제로 @layer b 안에 나옵니다. 출력 예시를 이에 맞추고 이유를 주석으로 적었습니다.
  • Center / VStack: 두 번째 자식의 className 순서를 실제 출력(a d b c)으로 고쳤습니다.
  • css 페이지: css 템플릿 리터럴의 class 번호 매김을 실제 출력으로 고쳤습니다.
  • group-selector: background-color → 실제 출력인 background로 고쳤습니다.
  • colors: "rgb(255, 0, 0)은 red가 된다"는 설명을 실제 동작(#FF0000, #F00, rgb(255, 0, 0)은 모두 #F00 한 class, rgba는 #FF000080)으로 고치고 출력 CSS를 추가했습니다.
  • breakpoints / length / shadow / colors: responsive 배열, pseudo + responsive, length / shadow / color token 예제에 실제 출력 CSS를 추가했습니다.
  • features, migration/stylex: 두 파일을 한 fence에 담아 import와 선언이 충돌하던 예제를 파일별 fence로 나눴습니다(DOC-26).

참고: 이번에 문서화하지 않은 동작

responsive 배열 안의 length / shadow token(px={['8px', null, '$containerX']})은 현재 빌드에서 var(--containerX)가 아니라 token의 첫 값(16px)이 리터럴로 들어갑니다. 문서는 "token at index 2"로 설명하고 Rust 단위 테스트도 $containerX를 유지하는 것으로 기대합니다. 버그일 가능성이 높아서 해당 예제에는 마커를 달지 않았습니다. 별도로 확인이 필요합니다.

landing 페이지만 바뀌었고 publish 대상 패키지 변경은 없어서 changepack은 추가하지 않았습니다.

Test plan

  • bun test packages/__tests__/docs-conformance.test.ts (421 pass): 수정 전에는 위 불일치들로 실패하는 것을 확인했습니다.
  • bunx tsc --ignoreConfig --noEmit --strict ... packages/__tests__/docs-conformance.test.ts
  • prettier (test 파일, 변경한 mdx)
  • CI publish job의 bun run test 통과

Refs #693

🤖 Generated with Claude Code

Docs examples were prose only, so they drifted from what the build
emits. packages/__tests__/docs-conformance.test.ts runs them through the
WASM codeExtract:

- An opted-in example ({/* conformance */} or {/* conformance: theme */}
  before its tsx fence) must emit exactly the rules of the next css
  fence, and the className values of a rendered tsx fence in between.
- Every row of the style props table and the selector table is checked
  against the property or selector it documents.
- Every js/jsx/ts/tsx fence on every docs page must parse on its own.

Opted in: box, center, css, flex, grid, group-selector, input, text,
v-stack, breakpoints, colors, length and shadow. Fix what it found:
component defaults are emitted in @layer b, the css`` literal numbers
its classes differently, group hover sets background (not
background-color), rgb(255, 0, 0) becomes #F00 (not red), two
className lists were out of order, and two fences holding two files
are split. Breakpoints, colors, length and shadow gain the CSS output
of an example.

Refs #693 (DOC-25, DOC-26)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant