pino-pretty
Advanced tools
Comparing version 5.0.2 to 5.1.0
@@ -33,3 +33,5 @@ 'use strict' | ||
prettifyError, | ||
deleteLogProperty | ||
deleteLogProperty, | ||
createDate, | ||
isValidDate | ||
} | ||
@@ -64,3 +66,9 @@ | ||
const instant = new Date(epoch) | ||
const instant = createDate(epoch) | ||
// If the Date is invalid, do not attempt to format | ||
if (!isValidDate(instant)) { | ||
return epoch | ||
} | ||
if (translateTime === true) { | ||
@@ -86,2 +94,34 @@ return dateformat(instant, 'UTC:' + DATE_FORMAT) | ||
/** | ||
* Constructs a JS Date from a number or string. Accepts any single number | ||
* or single string argument that is valid for the Date() constructor, | ||
* or an epoch as a string. | ||
* | ||
* @param {string|number} epoch The representation of the Date. | ||
* | ||
* @returns {Date} The constructed Date. | ||
*/ | ||
function createDate (epoch) { | ||
// If epoch is already a valid argument, return the valid Date | ||
let date = new Date(epoch) | ||
if (isValidDate(date)) { | ||
return date | ||
} | ||
// Convert to a number to permit epoch as a string | ||
date = new Date(+epoch) | ||
return date | ||
} | ||
/** | ||
* Checks if the argument is a JS Date and not 'Invalid Date'. | ||
* | ||
* @param {Date} date The date to check. | ||
* | ||
* @returns {boolean} true if the argument is a JS Date and not 'Invalid Date'. | ||
*/ | ||
function isValidDate (date) { | ||
return date instanceof Date && !Number.isNaN(date.getTime()) | ||
} | ||
function isObject (input) { | ||
@@ -88,0 +128,0 @@ return Object.prototype.toString.apply(input) === '[object Object]' |
{ | ||
"name": "pino-pretty", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"description": "Prettifier for Pino log lines", | ||
@@ -42,3 +42,3 @@ "type": "commonjs", | ||
"jmespath": "^0.15.0", | ||
"joycon": "^2.2.5", | ||
"joycon": "^3.0.0", | ||
"pump": "^3.0.0", | ||
@@ -56,4 +56,4 @@ "readable-stream": "^3.6.0", | ||
"standard": "^16.0.3", | ||
"tap": "^14.10.7", | ||
"tsd": "^0.16.0", | ||
"tap": "^15.0.0", | ||
"tsd": "^0.17.0", | ||
"typescript": "^4.2.4" | ||
@@ -60,0 +60,0 @@ }, |
@@ -25,12 +25,9 @@ 'use strict' | ||
test('basic prettifier tests', (t) => { | ||
t.beforeEach((done) => { | ||
t.beforeEach(() => { | ||
Date.originalNow = Date.now | ||
Date.now = () => epoch | ||
done() | ||
}) | ||
t.afterEach((done) => { | ||
t.afterEach(() => { | ||
Date.now = Date.originalNow | ||
delete Date.originalNow | ||
done() | ||
}) | ||
@@ -42,3 +39,3 @@ | ||
const formatted = pretty('this is not json\nit\'s just regular output\n') | ||
t.is(formatted, 'this is not json\nit\'s just regular output\n\n') | ||
t.equal(formatted, 'this is not json\nit\'s just regular output\n\n') | ||
}) | ||
@@ -52,3 +49,3 @@ | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -69,3 +66,3 @@ `[${epoch}] INFO (${pid} on ${hostname}): foo\n` | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -86,3 +83,3 @@ `[${epoch}] \u001B[32mINFO\u001B[39m (${pid} on ${hostname}): \u001B[36mfoo\u001B[39m\n` | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -103,3 +100,3 @@ `INFO [${epoch}] (${pid} on ${hostname}): foo\n` | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -120,3 +117,3 @@ `[${epoch}] INFO (${pid} on ${hostname}): baz\n` | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -137,3 +134,3 @@ `[${epoch}] WARN (${pid} on ${hostname}): foo\n` | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -156,3 +153,3 @@ `[2018-03-30 17:35:28.992 +0000] INFO (${pid} on ${hostname}): foo\n` | ||
const offset = dateformat(epoch, 'UTC:' + 'o') | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -176,3 +173,3 @@ `[${utcHour}:35:28 ${offset}] INFO (${pid} on ${hostname}): foo\n` | ||
const offset = dateformat(epoch, 'o') | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -198,3 +195,3 @@ `[${localDate} ${localHour}:35:28.992 ${offset}] INFO (${pid} on ${hostname}): foo\n` | ||
const offset = dateformat(epoch, 'o') | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -214,3 +211,3 @@ `[${localDate} ${localHour}:35:28 ${offset}] INFO (${pid} on ${hostname}): foo\n` | ||
const formatted = pretty('{"hello":"world"}') | ||
t.is(formatted, ' hello: "world"\n') | ||
t.equal(formatted, ' hello: "world"\n') | ||
}) | ||
@@ -308,3 +305,3 @@ | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `INFO (${pid} on ${hostname}): hello world\n`) | ||
t.equal(formatted, `INFO (${pid} on ${hostname}): hello world\n`) | ||
cb() | ||
@@ -343,6 +340,6 @@ } | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expectedLines.length + 2) | ||
t.equal(lines.length, expectedLines.length + 2) | ||
lines.shift(); lines.pop() | ||
for (let i = 0; i < lines.length; i += 1) { | ||
t.is(lines[i], expectedLines[i]) | ||
t.equal(lines[i], expectedLines[i]) | ||
} | ||
@@ -361,3 +358,3 @@ cb() | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `[${epoch}] INFO (matteo/${pid} on ${hostname}): hello world\n`) | ||
t.equal(formatted, `[${epoch}] INFO (matteo/${pid} on ${hostname}): hello world\n`) | ||
cb() | ||
@@ -372,9 +369,9 @@ } | ||
let formatted = pretty(null) | ||
t.is(formatted, 'null\n') | ||
t.equal(formatted, 'null\n') | ||
formatted = pretty(true) | ||
t.is(formatted, 'true\n') | ||
t.equal(formatted, 'true\n') | ||
formatted = pretty(false) | ||
t.is(formatted, 'false\n') | ||
t.equal(formatted, 'false\n') | ||
@@ -387,15 +384,15 @@ t.end() | ||
let formatted = pretty(2) | ||
t.is(formatted, '2\n') | ||
t.equal(formatted, '2\n') | ||
formatted = pretty(-2) | ||
t.is(formatted, '-2\n') | ||
t.equal(formatted, '-2\n') | ||
formatted = pretty(0.2) | ||
t.is(formatted, '0.2\n') | ||
t.equal(formatted, '0.2\n') | ||
formatted = pretty(Infinity) | ||
t.is(formatted, 'Infinity\n') | ||
t.equal(formatted, 'Infinity\n') | ||
formatted = pretty(NaN) | ||
t.is(formatted, 'NaN\n') | ||
t.equal(formatted, 'NaN\n') | ||
@@ -409,3 +406,3 @@ t.end() | ||
const formatted = pretty(undefined) | ||
t.is(formatted, 'undefined\n') | ||
t.equal(formatted, 'undefined\n') | ||
}) | ||
@@ -430,3 +427,3 @@ | ||
write (chunk, enc, cb) { | ||
t.is( | ||
t.equal( | ||
chunk.toString(), | ||
@@ -451,3 +448,3 @@ `[${epoch}] INFO (${pid} on ${hostname}): foo\n` | ||
write (formatted, enc, cb) { | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -479,3 +476,3 @@ `INFO [${epoch}] (${pid} on ${hostname}): foo\n` | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -497,5 +494,5 @@ expected.shift() | ||
let formatted = pretty(`{"msg":"nope", "time":${epoch}, "level":30}`) | ||
t.is(formatted, undefined) | ||
t.equal(formatted, undefined) | ||
formatted = pretty(`{"msg":"hello world", "time":${epoch}, "level":30}`) | ||
t.is(formatted, `[${epoch}] INFO: hello world\n`) | ||
t.equal(formatted, `[${epoch}] INFO: hello world\n`) | ||
}) | ||
@@ -512,3 +509,3 @@ | ||
const formatted = pretty(obj) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -537,6 +534,6 @@ `[${epoch}] INFO (${pid} on ${hostname}): foo\n` | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expectedLines.length + 2) | ||
t.equal(lines.length, expectedLines.length + 2) | ||
lines.shift(); lines.pop() | ||
for (let i = 0; i < lines.length; i += 1) { | ||
t.is(lines[i], expectedLines[i]) | ||
t.equal(lines[i], expectedLines[i]) | ||
} | ||
@@ -564,6 +561,6 @@ cb() | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expectedLines.length + 2) | ||
t.equal(lines.length, expectedLines.length + 2) | ||
lines.shift(); lines.pop() | ||
for (let i = 0; i < lines.length; i += 1) { | ||
t.is(lines[i], expectedLines[i]) | ||
t.equal(lines[i], expectedLines[i]) | ||
} | ||
@@ -588,3 +585,3 @@ cb() | ||
const arst = pretty('{"msg":"hello world", "foo": "bar", "cow": "moo", "level":30}') | ||
t.is(arst, 'INFO: hello world\n foo: bar_baz\n multiline\n cow: MOO\n') | ||
t.equal(arst, 'INFO: hello world\n foo: bar_baz\n multiline\n cow: MOO\n') | ||
}) | ||
@@ -601,3 +598,3 @@ | ||
const arst = pretty('{"msg":"hello world", "foo": "bar", "level":30}') | ||
t.is(arst, 'INFO: hello world\n foo: bar_baz\n') | ||
t.equal(arst, 'INFO: hello world\n foo: bar_baz\n') | ||
}) | ||
@@ -609,3 +606,3 @@ | ||
write (chunk, _, cb) { | ||
t.is( | ||
t.equal( | ||
chunk + '', | ||
@@ -635,3 +632,3 @@ `[${epoch}] INFO (${pid} on ${hostname}):\n a: {\n "b": "c"\n }\n n: null\n` | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.is(arst, `[${epoch}] INFO: hello world\n`) | ||
t.equal(arst, `[${epoch}] INFO: hello world\n`) | ||
}) | ||
@@ -643,3 +640,3 @@ | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.is(arst, `[${epoch}] INFO (on ${hostname}): hello world\n`) | ||
t.equal(arst, `[${epoch}] INFO (on ${hostname}): hello world\n`) | ||
}) | ||
@@ -651,3 +648,3 @@ | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.is(arst, `INFO (${pid} on ${hostname}): hello world\n`) | ||
t.equal(arst, `INFO (${pid} on ${hostname}): hello world\n`) | ||
}) | ||
@@ -659,3 +656,3 @@ | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.is(arst, `(${pid} on ${hostname}): hello world\n`) | ||
t.equal(arst, `(${pid} on ${hostname}): hello world\n`) | ||
}) | ||
@@ -667,3 +664,3 @@ | ||
const arst = pretty(`{"msg":"hello world", "pid":"${pid}", "hostname":"${hostname}", "time":${epoch}, "level":30}`) | ||
t.is(arst, 'hello world\n') | ||
t.equal(arst, 'hello world\n') | ||
}) | ||
@@ -690,3 +687,3 @@ | ||
const formatted = pretty(chunk.toString()) | ||
t.is( | ||
t.equal( | ||
formatted, | ||
@@ -705,3 +702,3 @@ `[${epoch}] INFO (${pid} on ${hostname}) </tmp/script.js>: foo\n` | ||
const arst = pretty(`{"msg":"hello world", "@timestamp":${epoch}, "level":30}`) | ||
t.is(arst, `[${epoch}] INFO: hello world\n`) | ||
t.equal(arst, `[${epoch}] INFO: hello world\n`) | ||
}) | ||
@@ -715,3 +712,3 @@ | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `INFO (${pid} on ${hostname}):\n v: 1\n`) | ||
t.equal(formatted, `INFO (${pid} on ${hostname}):\n v: 1\n`) | ||
cb() | ||
@@ -729,3 +726,3 @@ } | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): hello world\n`) | ||
t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): hello world\n`) | ||
cb() | ||
@@ -750,3 +747,3 @@ } | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`) | ||
t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message {"extra":{"foo":"bar","number":42},"upper":"FOOBAR"}\n`) | ||
@@ -765,3 +762,3 @@ cb() | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message\n`) | ||
t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}): message\n`) | ||
cb() | ||
@@ -768,0 +765,0 @@ } |
@@ -17,3 +17,3 @@ 'use strict' | ||
t.tearDown(() => rimraf(tmpDir, noop)) | ||
t.teardown(() => rimraf(tmpDir, noop)) | ||
@@ -30,6 +30,6 @@ t.test('loads and applies default config file: pino-pretty.config.js', (t) => { | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => { | ||
t.teardown(() => { | ||
fs.unlinkSync(configFile) | ||
@@ -50,6 +50,6 @@ child.kill() | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => { | ||
t.teardown(() => { | ||
fs.unlinkSync(configFile) | ||
@@ -70,6 +70,6 @@ child.kill() | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => { | ||
t.teardown(() => { | ||
fs.unlinkSync(configFile) | ||
@@ -90,6 +90,6 @@ child.kill() | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -107,6 +107,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -130,6 +130,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine.replace(/"msg"/, '"new_msg"')) | ||
t.tearDown(() => { | ||
t.teardown(() => { | ||
fs.unlinkSync(configFile) | ||
@@ -155,6 +155,6 @@ child.kill() | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[1594416696006] FATAL: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\nquerySql: SELECTT * FROM "test" WHERE id = $1;\nqueryArgs: 12\n') | ||
t.equal(data.toString(), '[1594416696006] FATAL: There was an error starting the process.\n QueryError: Error during sql query: syntax error at or near SELECTT\n at /home/me/projects/example/sql.js\n at /home/me/projects/example/index.js\nquerySql: SELECTT * FROM "test" WHERE id = $1;\nqueryArgs: 12\n') | ||
}) | ||
child.stdin.write('{"level":60,"time":1594416696006,"msg":"There was an error starting the process.","type":"Error","stack":"QueryError: Error during sql query: syntax error at or near SELECTT\\n at /home/me/projects/example/sql.js\\n at /home/me/projects/example/index.js","querySql":"SELECTT * FROM \\"test\\" WHERE id = $1;","queryArgs":[12]}\n') | ||
t.tearDown(() => { | ||
t.teardown(() => { | ||
fs.unlinkSync(configFile) | ||
@@ -170,7 +170,7 @@ child.kill() | ||
const child = spawn(process.argv[0], args, { env, cwd: tmpDir }) | ||
child.on('close', (code) => t.is(code, 1)) | ||
child.on('close', (code) => t.equal(code, 1)) | ||
child.stderr.on('data', (data) => { | ||
t.contains(data.toString(), 'Error: Failed to load runtime configuration file: pino-pretty.config.missing.json\n') | ||
t.equal(data.indexOf('Error: Failed to load runtime configuration file: pino-pretty.config.missing.json') >= 0, true) | ||
}) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -184,7 +184,7 @@ | ||
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir }) | ||
child.on('close', (code) => t.is(code, 1)) | ||
child.on('close', (code) => t.equal(code, 1)) | ||
child.stderr.on('data', (data) => { | ||
t.contains(data.toString(), 'Error: Invalid runtime configuration file: pino-pretty.config.js\n') | ||
t.equal(data.indexOf('Error: Invalid runtime configuration file: pino-pretty.config.js') >= 0, true) | ||
}) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -199,7 +199,7 @@ | ||
const child = spawn(process.argv[0], args, { env, cwd: tmpDir }) | ||
child.on('close', (code) => t.is(code, 1)) | ||
child.on('close', (code) => t.equal(code, 1)) | ||
child.stderr.on('data', (data) => { | ||
t.contains(data.toString(), 'Error: Invalid runtime configuration file: pino-pretty.config.invalid.js\n') | ||
t.equal(data.indexOf('Error: Invalid runtime configuration file: pino-pretty.config.invalid.js') >= 0, true) | ||
}) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -206,0 +206,0 @@ |
@@ -18,6 +18,6 @@ 'use strict' | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -31,6 +31,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), `INFO [${epoch}] (42 on foo): hello world\n`) | ||
t.equal(data.toString(), `INFO [${epoch}] (42 on foo): hello world\n`) | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -44,6 +44,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -57,6 +57,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -70,7 +70,7 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world\n`) | ||
}) | ||
child.stdin.write(logLine.replace('hello world', 'hello universe')) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -84,6 +84,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[1522431328992] INFO: hello world\n') | ||
t.equal(data.toString(), '[1522431328992] INFO: hello world\n') | ||
}) | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -100,3 +100,3 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), date + '\n') | ||
t.equal(data.toString(), date + '\n') | ||
}) | ||
@@ -107,3 +107,3 @@ | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -117,7 +117,7 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), '[1522431328992] INFO: hello world\n') | ||
t.equal(data.toString(), '[1522431328992] INFO: hello world\n') | ||
}) | ||
const logLine = '{"level":30,"@timestamp":1522431328992,"msg":"hello world"}\n' | ||
child.stdin.write(logLine) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -139,6 +139,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world {"extra":{"foo":"bar","number":42}}\n`) | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world {"extra":{"foo":"bar","number":42}}\n`) | ||
}) | ||
child.stdin.write(logLineWithExtra) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -163,6 +163,6 @@ | ||
child.stdout.on('data', (data) => { | ||
t.is(data.toString(), `[${epoch}] INFO (42 on foo): hello world {"extra":{"number":42}}\n`) | ||
t.equal(data.toString(), `[${epoch}] INFO (42 on foo): hello world {"extra":{"number":42}}\n`) | ||
}) | ||
child.stdin.write(logLineNested) | ||
t.tearDown(() => child.kill()) | ||
t.teardown(() => child.kill()) | ||
}) | ||
@@ -169,0 +169,0 @@ |
@@ -22,3 +22,3 @@ 'use strict' | ||
const formatted = pretty(logLine) | ||
t.is(formatted.substr(-2), 'd\n') | ||
t.equal(formatted.substr(-2), 'd\n') | ||
}) | ||
@@ -30,3 +30,3 @@ | ||
const formatted = pretty(logLine) | ||
t.is(formatted.substr(-3), 'd\r\n') | ||
t.equal(formatted.substr(-3), 'd\r\n') | ||
}) | ||
@@ -33,0 +33,0 @@ |
@@ -25,13 +25,9 @@ 'use strict' | ||
test('error like objects tests', (t) => { | ||
t.beforeEach((done) => { | ||
t.beforeEach(() => { | ||
Date.originalNow = Date.now | ||
Date.now = () => epoch | ||
done() | ||
}) | ||
t.afterEach((done) => { | ||
t.afterEach(() => { | ||
Date.now = Date.originalNow | ||
delete Date.originalNow | ||
done() | ||
}) | ||
@@ -50,4 +46,4 @@ | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expected.length + 1) | ||
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): hello world`) | ||
t.equal(lines.length, expected.length + 1) | ||
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): hello world`) | ||
cb() | ||
@@ -102,4 +98,4 @@ } | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expected.length + 6) | ||
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) | ||
t.equal(lines.length, expected.length + 6) | ||
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) | ||
t.match(lines[1], /\s{4}err: {/) | ||
@@ -138,4 +134,4 @@ t.match(lines[2], /\s{6}"type": "Error",/) | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expected.length + 5) | ||
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): {"extra":{"a":1,"b":2}}`) | ||
t.equal(lines.length, expected.length + 5) | ||
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}): {"extra":{"a":1,"b":2}}`) | ||
t.match(lines[1], /\s{4}err: {/) | ||
@@ -172,3 +168,3 @@ t.match(lines[2], /\s{6}"type": "Error",/) | ||
const formatted = pretty(chunk.toString()) | ||
t.is(formatted, `[${epoch}] INFO (${pid} on ${hostname}):\n err: error is hello world\n`) | ||
t.equal(formatted, `[${epoch}] INFO (${pid} on ${hostname}):\n err: error is hello world\n`) | ||
cb() | ||
@@ -196,4 +192,4 @@ } | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expected.length + 6) | ||
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) | ||
t.equal(lines.length, expected.length + 6) | ||
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) | ||
t.match(lines[1], /\s{4}err: {$/) | ||
@@ -227,4 +223,4 @@ t.match(lines[2], /\s{6}"type": "Error",$/) | ||
const lines = formatted.split('\n') | ||
t.is(lines.length, expected.length + 7) | ||
t.is(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) | ||
t.equal(lines.length, expected.length + 7) | ||
t.equal(lines[0], `[${epoch}] INFO (${pid} on ${hostname}):`) | ||
t.match(lines[1], /\s{4}err: {/) | ||
@@ -265,3 +261,3 @@ t.match(lines[2], /\s{6}"type": "Error",/) | ||
for (let i = 0; i < lines.length; i += 1) { | ||
t.is(lines[i], expectedLines[i]) | ||
t.equal(lines[i], expectedLines[i]) | ||
} | ||
@@ -316,3 +312,3 @@ cb() | ||
for (let i = 0; i < lines.length; i += 1) { | ||
t.true(expectedLines.includes(lines[i])) | ||
t.ok(expectedLines.includes(lines[i])) | ||
} | ||
@@ -319,0 +315,0 @@ cb() |
@@ -9,33 +9,33 @@ 'use strict' | ||
let colorized = colorizer(10) | ||
t.is(colorized, 'TRACE') | ||
t.equal(colorized, 'TRACE') | ||
colorized = colorizer(20) | ||
t.is(colorized, 'DEBUG') | ||
t.equal(colorized, 'DEBUG') | ||
colorized = colorizer(30) | ||
t.is(colorized, 'INFO') | ||
t.equal(colorized, 'INFO') | ||
colorized = colorizer(40) | ||
t.is(colorized, 'WARN') | ||
t.equal(colorized, 'WARN') | ||
colorized = colorizer(50) | ||
t.is(colorized, 'ERROR') | ||
t.equal(colorized, 'ERROR') | ||
colorized = colorizer(60) | ||
t.is(colorized, 'FATAL') | ||
t.equal(colorized, 'FATAL') | ||
colorized = colorizer(900) | ||
t.is(colorized, 'USERLVL') | ||
t.equal(colorized, 'USERLVL') | ||
colorized = colorizer('info') | ||
t.is(colorized, 'INFO') | ||
t.equal(colorized, 'INFO') | ||
colorized = colorizer('use-default') | ||
t.is(colorized, 'USERLVL') | ||
t.equal(colorized, 'USERLVL') | ||
colorized = colorizer.message('foo') | ||
t.is(colorized, 'foo') | ||
t.equal(colorized, 'foo') | ||
colorized = colorizer.greyMessage('foo') | ||
t.is(colorized, 'foo') | ||
t.equal(colorized, 'foo') | ||
}) | ||
@@ -46,33 +46,33 @@ | ||
let colorized = colorizer(10) | ||
t.is(colorized, '\u001B[90mTRACE\u001B[39m') | ||
t.equal(colorized, '\u001B[90mTRACE\u001B[39m') | ||
colorized = colorizer(20) | ||
t.is(colorized, '\u001B[34mDEBUG\u001B[39m') | ||
t.equal(colorized, '\u001B[34mDEBUG\u001B[39m') | ||
colorized = colorizer(30) | ||
t.is(colorized, '\u001B[32mINFO\u001B[39m') | ||
t.equal(colorized, '\u001B[32mINFO\u001B[39m') | ||
colorized = colorizer(40) | ||
t.is(colorized, '\u001B[33mWARN\u001B[39m') | ||
t.equal(colorized, '\u001B[33mWARN\u001B[39m') | ||
colorized = colorizer(50) | ||
t.is(colorized, '\u001B[31mERROR\u001B[39m') | ||
t.equal(colorized, '\u001B[31mERROR\u001B[39m') | ||
colorized = colorizer(60) | ||
t.is(colorized, '\u001B[41mFATAL\u001B[49m') | ||
t.equal(colorized, '\u001B[41mFATAL\u001B[49m') | ||
colorized = colorizer(900) | ||
t.is(colorized, '\u001B[37mUSERLVL\u001B[39m') | ||
t.equal(colorized, '\u001B[37mUSERLVL\u001B[39m') | ||
colorized = colorizer('info') | ||
t.is(colorized, '\u001B[32mINFO\u001B[39m') | ||
t.equal(colorized, '\u001B[32mINFO\u001B[39m') | ||
colorized = colorizer('use-default') | ||
t.is(colorized, '\u001B[37mUSERLVL\u001B[39m') | ||
t.equal(colorized, '\u001B[37mUSERLVL\u001B[39m') | ||
colorized = colorizer.message('foo') | ||
t.is(colorized, '\u001B[36mfoo\u001B[39m') | ||
t.equal(colorized, '\u001B[36mfoo\u001B[39m') | ||
colorized = colorizer.greyMessage('foo') | ||
t.is(colorized, '\u001B[90mfoo\u001B[39m') | ||
t.equal(colorized, '\u001B[90mfoo\u001B[39m') | ||
}) |
@@ -12,3 +12,3 @@ 'use strict' | ||
const result = internals.joinLinesWithIndentation({ input }) | ||
t.is(result, 'foo\n bar\n baz') | ||
t.equal(result, 'foo\n bar\n baz') | ||
}) | ||
@@ -19,3 +19,3 @@ | ||
const result = internals.joinLinesWithIndentation({ input, ident: ' ', eol: '^' }) | ||
t.is(result, 'foo^ bar^ baz') | ||
t.equal(result, 'foo^ bar^ baz') | ||
}) | ||
@@ -33,3 +33,3 @@ | ||
const formattedTime = internals.formatTime(epochMS) | ||
t.is(formattedTime, epochMS) | ||
t.equal(formattedTime, epochMS) | ||
}) | ||
@@ -39,3 +39,3 @@ | ||
const formattedTime = internals.formatTime(epochMS, true) | ||
t.is(formattedTime, '2019-04-06 17:30:00.000 +0000') | ||
t.equal(formattedTime, '2019-04-06 17:30:00.000 +0000') | ||
}) | ||
@@ -45,3 +45,3 @@ | ||
const formattedTime = internals.formatTime(epochMS, 'd mmm yyyy H:MM') | ||
t.is(formattedTime, '6 Apr 2019 17:30') | ||
t.equal(formattedTime, '6 Apr 2019 17:30') | ||
}) | ||
@@ -61,3 +61,3 @@ | ||
const formattedTime = internals.formatTime(dateStr) | ||
t.is(formattedTime, dateStr) | ||
t.equal(formattedTime, dateStr) | ||
}) | ||
@@ -67,3 +67,3 @@ | ||
const formattedTime = internals.formatTime(dateStr, true) | ||
t.is(formattedTime, '2019-04-06 17:30:00.000 +0000') | ||
t.equal(formattedTime, '2019-04-06 17:30:00.000 +0000') | ||
}) | ||
@@ -73,3 +73,3 @@ | ||
const formattedTime = internals.formatTime(dateStr, 'd mmm yyyy H:MM') | ||
t.is(formattedTime, '6 Apr 2019 17:30') | ||
t.equal(formattedTime, '6 Apr 2019 17:30') | ||
}) | ||
@@ -84,3 +84,3 @@ | ||
const formattedTime = internals.formatTime(dateStr, 'UTC:d mmm yyyy H:MM') | ||
t.is(formattedTime, '6 Apr 2019 17:30') | ||
t.equal(formattedTime, '6 Apr 2019 17:30') | ||
}) | ||
@@ -96,2 +96,36 @@ | ||
tap.test('#createDate', t => { | ||
const wanted = 1624450038567 | ||
t.test('accepts arguments the Date constructor would accept', async t => { | ||
t.plan(2) | ||
t.same(internals.createDate(1624450038567).getTime(), wanted) | ||
t.same(internals.createDate('2021-06-23T12:07:18.567Z').getTime(), wanted) | ||
}) | ||
t.test('accepts epoch as a string', async t => { | ||
// If Date() accepts this argument, the createDate function is not needed | ||
// and can be replaced with Date() | ||
t.plan(2) | ||
t.notSame(new Date('16244500385-67').getTime(), wanted) | ||
t.same(internals.createDate('1624450038567').getTime(), wanted) | ||
}) | ||
t.end() | ||
}) | ||
tap.test('#isValidDate', t => { | ||
t.test('returns true for valid dates', async t => { | ||
t.same(internals.isValidDate(new Date()), true) | ||
}) | ||
t.test('returns false for non-dates and invalid dates', async t => { | ||
t.plan(2) | ||
t.same(internals.isValidDate('20210621'), false) | ||
t.same(internals.isValidDate(new Date('2021-41-99')), false) | ||
}) | ||
t.end() | ||
}) | ||
tap.test('#prettifyError', t => { | ||
@@ -98,0 +132,0 @@ t.test('prettifies error', t => { |
@@ -13,3 +13,3 @@ 'use strict' | ||
const str = prettifyErrorLog({ log: err }) | ||
t.true(str.startsWith(' Error: Something went wrong')) | ||
t.ok(str.startsWith(' Error: Something went wrong')) | ||
}) | ||
@@ -20,3 +20,3 @@ | ||
const str = prettifyErrorLog({ log: err, ident: ' ' }) | ||
t.true(str.startsWith(' Error: Something went wrong')) | ||
t.ok(str.startsWith(' Error: Something went wrong')) | ||
}) | ||
@@ -27,3 +27,3 @@ | ||
const str = prettifyErrorLog({ log: err, eol: '\r\n' }) | ||
t.true(str.startsWith(' Error: Something went wrong\r\n')) | ||
t.ok(str.startsWith(' Error: Something went wrong\r\n')) | ||
}) | ||
@@ -39,3 +39,3 @@ | ||
const colorized = prettifyLevel({ log: {} }) | ||
t.is(colorized, undefined) | ||
t.equal(colorized, undefined) | ||
}) | ||
@@ -48,3 +48,3 @@ | ||
const colorized = prettifyLevel({ log }) | ||
t.is(colorized, 'INFO') | ||
t.equal(colorized, 'INFO') | ||
}) | ||
@@ -58,3 +58,3 @@ | ||
const colorized = prettifyLevel({ log, colorizer }) | ||
t.is(colorized, '\u001B[32mINFO\u001B[39m') | ||
t.equal(colorized, '\u001B[32mINFO\u001B[39m') | ||
}) | ||
@@ -70,3 +70,3 @@ | ||
const str = prettifyMessage({ log: {} }) | ||
t.is(str, undefined) | ||
t.equal(str, undefined) | ||
}) | ||
@@ -76,3 +76,3 @@ | ||
const str = prettifyMessage({ log: { msg: {} } }) | ||
t.is(str, undefined) | ||
t.equal(str, undefined) | ||
}) | ||
@@ -82,3 +82,3 @@ | ||
const str = prettifyMessage({ log: { msg: 'foo' } }) | ||
t.is(str, 'foo') | ||
t.equal(str, 'foo') | ||
}) | ||
@@ -88,3 +88,3 @@ | ||
const str = prettifyMessage({ log: { message: 'foo' }, messageKey: 'message' }) | ||
t.is(str, 'foo') | ||
t.equal(str, 'foo') | ||
}) | ||
@@ -95,3 +95,3 @@ | ||
const str = prettifyMessage({ log: { msg: 'foo' }, colorizer }) | ||
t.is(str, '\u001B[36mfoo\u001B[39m') | ||
t.equal(str, '\u001B[36mfoo\u001B[39m') | ||
}) | ||
@@ -102,3 +102,3 @@ | ||
const str = prettifyMessage({ log: { message: 'foo' }, messageKey: 'message', colorizer }) | ||
t.is(str, '\u001B[36mfoo\u001B[39m') | ||
t.equal(str, '\u001B[36mfoo\u001B[39m') | ||
}) | ||
@@ -108,3 +108,3 @@ | ||
const str = prettifyMessage({ log: { msg: 'foo', context: 'appModule' }, messageFormat: '{context} - {msg}' }) | ||
t.is(str, 'appModule - foo') | ||
t.equal(str, 'appModule - foo') | ||
}) | ||
@@ -114,3 +114,3 @@ | ||
const str = prettifyMessage({ log: { context: 'appModule' }, messageFormat: '{context} - {msg}' }) | ||
t.is(str, 'appModule - ') | ||
t.equal(str, 'appModule - ') | ||
}) | ||
@@ -120,3 +120,3 @@ | ||
const str = prettifyMessage({ log: { msg: 'foo', context: 'appModule', level: 30 }, messageFormat: '[{level}] {levelLabel} {context} - {msg}' }) | ||
t.is(str, '[30] INFO appModule - foo') | ||
t.equal(str, '[30] INFO appModule - foo') | ||
}) | ||
@@ -126,3 +126,3 @@ | ||
const str = prettifyMessage({ log: { level: 30 }, messageFormat: '{{level}}-{level}-{{level}-{level}}' }) | ||
t.is(str, '{30}-30-{30-30}') | ||
t.equal(str, '{30}-30-{30-30}') | ||
}) | ||
@@ -132,3 +132,3 @@ | ||
const str = prettifyMessage({ log: { level: 30, request: { url: 'localhost/test' }, msg: 'foo' }, messageFormat: '{request.url} - param: {request.params.process} - {msg}' }) | ||
t.is(str, 'localhost/test - param: - foo') | ||
t.equal(str, 'localhost/test - param: - foo') | ||
}) | ||
@@ -145,3 +145,3 @@ | ||
}) | ||
t.is(str, '--> localhost/test') | ||
t.equal(str, '--> localhost/test') | ||
}) | ||
@@ -157,3 +157,3 @@ | ||
const str = prettifyMetadata({ log: {} }) | ||
t.is(str, undefined) | ||
t.equal(str, undefined) | ||
}) | ||
@@ -163,3 +163,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo' } }) | ||
t.is(str, '(foo)') | ||
t.equal(str, '(foo)') | ||
}) | ||
@@ -169,3 +169,3 @@ | ||
const str = prettifyMetadata({ log: { pid: '1234' } }) | ||
t.is(str, '(1234)') | ||
t.equal(str, '(1234)') | ||
}) | ||
@@ -175,3 +175,3 @@ | ||
const str = prettifyMetadata({ log: { hostname: 'bar' } }) | ||
t.is(str, '(on bar)') | ||
t.equal(str, '(on bar)') | ||
}) | ||
@@ -181,3 +181,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', pid: '1234' } }) | ||
t.is(str, '(foo/1234)') | ||
t.equal(str, '(foo/1234)') | ||
}) | ||
@@ -187,3 +187,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', hostname: 'bar' } }) | ||
t.is(str, '(foo on bar)') | ||
t.equal(str, '(foo on bar)') | ||
}) | ||
@@ -193,3 +193,3 @@ | ||
const str = prettifyMetadata({ log: { pid: '1234', hostname: 'bar' } }) | ||
t.is(str, '(1234 on bar)') | ||
t.equal(str, '(1234 on bar)') | ||
}) | ||
@@ -199,3 +199,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', pid: '1234', hostname: 'bar' } }) | ||
t.is(str, '(foo/1234 on bar)') | ||
t.equal(str, '(foo/1234 on bar)') | ||
}) | ||
@@ -205,3 +205,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', caller: 'baz' } }) | ||
t.is(str, '(foo) <baz>') | ||
t.equal(str, '(foo) <baz>') | ||
}) | ||
@@ -211,3 +211,3 @@ | ||
const str = prettifyMetadata({ log: { pid: '1234', caller: 'baz' } }) | ||
t.is(str, '(1234) <baz>') | ||
t.equal(str, '(1234) <baz>') | ||
}) | ||
@@ -217,3 +217,3 @@ | ||
const str = prettifyMetadata({ log: { hostname: 'bar', caller: 'baz' } }) | ||
t.is(str, '(on bar) <baz>') | ||
t.equal(str, '(on bar) <baz>') | ||
}) | ||
@@ -223,3 +223,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', pid: '1234', caller: 'baz' } }) | ||
t.is(str, '(foo/1234) <baz>') | ||
t.equal(str, '(foo/1234) <baz>') | ||
}) | ||
@@ -229,3 +229,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', hostname: 'bar', caller: 'baz' } }) | ||
t.is(str, '(foo on bar) <baz>') | ||
t.equal(str, '(foo on bar) <baz>') | ||
}) | ||
@@ -235,3 +235,3 @@ | ||
const str = prettifyMetadata({ log: { caller: 'baz' } }) | ||
t.is(str, '<baz>') | ||
t.equal(str, '<baz>') | ||
}) | ||
@@ -241,3 +241,3 @@ | ||
const str = prettifyMetadata({ log: { pid: '1234', hostname: 'bar', caller: 'baz' } }) | ||
t.is(str, '(1234 on bar) <baz>') | ||
t.equal(str, '(1234 on bar) <baz>') | ||
}) | ||
@@ -247,3 +247,3 @@ | ||
const str = prettifyMetadata({ log: { name: 'foo', pid: '1234', hostname: 'bar', caller: 'baz' } }) | ||
t.is(str, '(foo/1234 on bar) <baz>') | ||
t.equal(str, '(foo/1234 on bar) <baz>') | ||
}) | ||
@@ -259,3 +259,3 @@ | ||
const str = prettifyObject({ input: {} }) | ||
t.is(str, '') | ||
t.equal(str, '') | ||
}) | ||
@@ -265,3 +265,3 @@ | ||
const str = prettifyObject({ input: { foo: 'bar' } }) | ||
t.is(str, ' foo: "bar"\n') | ||
t.equal(str, ' foo: "bar"\n') | ||
}) | ||
@@ -271,3 +271,3 @@ | ||
const str = prettifyObject({ input: { foo: { bar: 'baz' } } }) | ||
t.is(str, ' foo: {\n "bar": "baz"\n }\n') | ||
t.equal(str, ' foo: {\n "bar": "baz"\n }\n') | ||
}) | ||
@@ -277,3 +277,3 @@ | ||
const str = prettifyObject({ input: { foo: 'bar', hello: 'world' }, skipKeys: ['foo'] }) | ||
t.is(str, ' hello: "world"\n') | ||
t.equal(str, ' hello: "world"\n') | ||
}) | ||
@@ -283,3 +283,3 @@ | ||
const str = prettifyObject({ input: { foo: 'bar', pid: 12345 } }) | ||
t.is(str, ' foo: "bar"\n') | ||
t.equal(str, ' foo: "bar"\n') | ||
}) | ||
@@ -294,5 +294,5 @@ | ||
const str = prettifyObject({ input: { error: serializedError } }) | ||
t.true(str.startsWith(' error:')) | ||
t.true(str.includes(' "message": "Something went wrong",')) | ||
t.true(str.includes(' Error: Something went wrong')) | ||
t.ok(str.startsWith(' error:')) | ||
t.ok(str.includes(' "message": "Something went wrong",')) | ||
t.ok(str.includes(' Error: Something went wrong')) | ||
}) | ||
@@ -308,3 +308,3 @@ | ||
const str = prettifyTime({ log: {} }) | ||
t.is(str, undefined) | ||
t.equal(str, undefined) | ||
}) | ||
@@ -315,6 +315,6 @@ | ||
let str = prettifyTime({ log, translateFormat: true, timestampKey: 'customtime' }) | ||
t.is(str, '[2019-04-07 13:15:00.000 +0000]') | ||
t.equal(str, '[2019-04-07 13:15:00.000 +0000]') | ||
str = prettifyTime({ log, translateFormat: false, timestampKey: 'customtime' }) | ||
t.is(str, '[1554642900000]') | ||
t.equal(str, '[1554642900000]') | ||
}) | ||
@@ -325,31 +325,31 @@ | ||
let str = prettifyTime({ log, translateFormat: true }) | ||
t.is(str, '[2019-04-07 13:15:00.000 +0000]') | ||
t.equal(str, '[2019-04-07 13:15:00.000 +0000]') | ||
log = { timestamp: 1554642900000 } | ||
str = prettifyTime({ log, translateFormat: true }) | ||
t.is(str, '[2019-04-07 13:15:00.000 +0000]') | ||
t.equal(str, '[2019-04-07 13:15:00.000 +0000]') | ||
log = { time: '2019-04-07T09:15:00.000-04:00' } | ||
str = prettifyTime({ log, translateFormat: true }) | ||
t.is(str, '[2019-04-07 13:15:00.000 +0000]') | ||
t.equal(str, '[2019-04-07 13:15:00.000 +0000]') | ||
log = { timestamp: '2019-04-07T09:15:00.000-04:00' } | ||
str = prettifyTime({ log, translateFormat: true }) | ||
t.is(str, '[2019-04-07 13:15:00.000 +0000]') | ||
t.equal(str, '[2019-04-07 13:15:00.000 +0000]') | ||
log = { time: 1554642900000 } | ||
str = prettifyTime({ log, translateFormat: 'd mmm yyyy H:MM' }) | ||
t.is(str, '[7 Apr 2019 13:15]') | ||
t.equal(str, '[7 Apr 2019 13:15]') | ||
log = { timestamp: 1554642900000 } | ||
str = prettifyTime({ log, translateFormat: 'd mmm yyyy H:MM' }) | ||
t.is(str, '[7 Apr 2019 13:15]') | ||
t.equal(str, '[7 Apr 2019 13:15]') | ||
log = { time: '2019-04-07T09:15:00.000-04:00' } | ||
str = prettifyTime({ log, translateFormat: 'd mmm yyyy H:MM' }) | ||
t.is(str, '[7 Apr 2019 13:15]') | ||
t.equal(str, '[7 Apr 2019 13:15]') | ||
log = { timestamp: '2019-04-07T09:15:00.000-04:00' } | ||
str = prettifyTime({ log, translateFormat: 'd mmm yyyy H:MM' }) | ||
t.is(str, '[7 Apr 2019 13:15]') | ||
t.equal(str, '[7 Apr 2019 13:15]') | ||
}) | ||
@@ -360,15 +360,15 @@ | ||
let str = prettifyTime({ log }) | ||
t.is(str, '[1554642900000]') | ||
t.equal(str, '[1554642900000]') | ||
log = { timestamp: 1554642900000 } | ||
str = prettifyTime({ log }) | ||
t.is(str, '[1554642900000]') | ||
t.equal(str, '[1554642900000]') | ||
log = { time: '2019-04-07T09:15:00.000-04:00' } | ||
str = prettifyTime({ log }) | ||
t.is(str, '[2019-04-07T09:15:00.000-04:00]') | ||
t.equal(str, '[2019-04-07T09:15:00.000-04:00]') | ||
log = { timestamp: '2019-04-07T09:15:00.000-04:00' } | ||
str = prettifyTime({ log }) | ||
t.is(str, '[2019-04-07T09:15:00.000-04:00]') | ||
t.equal(str, '[2019-04-07T09:15:00.000-04:00]') | ||
}) | ||
@@ -379,9 +379,29 @@ | ||
let str = prettifyTime({ log }) | ||
t.is(str, '[0]') | ||
t.equal(str, '[0]') | ||
log = { timestamp: 0 } | ||
str = prettifyTime({ log }) | ||
t.is(str, '[0]') | ||
t.equal(str, '[0]') | ||
}) | ||
t.test('works with epoch as a number or string', (t) => { | ||
t.plan(3) | ||
const epoch = 1522431328992 | ||
const asNumber = prettifyTime({ | ||
log: { time: epoch, msg: 'foo' }, | ||
translateFormat: true | ||
}) | ||
const asString = prettifyTime({ | ||
log: { time: `${epoch}`, msg: 'foo' }, | ||
translateFormat: true | ||
}) | ||
const invalid = prettifyTime({ | ||
log: { time: '2 days ago', msg: 'foo' }, | ||
translateFormat: true | ||
}) | ||
t.same(asString, '[2018-03-30 17:35:28.992 +0000]') | ||
t.same(asNumber, '[2018-03-30 17:35:28.992 +0000]') | ||
t.same(invalid, '[2 days ago]') | ||
}) | ||
t.end() | ||
@@ -388,0 +408,0 @@ }) |
Sorry, the diff of this file is not supported yet
292390
2799
+ Addedjoycon@3.1.1(transitive)
- Removedjoycon@2.2.5(transitive)
Updatedjoycon@^3.0.0