Skip to content

Commit 1d48943

Browse files
jamietannaClaude Sonnet 5
andauthored
test(logger): add coverage of current metaFields stringifying behaviour (#45476)
As part of future changes, we need to correct the stringification logic when `branch` is an object. Before we do this, we can make sure we have full coverage of the existing behaviour. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
1 parent a9c8f74 commit 1d48943

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

lib/logger/pretty-stdout.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ describe('logger/pretty-stdout', () => {
5151
});
5252
expect(prettyStdout.getMeta(rec, false)).toBe(' (repository=a/b) [test]');
5353
});
54+
55+
it.each([
56+
{ field: 'repository' },
57+
{ field: 'baseBranch' },
58+
{ field: 'packageFile' },
59+
{ field: 'depType' },
60+
{ field: 'dependency' },
61+
{ field: 'branch' },
62+
])(
63+
'stringifies a non-string value for the $field meta field as "[object Object]"',
64+
({ field }) => {
65+
const rec = partial<BunyanRecord>({
66+
[field]: { count: 1 },
67+
});
68+
expect(prettyStdout.getMeta(rec)).toEqual(
69+
util.styleText('gray', ` (${field}=[object Object])`),
70+
);
71+
},
72+
);
73+
74+
it('stringifies a non-string (array) value for the dependencies meta field via Array#toString', () => {
75+
const rec = partial<BunyanRecord>({
76+
dependencies: ['abc', 'def'],
77+
});
78+
expect(prettyStdout.getMeta(rec)).toEqual(
79+
util.styleText('gray', ' (dependencies=abc,def)'),
80+
);
81+
});
5482
});
5583

5684
describe('getDetails(rec)', () => {
@@ -72,6 +100,44 @@ describe('logger/pretty-stdout', () => {
72100
expect(prettyStdout.getDetails(rec)).toBeEmptyString();
73101
});
74102

103+
it.each([
104+
{ field: 'repository' },
105+
{ field: 'baseBranch' },
106+
{ field: 'packageFile' },
107+
{ field: 'depType' },
108+
{ field: 'dependency' },
109+
{ field: 'dependencies' },
110+
{ field: 'branch' },
111+
])(
112+
'drops the $field meta string field entirely from details',
113+
({ field }) => {
114+
const rec = partial<BunyanRecord>({
115+
v: 0,
116+
[field]: 'value',
117+
});
118+
expect(prettyStdout.getDetails(rec)).toBeEmptyString();
119+
},
120+
);
121+
122+
it.each([
123+
{ field: 'repository' },
124+
{ field: 'baseBranch' },
125+
{ field: 'packageFile' },
126+
{ field: 'depType' },
127+
{ field: 'dependency' },
128+
{ field: 'dependencies' },
129+
{ field: 'branch' },
130+
])(
131+
'drops the $field meta field entirely from details, even when non-string',
132+
({ field }) => {
133+
const rec = partial<BunyanRecord>({
134+
v: 0,
135+
[field]: { count: 1 },
136+
});
137+
expect(prettyStdout.getDetails(rec)).toBeEmptyString();
138+
},
139+
);
140+
75141
it('supports a config', () => {
76142
const rec = partial<BunyanRecord>({
77143
v: 0,

0 commit comments

Comments
 (0)