Pipe stderr and log parse errors

This commit is contained in:
Kevin Sawicki 2017-06-20 14:19:46 -07:00
Родитель 403f997e15
Коммит 3c929304f7
1 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -59,13 +59,21 @@ function runLighthouse (url, callback) {
const lighthouse = ChildProcess.spawn(lighthousePath, args)
let output = ''
lighthouse.stderr.pipe(process.stderr)
lighthouse.stdout.on('data', (data) => {
output += data
})
lighthouse.once('close', () => {
let errorCount = 0
const report = JSON.parse(output)
let report
try {
report = JSON.parse(output)
} catch (parseError) {
console.error(`Parsing JSON report output failed: ${output}`)
callback(1)
return
}
report.reportCategories.forEach((category) => {
category.audits.forEach((audit) => {