mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
- Removed code generators (e2e/generators, storybook/generators) - Created JSON test runner that executes Playwright tests directly from JSON - Created JSON story loader that renders Storybook stories directly from JSON - No intermediate code generation - JSON is executable/renderable at runtime - json-packages.spec.ts auto-discovers and runs all package tests from JSON - DynamicStory component renders stories from JSON definitions - True meta/abstract architecture: configuration itself is executable - Single source of truth: JSON definitions only (no generated .spec.ts or .stories.tsx) - Changes to JSON take effect immediately without regeneration - Added comprehensive READMEs explaining the interpretation approach Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
4.1 KiB
4.1 KiB
JSON Playwright Test Runner
No code generation - tests are interpreted directly from JSON at runtime.
This is the true meta/abstract approach: the JSON itself is executable, not just a template for code generation.
Philosophy
Instead of generating .spec.ts files from JSON, we directly execute the JSON test definitions. This keeps tests as pure data that's interpreted at runtime, staying true to the 95% configuration rule.
How It Works
- Discovery: Scans
packages/*/playwright/tests.jsonfiles - Loading: Reads JSON test definitions at runtime
- Interpretation: Executes test steps directly from JSON
- No Intermediate: No code generation step - JSON → Execution
Usage
Run JSON-Defined Package Tests
# Run all JSON-defined package tests
npm run test:e2e:json
# Or run directly
npm run test:e2e -- e2e/json-packages.spec.ts
# With UI mode
npm run test:e2e:ui -- e2e/json-packages.spec.ts
How Tests Are Loaded
The json-packages.spec.ts file automatically discovers and loads all tests:
import { loadAllPackageTests } from './json-runner/playwright-json-runner'
// Discovers packages/*/playwright/tests.json and registers tests
await loadAllPackageTests(packagesDir, test)
Example: JSON Test Definition
packages/ui_home/playwright/tests.json:
{
"$schema": "https://metabuilder.dev/schemas/package-playwright.schema.json",
"package": "ui_home",
"tests": [{
"name": "should display hero section",
"tags": ["@smoke", "@ui"],
"steps": [
{
"description": "Navigate to home page",
"action": "navigate",
"url": "/"
},
{
"description": "Wait for page load",
"action": "waitForLoadState",
"state": "domcontentloaded"
},
{
"description": "Verify hero title visible",
"action": "expect",
"selector": ".hero-title",
"assertion": {
"matcher": "toBeVisible"
}
}
]
}]
}
Executed directly - no intermediate code generation!
Supported Actions
- Navigation:
navigate,waitForNavigation,waitForLoadState - Interactions:
click,dblclick,fill,type,select,check,uncheck,hover,focus,press - Assertions:
expectwith all Playwright matchers - Utilities:
wait,waitForSelector,screenshot,evaluate
Supported Selectors
selector- CSS selectorrole- ARIA role with optional texttext- Text contentlabel- Form labelplaceholder- Input placeholdertestId- data-testid attribute
Supported Assertion Matchers
All standard Playwright matchers:
- Visibility:
toBeVisible,toBeHidden - State:
toBeEnabled,toBeDisabled,toBeChecked,toBeFocused,toBeEmpty - Content:
toHaveText,toContainText,toHaveValue - Count:
toHaveCount - Attributes:
toHaveAttribute,toHaveClass,toHaveCSS - Page:
toHaveURL,toHaveTitle
Benefits of JSON Execution
- True Meta Architecture: Tests are data, not code
- No Build Step: JSON is directly executable
- Runtime Interpretation: Changes take effect immediately
- Single Source of Truth: JSON is the only definition
- Package Ownership: Each package owns its test data
- Schema Validated: Tests conform to JSON schema
File Structure
e2e/
├── json-runner/
│ └── playwright-json-runner.ts # JSON test interpreter
├── json-packages.spec.ts # Auto-loads all package tests
└── smoke.spec.ts # Manual smoke tests
vs Code Generation
| Approach | Source of Truth | Runtime | Changes |
|---|---|---|---|
| Code Generation | JSON → Generate .spec.ts |
Executes TypeScript | Requires regeneration |
| JSON Execution ✅ | JSON (only) | Interprets JSON | Immediate effect |
JSON execution is more meta/abstract - the configuration itself is executable!
See Also
schemas/package-schemas/playwright.schema.json- JSON Schemaschemas/package-schemas/PLAYWRIGHT_SCHEMA_README.md- Schema documentationpackages/*/playwright/tests.json- Test definitions