这里缺少什么
我想在代码中获得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';
您可以尝试使用maxBuffer
选项。
阅读更多:https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
此外,这个代码示例可能很有用:
var exec = require('child_process').exec;
var child = exec('npm ls --json --long', {
encoding: 'utf8',
// maxBuffer Number largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200*1024)
maxBuffer: 10*1024*1024
});