IntelliJ中的Mocha运行配置

时间:2019-03-20 11:12:19

标签: intellij-idea mocha

我已经将mocha配置为通过mocha intelliJ mocha插件在我的react应用中运行测试用例,我定义了以下配置:

enter image description here

我有帮助Javascript文件,该文件应该在测试之前由mocha加载,因此我在上面的屏幕快照的mocha选项中添加了--config,该文件的内容如下:

--recursive
--require helper.js

问题似乎是该帮助程序未加载,因此我遇到了类似这样的错误:

ReferenceError: regeneratorRuntime is not defined
 windows is not defined

在Windows中的位置是在helper.js中定义的,因此我的问题是如何从intelliJ中存在的mocha运行配置中加载helper.js

替代此方法,当我在终端中运行以下命令时,此方法工作正常,因此在终端中为mocha运行所有测试用例:

mocha --require babel-register --require ignore-styles --require ./test/test.helper.js

但是我只想从intelliJ运行单个测试,因此非常感谢对此问题的任何提示。

1 个答案:

答案 0 :(得分:0)

mocha.opts传递到摩卡的正确方法是--opts选项,例如--opts config/mocha.opts(路径必须相对于项目根文件夹)。 mocha.opts中本地模块的路径也应相对于项目根目录。 例如,如果我的助手位于<project dir>/specs/util/test.helper.js中,而mocha.opts-位于<project dir>/config/mocha.opts中,则.opts

--require ./specs/util/test.helper.js

并运行配置如下所示:

enter image description here

相关问题