當我在命令行上啓動grunt時,如何將參數傳遞給節點進程?通過grunt傳遞node.js選項
具體來說,我想將選項--expose-gc傳遞給運行grunt的節點。 我運行的命令是:
grunt mocha:mytests
我想要實現,我的摩卡測試得到的垃圾收集接口暴露出來。
如果這是任何幫助:繁重的文件部分是這樣的:
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'
]
}
什麼是摩卡:mytests任務看起來像在'Gruntfile.js'?也許在你的問題中包括代碼片段會增加你獲得答案的機會。 – RobC
Grunt mocha插件API不提供選項來傳遞'--expose-gc'(..including this [one](https://github.com/kmiyashiro/grunt-mocha))。您可以使用[grunt-shell](https://github.com/sindresorhus/grunt-shell)代替。然後將其配置爲通過[CLI](https://mochajs.org/#usage)運行相同的mocha命令。你的_grunt-shell_命令是:'command:'./node_modules/mocha/bin/mocha -t 500 -gc path/to/files'',藉此'path/to/files'部分被替換爲'src'文件。請注意,該命令通過'bin'文件夾運行本地摩卡。您還需要安裝摩卡'$ npm i -D mocha' – RobC
@RobC您所說的話將被認定爲答案! – Alfi