From 4a8516e68a7f5edef916d7413680b31c406b88c1 Mon Sep 17 00:00:00 2001 From: Emanuele Libralato Date: Mon, 2 Sep 2019 16:47:31 +0200 Subject: [PATCH] fix: task/test results outputs are not shown --- garden-service/src/logger/log-entry.ts | 5 +++-- garden-service/src/logger/renderers.ts | 9 ++++----- .../test/unit/src/logger/log-entry.ts | 7 +++++++ .../test/unit/src/logger/renderers.ts | 20 +++++++++++++++++++ package.json | 2 +- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/garden-service/src/logger/log-entry.ts b/garden-service/src/logger/log-entry.ts index 16fd90d550..bbfba819ce 100644 --- a/garden-service/src/logger/log-entry.ts +++ b/garden-service/src/logger/log-entry.ts @@ -38,6 +38,7 @@ interface MessageBase { section?: string symbol?: LogSymbol append?: boolean + data?: any } export interface MessageState extends MessageBase { @@ -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 @@ -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 @@ -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, }) } } @@ -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(), diff --git a/garden-service/src/logger/renderers.ts b/garden-service/src/logger/renderers.ts index 8be3acf9ac..f56a8b361f 100644 --- a/garden-service/src/logger/renderers.ts +++ b/garden-service/src/logger/renderers.ts @@ -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 "" } @@ -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 "" } @@ -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 { diff --git a/garden-service/test/unit/src/logger/log-entry.ts b/garden-service/test/unit/src/logger/log-entry.ts index cfe3bd29eb..5e90ffa3b1 100644 --- a/garden-service/test/unit/src/logger/log-entry.ts +++ b/garden-service/test/unit/src/logger/log-entry.ts @@ -70,6 +70,7 @@ describe("LogEntry", () => { section: undefined, symbol: undefined, status: undefined, + data: undefined, append: undefined, } it("should update entry state", () => { @@ -88,6 +89,7 @@ describe("LogEntry", () => { section: "caesar", symbol: "info", status: "done", + data: { some: "data" }, metadata: { task: taskMetadata }, }) @@ -97,6 +99,7 @@ describe("LogEntry", () => { section: "caesar", symbol: "info", status: "done", + data: { some: "data" }, append: undefined, timestamp, }]) @@ -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([ { @@ -123,6 +128,7 @@ describe("LogEntry", () => { section: "caesar", symbol: "info", status: "done", + data: { some: "data" }, append: undefined, timestamp, }, @@ -132,6 +138,7 @@ describe("LogEntry", () => { section: "caesar", symbol: "info", status: "done", + data: { some: "data_updated" }, append: undefined, timestamp, }, diff --git a/garden-service/test/unit/src/logger/renderers.ts b/garden-service/test/unit/src/logger/renderers.ts index 867496a515..b9b8d6c24a 100644 --- a/garden-service/test/unit/src/logger/renderers.ts +++ b/garden-service/test/unit/src/logger/renderers.ts @@ -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", () => { diff --git a/package.json b/package.json index 61ce93e539..8a0f2e781f 100644 --- a/package.json +++ b/package.json @@ -67,4 +67,4 @@ } }, "snyk": true -} \ No newline at end of file +}