Skip to content

--config does not resolve paths relative to CWD #3822

@cspotcode

Description

@cspotcode

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 node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

.js config loading with --config does not handle relative paths correctly, because it calls require() with a relative path.

Here's the problem: https://github.com/mochajs/mocha/blob/master/lib/cli/config.js#L38

Steps to Reproduce

cd to an empty directory. touch foo.js

mocha --config foo.js

Expected behavior: [What you expect to happen]

mocha loads config from foo.js

Actual behavior: [What actually happens]

/c/Users/cspotcode/Documents/Personal-dev/@mochajs/mocha/lib/cli/config.js:64
    throw new Error(`failed to parse ${filepath}: ${err}`);
    ^

Error: failed to parse foobar.js: Error: Cannot find module 'foo.js'

Reproduces how often: [What percentage of the time does it reproduce?]

All the time

Versions

Mocha 6.0.2
WSL WLinux bash

Additional Information

Issue #3818

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions