mocha
mocha copied to clipboard
🚀 Feature: Config file schema
Prerequisites
- [x] Checked that your issue hasn't already been filed by cross-referencing issues with the
faq
label - [x] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- [x] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- [x] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend avoiding the use of globally installed Mocha.
Description
Is there a schema or declaration for mocha's new config file, so that we get tooling? Could be a JSON schema, TypeScript declarations, or both.
It can be declared in one form and compiled to the other via quicktype. https://www.npmjs.com/package/quicktype https://app.quicktype.io/?share=x6K1P6RGhC3tAxYP9tgm
Expected behavior: [What you expect to happen]
Here's a usage example, if such declarations existed.
.mocharc.json
{
"$schema": "https://mochajs.org/schemas/rc.json",
// tooltips with descriptions and defaults available here
}
.mocharc.js
module.exports = /**@type Mocha.Rc */({
// tooltips with descriptions and defaults available here
});
Versions
mocha@next
Additional Information
How would you want the type Mocha.Rc
to be kept in sync with the json schema? I have some experience with this using https://github.com/bcherny/json-schema-to-typescript. Do you want me do create a merge request for this?
I would also suggest to use the schema for validation, but that would be a different PR I think.
I have opened a pull request to add a .mocharc
JSON schema to https://www.schemastore.org — PR is at https://github.com/SchemaStore/schemastore/pull/1215 — Some eyes 👀 on it would be nice. Comments, criticism, and howls of derisive laughter appreciated.
Once that's merged in, that should provide VS Code users with automatic schema validation and editor help for both JSON (and YAML, if they're using the YAML language server extension from RedHat). I imagine other editors would pick that up as well.
as a heads up, @nbcarey's PR has been merged so you can use
{
"$schema": "https://json.schemastore.org/mocharc"
}
as your schema
@AlexAegis's comment worked for me just now, should this issue be closed? @juergba
Actually, it looks like the "loader" option is not there. This option was recommended to me in https://github.com/mochajs/mocha/issues/4726#issuecomment-903137367 and seems to be a valid option.