Skip to content

Commit

Permalink
fix(test): improve error logging in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thsig authored and edvald committed Jan 21, 2020
1 parent 54d74cc commit c308f46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions garden-service/test/e2e-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk"
import execa from "execa"
import mlog from "mocha-logger"
import { remove } from "fs-extra"
import { get, intersection, padEnd } from "lodash"
import parseArgs = require("minimist")
Expand Down Expand Up @@ -70,8 +70,8 @@ export function parseLogEntries(entries: string[]): JsonLogEntry[] {
try {
return JSON.parse(line)
} catch (error) {
mlog.log("Unable to parse line", line)
return {}
// Unable to parse line, so we assume it's a line from an error message.
return { msg: chalk.red(line) }
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions garden-service/test/run-garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ export function commandReloadedStep(): WatchTestStep {
}
}

function stringifyJsonLog(entries: UpdateLogEntryParams[]) {
function stringifyJsonLog(entries: UpdateLogEntryParams[], opts = { error: false }) {
return entries
.map((l) => {
const msg = chalk.white(<string>l.msg || "")
const msg = (opts.error ? chalk.red : chalk.white)(<string>l.msg || "")
return l.section ? `${chalk.cyanBright(l.section)}${chalk.gray(":")} ${msg}` : msg
})
.join("\n")
Expand All @@ -128,7 +128,7 @@ export async function runGarden(dir: string, command: string[]): Promise<JsonLog
let msg = err.message.split("\n")[0]
if (err.stdout) {
const parsedLog = parseLogEntries(err.stdout.split("\n").filter(Boolean))
msg += "\n" + stringifyJsonLog(parsedLog)
msg += "\n" + stringifyJsonLog(parsedLog, { error: true })
}
throw new Error(`Failed running command '${command.join(" ")}': ${msg}`)
}
Expand Down

0 comments on commit c308f46

Please sign in to comment.