Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug: Some Settings Cannot Be Inherited (extends keyword) #4979

Open
4 tasks done
manuth opened this issue Apr 24, 2023 · 1 comment
Open
4 tasks done

馃悰 Bug: Some Settings Cannot Be Inherited (extends keyword) #4979

manuth opened this issue Apr 24, 2023 · 1 comment
Labels
status: waiting for author waiting on response from OP - more information needed type: bug a defect, confirmed by a maintainer

Comments

@manuth
Copy link

manuth commented Apr 24, 2023

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • 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.
  • '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
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Currently, mocha will load default settings from lib/mocharc.json from this package and only after doing so process the configuration using yargs.

This breaks yargs extends mechanism as the values predefined in said mocharc.json file cannot be overridden.

This means that following settings cannot be specified using the extends config:

  • diff
  • package
  • reporter
  • slow
  • timeout
  • ui

I assume that arrays still do work as, to my understanding, yargs will concatenate arrays taken from extends configs.

Steps to Reproduce

  1. Create a project with mocha tests written using the tdd ui
  2. In your project's root, create a file base.json with the following content:
    {
        "ui": "tdd"
    }
  3. In your project's root, create a file called .mocharc.json:
    {
        "timeout": 10000
    }
  4. Try to run your tdd tests by running the mocha command

Expected behavior:

mocha should be able to execute this test as the setting "ui": "tdd" is supposed to be inherited.

Actual behavior: [What actually happens]

mocha will instead show the following error message:

ReferenceError: suite is not defined

Reproduces how often: 100%

Versions

  • The output of mocha --version and node_modules/.bin/mocha --version: 10.0.2
  • The output of node --version: 20.0.0
  • Your operating system
    • name and version: arch1
    • architecture (32 or 64-bit): amd64
  • Your shell (e.g., bash, zsh, PowerShell, cmd): bash, PowerShell, cmd
  • Your browser and version (if running browser tests):
  • Any third-party Mocha-related modules (and their versions):
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version):

Additional Information

Notice that default values from this package's lib/mocharc.json file are applied to the current config file during the execution of import("mocha/lib/cli/options").loadOptions() in this piece of code:

args = parse(args._, mocharc, args, rcConfig || {}, pkgConfig || {});

Only after invoking loadOptions(), the extends setting is processed by yargs:

  • First, loadOptions() is executed - in doing so, values from lib/mocharc.json are applied
    var args = mochaArgs || loadOptions(argv);
  • After that, features such as extends are processed by yargs:
    .config(args)

Related to this question: #3916
There is also a PR addressing this issue: #4407
Furthermore, I created a PR myself: #4980

@JoshuaKGoldberg JoshuaKGoldberg changed the title Some Settings Cannot Be Inherited 馃悰 Bug: Some Settings Cannot Be Inherited (extends keyword) Jan 18, 2024
@JoshuaKGoldberg JoshuaKGoldberg added type: bug a defect, confirmed by a maintainer duplicate been there, done that, got the t-shirt... and removed unconfirmed-bug duplicate been there, done that, got the t-shirt... labels Jan 18, 2024
@JoshuaKGoldberg JoshuaKGoldberg added the status: in triage a maintainer should (re-)triage (review) this issue label Feb 9, 2024
@JoshuaKGoldberg
Copy link
Member

In your project's root, create a file base.json

This confuses me. Nothing in the .mocharc.json references extending base.json. So it makes sense that the values in base.json wouldn't be used.

Was the repro meant to have .mocharc.json look like this?

{
  "extends": "./base.json",
  "timeout": 10000
}

The PR makes sense at first glance, and I can reproduce the buggy behavior by adding in the missing "extends". But I just want to be sure. 馃檪

@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author waiting on response from OP - more information needed and removed status: in triage a maintainer should (re-)triage (review) this issue labels Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author waiting on response from OP - more information needed type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants