-
Notifications
You must be signed in to change notification settings - Fork 0
chore(docs): engineering docs test section validation - POC #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
09e374c to
87c668f
Compare
c361c51 to
9f64f6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the file that will extract the tests from the .docs.spec.tsx test files themselves
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow the logic in this file, but there is a lot of AST data manipulation happening there, thanks for all for all the comments. Really helps to at least have a grasp of what each function does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here enable the extracted tests (below) to be built in the docs
| }); | ||
| }); | ||
| ``` | ||
| {{docs-tests: text-input.docs.spec.tsx}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tag enables the mdx parser to inject the docs appropriately
| /** | ||
| * @docs-section basic-rendering | ||
| * @docs-title Basic Rendering Tests | ||
| * @docs-description Verify the component renders with expected elements | ||
| * @docs-order 1 | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSDOC comments here allow us to formulate the transformed tests into documentation in a structured way.
| <NimbusProvider> | ||
| <TextInput placeholder="Email address" /> | ||
| </NimbusProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to show consumers the actual boilerplate required to set up a test and be transparent, rather than abstracting the NimbusProvider away in some sort of custom renderProvider function that's out of these test's scopes.
ddouglasz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immense work Jai! Thanks for the work put into this! 🙌🏽
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to follow the logic in this file, but there is a lot of AST data manipulation happening there, thanks for all for all the comments. Really helps to at least have a grasp of what each function does.
This PR introduces a test-to-docs system where documentation test examples are automatically generated from real, executable test files.
The Problem
Test code examples in engineering documentation can become stale when component APIs change. Manually maintaining test examples in MDX files is error-prone and creates duplication.
The Solution
Inverted strategy: Tests live in
.docs.spec.tsxfiles and are injected into documentation at build time.How it works:
.docs.spec.tsxfiles with JSDoc tags:.dev.mdx:What's Included
Infrastructure
packages/nimbus-docs-build/src/parsers/test-extractor.ts)packages/nimbus-docs-build/src/types/test-section.ts)packages/nimbus-docs-build/src/parsers/parse-mdx.ts)Pilot Implementation
.docs.spec.tsxwith 5 test sections (14 tests - all passing)text-input.dev.mdxwith injection token<NimbusProvider>wrappingDocumentation
docs/engineering-docs-validation.md)/create-eng-docsslash commandCleanup
test:docscommandBenefits
✅ Single source of truth - Tests ARE the documentation examples
✅ Type-safe - TypeScript catches API changes in test files
✅ Normal workflow - Tests run with
pnpm test, no special commands✅ Always up-to-date - Documentation generated from working tests
✅ Full transparency - Shows complete code with provider setup
✅ Build-time validation - Missing/broken tests fail docs build
✅ IDE support - Full autocomplete and type checking in test files
Key Design Decision: Full Transparency
Documentation shows unmodified test code including all boilerplate:
<NimbusProvider>wrapper visible in every exampleNimbusProvider,ReactNode)Technical Details
Dependencies added:
@typescript-eslint/typescript-estree- TypeScript AST parser@typescript-eslint/types- AST type definitionsBuild process:
{{docs-tests: filename}}tokens.docs.spec.tsxfiledescribe()blocks with@docs-sectionJSDoc tagsExample Output
Test file (
text-input.docs.spec.tsx):Generated documentation shows exactly the same code - no transformations, complete transparency.
Next Steps
.docs.spec.tsxfiles