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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mocha --opts not working anymore #7

Closed
thomasweitzel opened this issue Oct 16, 2019 · 8 comments
Closed

mocha --opts not working anymore #7

thomasweitzel opened this issue Oct 16, 2019 · 8 comments

Comments

@thomasweitzel
Copy link

thomasweitzel commented Oct 16, 2019

As soon as I include "yaml-schema-validator": "^1.1.9" in my package.json and npm install it, mocha --opts mocha.opts fails with this error message:

$ mocha --opts mocha.opts
error: unknown option `--opts'

My project has these dependencies:

"devDependencies": {
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "eslint": "^6.5.1",
    "eslint-config-airbnb-base": "^14.0.0",
    "eslint-plugin-import": "^2.14.0",
    "fast-xml-parser": "3.13.0",
    "mocha": "^6.2.1",
    "nyc": "^14.1.1",
    "yaml-schema-validator": "^1.1.9"
  },
  "dependencies": {
    "app-root-path": "^2.2.1",
    "bluebird": "^3.7.0",
    "config": "^3.2.3",
    "glob": "^7.1.4",
    "js-yaml": "^3.13.1",
    "json5": "^2.1.1",
    "jszip": "^3.2.2",
    "lodash": "^4.17.11",
    "moment": "^2.22.2",
    "moment-range": "^4.0.1",
    "moment-timezone": "^0.5.23",
    "normalize-path": "^3.0.0",
    "ramda": "^0.26.1",
    "sql.js": "^1.0.0",
    "winston": "^3.2.1",
    "yargs": "^14.2.0"
  }

If I remove yaml-schema-validator, the command mocha --opts mocha.opts runs all tests as expected.

The problematic behavior is observed regardless of platform, it's the same on Linux, Windows, or macOS. Node.js version 10.16.3 was used.

@bkimminich
Copy link

I have observed the exact same behavior with Jest. Having yaml-schema-validator in the package.json and installed does not cause issues for me. Only when it is imported with require('yaml-schema-validator') in my project, the error: unknown option xxxxx errors arise.

See jestjs/jest#9379 for my original report assuming Jest would be the culprit. It contains steps to reproduce the issue from the failing commits from my Travis-CI pipeline.

@bkimminich
Copy link

I just tried with "yaml-schema-validator": "1.0.0" pinned dependency and the issue exists there already, so it is probably there from the beginning and not a regression.

C:\Data\GitHub\juice-shop>npm run frisby

> juice-shop@10.0.0-SNAPSHOT frisby C:\Data\GitHub\juice-shop
> nyc --report-dir=./build/reports/coverage/api-tests jest --silent --runInBand --forceExit

Determining test suites to run...error: unknown option `--silent'

@bkimminich
Copy link

Removing the only const validateSchema = require('yaml-schema-validator') in my code base (which does not even have to be called - it just has to be imported) makes my test suite run perfectly fine again.

@bkimminich
Copy link

I think the culprit is the design of the module as a mix of CLI and programmatic library all in one. I have no experience with the commander module, but I suspect that this code section is somehow "eating" the command line arguments of the jest or mocha call:

program
  .version(pkg.version)
  .command('validate')
  .option('-f, --filePath <filePath>', 'path to the target file for validating')
  .option('-j, --json','passed if target file is in JSON format')
  .option('-s, --schema [schemaPath]','path to an external schema.js file')
  .action(validateSchema);

program.parse(process.argv);

if(process.argv.includes('help')) {
  help()
}

If this would be extracted into its own file - which then serves for the CLI use case - the programmatic use case would import the actual validator only but not the CLI code.

@bkimminich
Copy link

✅ The problem can be bypassed by programmatically importing const validateSchema = require('yaml-schema-validator/src') as a workaround.

bkimminich added a commit to juice-shop/juice-shop that referenced this issue Jan 9, 2020
@rockon1985
Copy link
Collaborator

thanks @bkimminich for coming up with this. It can work as a temporary workaround till I mitigate the root cause.
Looks like an issue in one of the dependencies and not in the package itself. Would certainly recommend to upgrade to node version 10+ or 11 to avoid this scenario.
Closing this issue.

@bkimminich
Copy link

I'm using Node 10, 12 and 13 in my project and they all had this problem.

@alambike
Copy link

alambike commented Nov 2, 2021

Same error here running jest --coverage. Tested with the following node versions:

  • v10.24.1
  • v12.22.3
  • v14.17.4
 ●  process.exit called with "1"

      5 |
    > 6 | const validateSchema = require('yaml-schema-validator');
        |                        ^
      8 |


      at Command.Object.<anonymous>.Command.unknownOption (node_modules/yaml-schema-validator/node_modules/commander/index.js:823:11)
      at Command.Object.<anonymous>.Command.parseArgs (node_modules/yaml-schema-validator/node_modules/commander/index.js:661:12)
      at Command.Object.<anonymous>.Command.parse (node_modules/yaml-schema-validator/node_modules/commander/index.js:474:21)
      at Object.<anonymous> (node_modules/yaml-schema-validator/index.js:24:9)
      at Object.<anonymous> (src/config/settings.js:6:24)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants