mochapack icon indicating copy to clipboard operation
mochapack copied to clipboard

Ability to use a mocharc config file.

Open jamesopti opened this issue 6 years ago • 6 comments

Is there any support for using a mocharc file instead of mochapack.opts?

As of Mocha 6, mocha.opts is considered legacy and I find it easier to specify multiple configs in JSON instead of as command line arguments.

P.S. - Thanks for picking up support for this package!

jamesopti avatar Mar 08 '19 18:03 jamesopti

@jamesopti Finding this issue helped me stop pulling my hair out!

However I'm not having success with a mocha.opts with a --require flag in it. Where should the mocha.opts go in your source tree? What's the best way to --require a file from the source tree eg:

--require ../../src/globals

(importing the module in the test file works, but I want to move the require to the mocha.opts)

kierans avatar Feb 11 '20 10:02 kierans

@jamesopti or @kierans can you give this a go with 2.0.0? If it works and you do not run into the issue opened in #65 then we can mark this as resolved.

Thanks

Jack-Barry avatar May 06 '20 20:05 Jack-Barry

@Jack-Barry I am using 2.0.2 and my .mocharc.yaml is not being honored in any fashion. Are only specific file formats supported?

edit: tried with .json and it did not work either

lakeshadow0 avatar Jul 29 '20 16:07 lakeshadow0

@lakeshadow0 Have you tried it with the config flag pointing to your .mocharc?

Jack-Barry avatar Jul 29 '20 16:07 Jack-Barry

@Jack-Barry Ah, I see. I just tried it, and got the error Invalid JSON config file: .mocharc.yaml. I assume then only JSON configurations are supported.

edit: after converting to JSON everything works except for "spec" configuration was not honored. I would expect that YAML would be supported since mocha supports it. I can offer some time to help out with regards to this if you could just point me in the right direction.

lakeshadow0 avatar Jul 29 '20 16:07 lakeshadow0

There might be something out of whack with src/cli/argsParser/optionsFromParsedArgs/mocha/mochaOptionsFromParsedArgs.ts or src/cli/argsParser/optionsFromParsedArgs/mocha/mergeMochaConfigWithOptions.ts

Basically, Mochapack is aiming to offload as much functionality as possible to Mocha, might have missed something in here as far as extracting the config file/determining which parser to use under the hood by Mocha's internals.

Jack-Barry avatar Jul 29 '20 21:07 Jack-Barry