node.js 是否有 .mocha 文件,我可以在其中指定诸如 --no-colors 之类的默认值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15951010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:11:04  来源:igfitidea点击:

Is there a .mocha file where I can specify defaults such as --no-colors?

node.jsconfigurationconfigmochadotfiles

提问by mcandre

I'd like to set some defaults for mocha without having to type them each time. Does mocha look for a config file / dotfile anywhere, as jshint looks for .jshintrcand npm looks for package.json?

我想为 mocha 设置一些默认值,而不必每次都输入它们。mocha 是否在任何地方寻找配置文件/点文件,就像 jshint 寻找.jshintrc和 npm 寻找一样package.json

回答by zs2020

Yes. You can create a file ./test/mocha.optsand in the file you can specify --no-colors.

是的。您可以创建一个文件./test/mocha.opts并在该文件中指定--no-colors.

See mocha.optson Mocha Docfor more information.

有关更多信息,请参阅Mocha Doc上的mocha.opts

回答by gabssnake

The default is ./test/mocha.opts. You can pass a custom path with the --optsparameter :

默认为./test/mocha.opts。您可以使用--opts参数传递自定义路径:

mocha --opts ./mocha.opts

mocha --opts ./mocha.opts

Useful in case you don't store your tests in test/folder, but next to code files, for example.

例如,如果您不将测试存储在test/文件夹中,而是存储在代码文件旁边,则很有用。

Any name and extension seems to work, so you can even do mocha --opts .mocharcif you want it to go well with .jshintrc, .babelrcand the like.

任何名称和扩展名似乎都有效,因此mocha --opts .mocharc如果您希望它与 等配合使用.jshintrc,您甚至可以这样做.babelrc

回答by migg

In mocha 6+ the mocha.optswas changed to legacyand the new place to define your configuration is a .mocharcfile that can have different formats (JSON, YAML, JS) as described in the docsor a JSON config added to the package.jsonusing mochakey.

在摩卡6+的mocha.opts改变为legacy与新的地方定义配置是一个.mocharc可以具有不同的格式(JSON,YAML,JS),为文件中的文档中描述或添加到一个JSON配置package.json使用mocha密钥。

Specifying your own path to mocha config is done using --config <file>but mocha uses any .mocharc.*file as default in order described in the docs (JS, YAML, YML, JSON) and also automatically uses mochakey from package.jsonwith lower priority than a given config file.

指定您自己的 mocha 配置路径是使用完成的,--config <file>但是 mocha 使用任何.mocharc.*文件作为默认文件,按照文档(JS、YAML、YML、JSON)中描述的顺序,并且还会自动使用优先级低于给定配置文件的mocha密钥package.json