Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion logs/lib/retrieveLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint no-use-before-define: 0 */

const BbPromise = require('bluebird');
const chalk = require('chalk');

module.exports = {
retrieveLogs() {
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = {
}

let output = logs.entries
.reduce((p, c, i) => p += `${c.timestamp}: ${c.textPayload}\n`, ''); //eslint-disable-line
.reduce((p, c, i) => p += `${chalk.grey(c.timestamp + ':')} ${c.textPayload}\n`, ''); //eslint-disable-line

output = `Displaying the ${logs.entries.length} most recent log(s):\n\n${output}`; // prettify output
output = output.slice(0, output.length - 1); // remove "\n---\n\n" for the last log entry
Expand Down
10 changes: 7 additions & 3 deletions logs/lib/retrieveLogs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const sinon = require('sinon');
const BbPromise = require('bluebird');
const chalk = require('chalk');

const GoogleProvider = require('../../provider/googleProvider');
const GoogleLogs = require('../googleLogs');
Expand Down Expand Up @@ -131,18 +132,21 @@ describe('RetrieveLogs', () => {
],
};

const logEntry1 = `${chalk.grey('1970-01-01 00:00:')} Entry 1`;
const logEntry2 = `${chalk.grey('1970-01-01 00:01:')} Entry 2`;
const expectedOutput =
'Displaying the 2 most recent log(s):\n\n1970-01-01 00:00: Entry 1\n1970-01-01 00:01: Entry 2';
`Displaying the 2 most recent log(s):\n\n${logEntry1}\n${logEntry2}`;

return googleLogs.printLogs(logs).then(() => {
expect(consoleLogStub.calledWithExactly(expectedOutput)).toEqual(true);
});
});

it('should print a default message to the console when no logs were received', () => {
const date = new Date().toISOString().slice(0, 10);
const date = `${new Date().toISOString().slice(0, 10)}:`;
const logEntry = `${chalk.grey(date)} There is no log data to show...`;
const expectedOutput =
`Displaying the 1 most recent log(s):\n\n${date}: There is no log data to show...`;
`Displaying the 1 most recent log(s):\n\n${logEntry}`;

return googleLogs.printLogs({}).then(() => {
expect(consoleLogStub.calledWithExactly(expectedOutput)).toEqual(true);
Expand Down