Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/metro/src/lib/TerminalReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class TerminalReporter {
this._logHmrClientError(event.error);
break;
case 'client_log':
logToConsole(this.terminal, event.level, event.mode, ...event.data);
logToConsole(this.terminal, event.level, ...event.data);
break;
case 'unstable_server_log':
const logFn = {
Expand Down
62 changes: 31 additions & 31 deletions packages/metro/src/lib/__tests__/logToConsole-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ beforeEach(() => {
});

test('invoke native console methods', () => {
log(console, 'log', 'BRIDGE', 'Banana');
log(console, 'warn', 'BRIDGE', 'Apple');
log(console, 'warn', 'BRIDGE', 'Kiwi');
log(console, 'log', 'Banana');
log(console, 'warn', 'Apple');
log(console, 'warn', 'Kiwi');
jest.runAllTimers();

expect(console.log).toHaveBeenNthCalledWith(1, ' LOG ', 'Banana');
Expand All @@ -44,22 +44,22 @@ test('invoke native console methods', () => {
});

test('removes excess whitespace', () => {
log(console, 'log', 'BRIDGE', 'Banana\n ');
log(console, 'log', 'Banana\n ');
jest.runAllTimers();

expect(console.log).toHaveBeenNthCalledWith(1, ' LOG ', 'Banana');
});

test('ignore `groupCollapsed` calls', () => {
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupCollapsed');
log(console, 'groupEnd');
jest.runAllTimers();

expect(console.log).not.toHaveBeenCalled();
});

test('warn if `groupCollapsed` and `groupEnd` are not balanced', () => {
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'groupCollapsed');
jest.runAllTimers();

expect(console.log).toHaveBeenCalledWith(
Expand All @@ -68,47 +68,47 @@ test('warn if `groupCollapsed` and `groupEnd` are not balanced', () => {
);

// Ensure that the console resets the state and will accept new logs
log(console, 'warn', 'BRIDGE', 'Apple');
log(console, 'warn', 'Apple');
jest.runAllTimers();
expect(console.log).toHaveBeenCalledWith(' WARN ', 'Apple');
});

test('can deal with nested `group` and `groupCollapsed` calls', () => {
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'group', 'BRIDGE');
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupCollapsed');
log(console, 'group');
log(console, 'groupCollapsed');
log(console, 'groupEnd');
log(console, 'groupEnd');
log(console, 'groupEnd');
jest.runAllTimers();

expect(console.log).not.toHaveBeenCalled();

log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'group', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupCollapsed');
log(console, 'group');
log(console, 'groupEnd');
log(console, 'groupCollapsed');
log(console, 'groupEnd');
log(console, 'groupEnd');
jest.runAllTimers();

expect(console.log).not.toHaveBeenCalled();

log(console, 'group', 'BRIDGE');
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'group');
log(console, 'groupCollapsed');
log(console, 'groupEnd');
log(console, 'groupCollapsed');
log(console, 'groupEnd');
log(console, 'groupEnd');
jest.runAllTimers();

expect(console.log).toHaveBeenCalledTimes(1);

log(console, 'groupCollapsed', 'BRIDGE');
log(console, 'group', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'groupEnd', 'BRIDGE');
log(console, 'log', 'BRIDGE', 'Banana');
log(console, 'groupCollapsed');
log(console, 'group');
log(console, 'groupEnd');
log(console, 'groupEnd');
log(console, 'log', 'Banana');
jest.runAllTimers();

expect(console.log).toHaveBeenCalledTimes(2);
Expand Down
11 changes: 2 additions & 9 deletions packages/metro/src/lib/logToConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ const util = require('util');
const groupStack = [];
let collapsedGuardTimer;

module.exports = (
terminal: Terminal,
level: string,
mode: 'BRIDGE' | 'NOBRIDGE',
...data: Array<mixed>
) => {
module.exports = (terminal: Terminal, level: string, ...data: Array<mixed>) => {
// $FlowFixMe[invalid-computed-prop]
const logFunction = console[level] && level !== 'trace' ? level : 'log';
const color =
Expand Down Expand Up @@ -66,10 +61,8 @@ module.exports = (
data[data.length - 1] = lastItem.trimEnd();
}

const modePrefix =
!mode || mode == 'BRIDGE' ? '' : `(${mode.toUpperCase()}) `;
terminal.log(
color.bold(` ${modePrefix}${logFunction.toUpperCase()} `) +
color.bold(` ${logFunction.toUpperCase()} `) +
''.padEnd(groupStack.length * 2, ' '),
// `util.format` actually accepts any arguments.
// If the first argument is a string, it tries to format it.
Expand Down
Loading