我的 NodeJS 有以下脚本。
"scripts": {
"start": "grunt",
"test": "node --debug --harmony node_modules/grunt-cli/bin/grunt test"
}
我正在运行节点 v0.11.13,所以我需要设置 --harmony 标志。在 grunt 上,如果我使用 npm test 启动测试,测试就会配置正确,但我更愿意将其全部放在 grunt 文件中。有没有办法配置 grunt 来启动服务器并运行测试?
您可以创建一个别名任务,使用这些节点标志生成 grunt,如下所示:
grunt.registerTask('debug', function() {
var done = this.async();
// Specify tasks to run spawned
var tasks = Array.prototype.slice.call(arguments, 0);
grunt.util.spawn({
// Use the existing node path
cmd: process.execPath,
// Add the flags and use process.argv[1] to get path to grunt bin
args: ['--debug', '--harmony', process.argv[1]].concat(tasks),
// Print everything this process is doing to the parent stdio
opts: { stdio: 'inherit' }
}, done);
});
然后您可以启动服务器并运行测试:grunt default debug:test
或者任何组合:
-
grunt server test
(两者都在没有节点标志的情况下运行)
-
grunt debug:server:test
(都使用节点标志运行)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)