Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through non-object valid JSON, fixes #72 #81

Merged
merged 1 commit into from Oct 8, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -55,11 +55,11 @@ module.exports = function prettyFactory (options) {
let log
if (!isObject(inputData)) {
const parsed = jsonParser(inputData)
log = parsed.value
if (parsed.err) {
if (parsed.err || !isObject(parsed.value)) {
// pass through
return inputData + EOL
}
log = parsed.value
} else {
log = inputData
}
Expand Down
17 changes: 17 additions & 0 deletions test/cli.test.js
Expand Up @@ -76,5 +76,22 @@ test('cli', (t) => {
t.tearDown(() => child.kill())
})

t.test('passes through stringified date as string', (t) => {
t.plan(1)
const child = spawn(process.argv0, [bin])
child.on('error', t.threw)

const date = JSON.stringify(new Date(epoch))

child.stdout.on('data', (data) => {
t.is(data.toString(), date + '\n')
})

child.stdin.write(date)
child.stdin.write('\n')

t.tearDown(() => child.kill())
})

t.end()
})