Skip to content

Commit

Permalink
fix: task/test results outputs are not shown
Browse files Browse the repository at this point in the history
  • Loading branch information
10ko authored and thsig committed Sep 4, 2019
1 parent 416831a commit 4a8516e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
5 changes: 3 additions & 2 deletions garden-service/src/logger/log-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface MessageBase {
section?: string
symbol?: LogSymbol
append?: boolean
data?: any
}

export interface MessageState extends MessageBase {
Expand Down Expand Up @@ -78,7 +79,6 @@ export class LogEntry extends LogNode {
private messageStates?: MessageState[]
private metadata?: LogEntryMetadata
public readonly root: Logger
public readonly data?: any
public readonly fromStdStream?: boolean
public readonly indent?: number
public readonly errorData?: GardenError
Expand All @@ -89,7 +89,6 @@ export class LogEntry extends LogNode {
super(params.level, params.parent, params.id)

this.root = params.root
this.data = params.data
this.fromStdStream = params.fromStdStream
this.indent = params.indent
this.errorData = params.error
Expand All @@ -104,6 +103,7 @@ export class LogEntry extends LogNode {
section: params.section,
symbol: params.symbol,
status: params.level === LogLevel.error ? "error" : params.status,
data: params.data,
})
}
}
Expand All @@ -125,6 +125,7 @@ export class LogEntry extends LogNode {
section: updateParams.section || messageState.section,
status: updateParams.status || messageState.status,
symbol: updateParams.symbol || messageState.symbol,
data: updateParams.data || messageState.data,
// Next state does not inherit the append field
append: updateParams.append,
timestamp: Date.now(),
Expand Down
9 changes: 4 additions & 5 deletions garden-service/src/logger/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function renderMsg(entry: LogEntry): string {
}

export function renderData(entry: LogEntry): string {
const { data } = entry
const { data } = entry.getMessageState()
if (!data) {
return ""
}
Expand All @@ -168,8 +168,8 @@ export function renderSection(entry: LogEntry): string {
}

export function formatForTerminal(entry: LogEntry): string {
const { msg, emoji, section, symbol } = entry.getMessageState()
const empty = [msg, section, emoji, symbol].every(val => val === undefined)
const { msg, emoji, section, symbol, data } = entry.getMessageState()
const empty = [msg, section, emoji, symbol, data].every(val => val === undefined)
if (empty) {
return ""
}
Expand Down Expand Up @@ -199,8 +199,7 @@ export function cleanWhitespace(str) {

// TODO: Include individual message states with timestamp
export function formatForJson(entry: LogEntry): JsonLogEntry {
const { data } = entry
const { section } = entry.getMessageState()
const { section, data } = entry.getMessageState()
const metadata = entry.getMetadata()
const msg = chainMessages(entry.getMessageStates() || [])
return {
Expand Down
7 changes: 7 additions & 0 deletions garden-service/test/unit/src/logger/log-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe("LogEntry", () => {
section: undefined,
symbol: undefined,
status: undefined,
data: undefined,
append: undefined,
}
it("should update entry state", () => {
Expand All @@ -88,6 +89,7 @@ describe("LogEntry", () => {
section: "caesar",
symbol: "info",
status: "done",
data: { some: "data" },
metadata: { task: taskMetadata },
})

Expand All @@ -97,6 +99,7 @@ describe("LogEntry", () => {
section: "caesar",
symbol: "info",
status: "done",
data: { some: "data" },
append: undefined,
timestamp,
}])
Expand All @@ -111,10 +114,12 @@ describe("LogEntry", () => {
section: "caesar",
symbol: "info",
status: "done",
data: { some: "data" },
})
entry.setState({
msg: "world",
emoji: "hamburger",
data: { some: "data_updated" },
})
expect(entry.getMessageStates()).to.eql([
{
Expand All @@ -123,6 +128,7 @@ describe("LogEntry", () => {
section: "caesar",
symbol: "info",
status: "done",
data: { some: "data" },
append: undefined,
timestamp,
},
Expand All @@ -132,6 +138,7 @@ describe("LogEntry", () => {
section: "caesar",
symbol: "info",
status: "done",
data: { some: "data_updated" },
append: undefined,
timestamp,
},
Expand Down
20 changes: 20 additions & 0 deletions garden-service/test/unit/src/logger/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ describe("renderers", () => {
const entry = logger.placeholder()
expect(formatForTerminal(entry)).to.equal("")
})
it("should return an empty string without a new line if the parameter LogEntryParams is empty", () => {
const entry = logger.info({})
expect(formatForTerminal(entry)).to.equal("")
})
it("should return a string with a new line if any of the members of entry.messageState is not empty", () => {
const entryMsg = logger.info({ msg: "msg" })
expect(formatForTerminal(entryMsg)).contains("\n")

const entryEmoji = logger.info({ emoji: "warning" })
expect(formatForTerminal(entryEmoji)).contains("\n")

const entrySection = logger.info({ section: "section" })
expect(formatForTerminal(entrySection)).contains("\n")

const entrySymbol = logger.info({ symbol: "success" })
expect(formatForTerminal(entrySymbol)).contains("\n")

const entryData = logger.info({ data: { some: "data" } })
expect(formatForTerminal(entryData)).contains("\n")
})
})
describe("formatForJson", () => {
it("should return a JSON representation of a log entry", () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@
}
},
"snyk": true
}
}

0 comments on commit 4a8516e

Please sign in to comment.