nodejs顺序执行shell


最近工作中需要用到nodejs编写脚本来顺序执行自动化测试用例,编写代码如下:

var runCommand = function (command){
	child_process.exec(command,function (error, stdout, stderr) {
        if (stdout !== null) {
          console.log('exec stdout: ' + stdout);
        }
        if (error !== null) {
          console.log('exec error: ' + error);
        }
    });
};

for (var i = 0; i < path.length; i++) {
		if (i !== 0) {
			if (argv.report === 'true') {
				runCommand('mocha ./');
			};

		};
};

但是nodejs的child_process模块执行是异步的,多个命令同时执行会失败。但是自动化测试的服务
不支持同时执行,导致测试多个进程失败。

最后在网上找到了nodejs的shelljs模块,可以解决问题:

require('shelljs/global');

for (var i = 0; i < path.length; i++) {
		if (exec('mocha ./').code !== 0) {
			echo('Error: Git commit failed');
			exit(1);
		}
};


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM