我想在代码中获得cucumber-js进程的结果。以JSON格式:
const { exec } = require('child_process')
function getResults () {
return new Promise((resolve, reject) => {
const options = {
encoding: 'utf8'
};
let results = '';
let commands = 'cucumber-js —format json';
const proc = exec(commands, options);
proc.stdout.setEncoding('utf8');
proc.stdout.on('data', chunk => { results += chunk });
proc.stdout.on('end', () => { resolve(results) });
proc.stdout.on('error', reject);
})
}
getResults().then(console.log)

在结果中我得到的stdout不够,json(结果)无效
当我换线时, - 一切正常:
let commands = 'cucumber-js —format json';
==============>
let commands = 'cucumber-js —format json > results.txt && cat results.txt';
答案 0 :(得分:2)
您可以尝试使用run_myapp.cmd
选项。
了解详情:https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
此代码示例也可能有用:
maxBuffer