question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

[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:

Write the tests before any of the code. Run the tests; they should fail. The tests all pass. The tests all pass?!

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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

1reaction
SimenBcommented, Dec 30, 2021

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.

0reactions
Kurt-von-Lavencommented, Feb 19, 2022

Bravo! Adding schemas to JSON Schema Store is indeed straightforward and documented.

Once we have a schema that works, we can start using it inside Jest. How to get that schema onto some schema store I donā€™t know, but probably fairly straightforward

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create your own auto-completion for JSON and YAML ...
Open the settings for the YAML extension and search for "Yaml: Schemas" and click "Edit in settings. json". The "settings. json" file will...
Read more >
Create your own auto-completion for JSON and YAML files on ...
In this article, I demonstrate how to create a JSON Schema, to provide auto-completion to Hadolint configuration files on VS Code editor.
Read more >
Schema Validation for YAML
JSON Schema can be used to validate YAML documents. YAML Ain't Markup Language (YAML) is a powerful data serialization language that aims to...
Read more >
How to configure YAML schema to make editing files easier
The JSON Schema store is used directly or through the YAML Language Server in several IDEs. It allows an automatic binding of YAML...
Read more >
Implementations - JSON Schema
Implementations are classified based on their functionality. When known, the license of the project is also mentioned. If you have updates to this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found