通过grunt传递node.js选项

当我在命令行上开始咕噜时,如何将一个parameter passing给节点进程?

具体来说,我想将选项–expose-gc传递给运行grunt的节点。 我运行的命令是:

grunt mocha:mytests 

我想实现,我的摩卡testing暴露垃圾收集界面。

如果有任何帮助:grunt文件部分如下所示:

 myTest: { src: [ 'mocha.hooks/*.spec.js', 'build/ch.actifsource.*/**/test/*.spec.js', 'mocha.hooks/*.spec.server.js', 'build/ch.actifsource.*/**/test/*.spec.server.js' ], options: { timeout: 500, logErrors: true }, ignore: [ './src/**/RegisterResourceTypes.js' ] } 

各种grunt摩卡插件的API不提供一个选项来传递--expose-gc ,包括这个。

您可以安装grunt-shell,并将其configuration为像通过CLI一样运行相同的mocha命令。

你的grunt-shell command是:

 // ... shell: { myTest: { command: './node_modules/mocha/bin/mocha -t 500 -gc path/to/files' } } // ... 

path/to/files部分应该用你的src文件replace。

请注意,该命令通过bin文件夹运行本地摩卡 ,因此您还需要安装摩卡 :

$ npm i -D mocha