Closed thomasweitzel closed 4 years ago
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 https://github.com/facebook/jest/issues/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.
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'
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.
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.
✅ The problem can be bypassed by programmatically importing const validateSchema = require('yaml-schema-validator/src')
as a workaround.
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.
I'm using Node 10, 12 and 13 in my project and they all had this problem.
Same error here running jest --coverage
. Tested with the following node versions:
● 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)
As soon as I include
"yaml-schema-validator": "^1.1.9"
in mypackage.json
andnpm install
it,mocha --opts mocha.opts
fails with this error message:My project has these dependencies:
If I remove
yaml-schema-validator
, the commandmocha --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.