[Feature]: Create Schema for JSON and YAML Config Files
See original GitHub issueš Feature Proposal
Write a draft v4 JSON schema defining Jest config files for inclusion in JSON SchemaStore.
Motivation
Jest config files are powerful, complex, and offer many options. A number of them (e.g., coverageReporters, coverageThreshold, moduleNameMapper, reporters, transform) have complex types, and a number (e.g., *PathIgnorePatterns
) have long names.
Example
Offering a schema makes it easy for projects that desire to validate their config files to do so with minimal effort and receive precise, helpful, real-time in-editor warnings and autocomplete suggestions regarding typos in key names. A schema would also make it easy to validate Jest config files in CI. JSON Schema Store recommends use of draft v4 JSON schemas for maximum compatibility.
Pitch
āQuis custodiet ipsos custodes?ā (āWho will guard the guards themselves?ā) ~ Satires (Satire IV lines 347-348), Decimus Junius Juvenalis (a.k.a., Juvenal)
Or as retold via Gru from Despicable Me:
I donāt know whether or not a schema would catch any issues that Jest itself wouldnāt catch when run, but itās generally preferable to catch issues as they are introduced, and auto-completion of keys is an appreciated productivity boost. A JSON schema is extremely precise documentation, leaving no ambiguity as to what constitutes a valid JSON/YAML config file. Using a JSON schema may simplify Jestās validation logic, facilitate automatically testing whether the JSON/YAML and JavaScript/TypeScript config file options are in sync with one another, and allow documentation to be auto-generated if these things arenāt happening already. In the meantime, users who want stronger type checking and auto-completion can presently use a TypeScript file. However, dynamic code execution introduces another possible point of failure, and TypeScript config files require some extra setup (e.g., introducing a dev dependency on ts-node, which can be especially burdensome in high-security settings). Many projects also prefer to use static JSON or YAML config files for simplicity.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10
Top GitHub Comments
Iād start by using typebox (linked above) to build up the json schema in memory. We can then write that to disk for publishing somewhere (probably a new module, but we can look at that later), and use ajv or something to validate it internally within
jest-config
.Bravo! Adding schemas to JSON Schema Store is indeed straightforward and documented.