Skip to content

Commit 888e298

Browse files
committed
chore: fix custom time test
1 parent 799e2fd commit 888e298

4 files changed

Lines changed: 23 additions & 22 deletions

File tree

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,19 @@ module.exports = {
157157
* Note you cannot pass functions to pino-princess when using it as a pino v7 transport. These need to be configured in a pino-princess.config.js file.
158158
*/
159159
format: {
160-
formatLevel: (level) => {},
161-
formatLoadTime: (timestamp) => {},
162-
formatTime: (date) => {},
163-
formatName: (name) => {},
164-
formatMessage: (message) => {},
165-
formatBundleSize: (bundleSize) => {},
166-
formatNs: (ns) => {},
167-
formatExtraFields: (extraFields) => {},
168-
formatStack: (stack) => {},
169-
formatUrl: (url) => {},
170-
formatStatusCode: (statusCode) => {},
171-
formatErrorProp: (err) => {},
172-
formatMethod: (method) => {},
173-
formatId: (id) => {},
160+
name: (name) => {},
161+
time: (time, timeFormat) => {},
162+
level: (level) => {},
163+
'req.id': (id) => {},
164+
'req.method': (method) => {},
165+
'res.statusCode': (statusCode) => {},
166+
'req.url': (url) => {},
167+
[messageKey]: (msg) => {},
168+
responseTime: (responseTime) => {},
169+
extraFields: (extraFieldsObj, {theme}) => {},
170+
[errorKey]: (err) => {},
171+
[`${errorKey}.stack`]: (errStack) => {},
174172
},
173+
175174
};
176175
```

test/prettify.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {format} from 'date-fns';
12
import anyTest, {type TestFn} from 'ava';
23
import {prettify} from '../lib/prettify.js';
34

@@ -158,17 +159,24 @@ test('full log line with all time and extra time multiline', (t) => {
158159
});
159160

160161
test('custom time format', (t) => {
162+
const time = new Date();
163+
161164
const input = JSON.stringify({
162165
level: 30,
163-
time: 1_748_381_511_840,
166+
time,
164167
msg: 'hello',
165168
});
166169

170+
const defaultOutput = t.context.prettify(input);
171+
167172
const output = t.context
168173
.stripAnsi(prettify({timeFormat: 'yyyy-MM-dd HH:mm:ss'})(input) ?? '')
169174
.trim();
170175

171-
t.snapshot(output);
176+
const formattedTime = format(time, 'yyyy-MM-dd HH:mm:ss');
177+
178+
t.false(defaultOutput.includes(formattedTime));
179+
t.true(output.includes(`[${formattedTime}]`));
172180
});
173181

174182
test('custom message key', (t) => {

test/snapshots/dist/test/prettify.test.js.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ Generated by [AVA](https://avajs.dev).
6464
"else": "to add",␊
6565
"for": {"extra": "time"}`
6666

67-
## custom time format
68-
69-
> Snapshot 1
70-
71-
'[2025-05-27 17:31:51] ✨ INFO hello'
72-
7367
## custom formatters are merged in the same order as default
7468

7569
> Snapshot 1
-37 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)