Coffeescript 如何将编译器选项传递给mocha

Coffeescript 如何将编译器选项传递给mocha,coffeescript,mocha.js,Coffeescript,Mocha.js,我运行mocha命令来运行测试 $ ./node_modules/.bin/mocha --compilers coffee:coffee-script -R spec 我希望将其他选项传递给coffee脚本编译器(-bare),以避免在将.coffee编译为.js时引入外部闭包。有办法做到这一点吗?我试过了 $ ./node_modules/.bin/mocha --compilers coffee:coffee-script --bare -R spec 但这看起来不对。它也没有说,裸咖

我运行mocha命令来运行测试

$ ./node_modules/.bin/mocha --compilers coffee:coffee-script -R spec
我希望将其他选项传递给coffee脚本编译器(-bare),以避免在将.coffee编译为.js时引入外部闭包。有办法做到这一点吗?我试过了

$ ./node_modules/.bin/mocha --compilers coffee:coffee-script --bare -R spec
但这看起来不对。它也没有说,裸咖啡对摩卡来说不是一个有效的选择

  error: unknown option `--bare'
--compiler选项不支持这一点,但您可以编写一个脚本,用您的选项激活编译器,然后使用mocha的--require选项激活注册脚本。例如,在名为babelhook.js的项目根目录下创建一个文件:

// This file is required in mocha.opts
// The only purpose of this file is to ensure
// the babel transpiler is activated prior to any
// test code, and using the same babel options

require("babel-register")({
  experimental: true
});
然后将其添加到mocha.opts:

--require babelhook

就这样。Mocha在进行任何测试之前都需要babelhook.js。

只需在根目录中添加一个
.babelrc
文件即可。 然后任何babel实例(构建、运行时、测试等)都会引用它。


您甚至可以为每个环境添加特定的配置选项。

以防有人无意中发现这一点。巴别塔中的“实验性”选项已被弃用。您的“babelhook.js”现在应该是:

//mocha.opts中需要此文件
//此文件的唯一目的是确保
//巴贝尔transpiler在进行任何操作之前被激活
//测试代码,并使用相同的巴别塔选项
要求(“巴别塔/登记册”)({
阶段:1
});

这似乎是最好的解决方案,嗯,我想我不能通过.babelrc修改babel寄存器的“忽略”选项,但如果我使用babelhook方式,它就会工作。
ignore
选项目前在
中似乎不起作用。babelrc
不是babel寄存器吗?@goldylucks我相信
babel/register
是babel v5,
babel寄存器
babel v6。