简体   繁体   English

如何从测试文件中访问mocha选项?

[英]How to access mocha options from within a test file?

I am running mocha tests using gruntjs and grunt-simple-mocha: https://github.com/yaymukund/grunt-simple-mocha 我正在使用gruntjs和grunt-simple-mocha运行mocha测试: https//github.com/yaymukund/grunt-simple-mocha

How can I access the options defined in my grunt.js file within each mocha test? 如何在每个mocha测试中访问我的grunt.js文件中定义的选项?

What I would like to accomplish, is to have some common configuration in my gruntfile, and use that in my tests. 我想要完成的是在我的gruntfile中有一些常见的配置,并在我的测试中使用它。

The one way I found already is using global values, which is not very good, but works 我发现的一种方法是使用全局值,这不是很好,但有效

inside grunt.js config grunt.js配置中

global.hell = 'hey you';

inside test 内部测试

console.log(global.hell);

inspecting one more way now, maybe it will be better 现在再检查一下,也许会更好

--EDIT - 编辑

No, seems it's the one I will stop at, if I don't want to end up with some black magic like in mocha-as-promised, because i don't have skills to write that. 不,似乎这是我要停下来的那个,如果我不想像摩卡承诺那样结束一些黑魔法,因为我没有技巧可以写出来。

--EDIT - 编辑

Also you can take a look at this - https://github.com/visionmedia/mocha/wiki/Shared-Behaviours you can share some object between tests, but not sure if it will help with grunt 你也可以看看这个 - https://github.com/visionmedia/mocha/wiki/Shared-Behaviours你可以在测试之间分享一些对象,但不确定它是否有助于grunt

As far as I'm aware there is no way to push any objects into your mocha suit. 据我所知,没有办法将任何物体推入你的摩卡服。 The only other interpretation I can think of for your question, you would like to load a common set of configs among your test files. 对于你的问题我唯一能想到的其他解释,你想在你的测试文件中加载一组通用的配置。 I dont belive you can, other than at the very top of your test files loading a common config file to be availble to your test methods. 我不相信你可以,除了你的测试文件的顶部加载一个通用的配置文件可用于你的测试方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM