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
5 changes: 4 additions & 1 deletion src/components/LogView/LogViewEntry.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const TIMESTAMP_REGEX = [

const isError = str => str[0] === 'E';

const normalizeText = value =>
typeof value === 'string' ? value : JSON.stringify(value) || '';

const getLogEntryInfo = str => {
const re = getTimestampRegex();
const timeStampStr = str.match(re) ? str.match(re)[0] : '';
Expand All @@ -36,7 +39,7 @@ const getLogEntryInfo = str => {
const getTimestampRegex = () => new RegExp(TIMESTAMP_REGEX, ['i']);

const LogViewEntry = ({ text = '', timestamp }) => {
const logEntryInfo = getLogEntryInfo(text);
const logEntryInfo = getLogEntryInfo(normalizeText(text));
const classes = [styles.entry, logEntryInfo.error ? styles.error : ''];
return (
<li className={classes.join(' ')}>
Expand Down
33 changes: 33 additions & 0 deletions src/lib/tests/LogViewEntry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
jest.dontMock('../../components/LogView/LogViewEntry.react');

import React from 'react';
import renderer from 'react-test-renderer';
const LogViewEntry = require('../../components/LogView/LogViewEntry.react').default;

describe('LogViewEntry', () => {
it('renders a string log message', () => {
const text = 'I2015-09-30T00:36:45.522Z] hello world';
const tree = renderer
.create(<LogViewEntry text={text} timestamp="I2015-09-30T00:36:45.522Z]" />)
.toJSON();
expect(JSON.stringify(tree)).toContain('hello world');
});

it('does not crash when the message is a non-string object', () => {
const message = { ok: 0, code: 40352, codeName: 'Location40352', name: 'MongoError' };
let tree;
expect(() => {
tree = renderer
.create(<LogViewEntry text={message} timestamp="2021-08-20T09:59:24.974Z" />)
.toJSON();
}).not.toThrow();
expect(JSON.stringify(tree)).toContain('MongoError');
});
});
Loading