mocha icon indicating copy to clipboard operation
mocha copied to clipboard

🚀 Feature: Config file schema

Open cspotcode opened this issue 5 years ago • 6 comments

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) and mocha --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

cspotcode avatar Feb 13 '19 21:02 cspotcode

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?

nicojs avatar Apr 06 '20 06:04 nicojs

I would also suggest to use the schema for validation, but that would be a different PR I think.

nicojs avatar Apr 06 '20 06:04 nicojs

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.

nbcarey avatar Aug 25 '20 02:08 nbcarey

as a heads up, @nbcarey's PR has been merged so you can use

{
	"$schema": "https://json.schemastore.org/mocharc"
}

as your schema

AlexAegis avatar Jan 09 '21 09:01 AlexAegis

@AlexAegis's comment worked for me just now, should this issue be closed? @juergba

Maxim-Mazurok avatar Aug 22 '21 04:08 Maxim-Mazurok

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.

Maxim-Mazurok avatar Aug 22 '21 04:08 Maxim-Mazurok