Skip to content

🐛 Bug: Spec Configuration Option Incorrectly takes Priority over a Spec Command-line Argument #5412

@X-Guardian

Description

@X-Guardian

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have '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, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

With a Mocha configuration file that contains the spec option, I would expect that running the Mocha CLI with a spec argument, the CLI argument should take priority.

Actual

The spec option in the configuration file takes priority.

Minimal, Reproducible Example

Create two test files:

  • src/test1/test1.spec.js
  • src/test2/test2.spec.js

Create the following .mocharc.yml with a spec option:

spec: ["src/**/*.spec.js"]

Run Mocha specifying only the first test file:

yarn mocha src/test1/test1.spec.js

The result is that incorrectly, both test files will run

  test1
    ✔ should be true

  test2
    ✔ should be true


  2 passing (2ms)

Remove the spec option from .mocharc.yml and re-run Mocha specifying only the first test file:

yarn mocha src/test1/test1.spec.js

The results is that correctly, only the first test will run:

  test1
    ✔ should be true


  1 passing (1ms)

Versions

11.7.1

Additional Info

According to https://mochajs.org/#merging, the command line arguments should take priority over the configuration file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: documentationanything involving docs or mochajs.orgfaqa frequently asked question or common misconceptionstatus: accepting prsMocha can use your help with this one!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions