I've been trying to download a HAR file from saucelabs using the exec command, but I get this error when it downloads too much data:
RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]: stdout maxBuffer length exceeded
I've seen that child_process spawn is used instead for larger files, but I haven't managed to get it to work with all the parameters I am sending. Also I couldn't figure out how to return the downloaded data and store as a variable with spawn. Is anybody able to show me how to use spawn to get the data, and how to save that data into a variable for further processing.
Thanks
async getNetworkRequests (jobId) {
const harFile = await new Promise((resolve, reject) => {
exec(`curl -u "${process.env.SAUCE_USER}:${process.env.SAUCE_KEY}" --location --compressed --request GET 'https://api.eu-central-1.saucelabs.com/rest/v1/${process.env.SAUCE_USER}/jobs/${jobId}/assets/network.har'`, (error, stdout) => {
if (error) {
console.log(`Error message: ${error}`)
reject(error)
}
resolve(stdout)
})
})
return harFile
}
I've made some progress with spawn, but I am unable to get the data out of the stdout function:
async getNetworkRequests (jobId) {
const spawnProcess = spawn('/bin/sh', ['-c', `curl -u "${process.env.SAUCE_USER}:${process.env.SAUCE_KEY}" --location --compressed --request GET 'https://api.eu-central-1.saucelabs.com/rest/v1/${process.env.SAUCE_USER}/jobs/${jobId}/assets/network.har'`])
const output
spawnProcess.stdout.on('data', data => {
output = data.toString()
})
console.log(output) // This returns undefined
}