Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f656c62

Browse files
author
Michal Vlasák
committed
Add stackdriver severity tests
1 parent fa43019 commit f656c62

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

tests/index.test.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,46 @@ test('OPTIONS requests are ignored by default', () => {
141141
});
142142
});
143143
});
144+
145+
test('severity field is automatically added to log object', () => {
146+
const loggerWrites = jest.fn();
147+
const logger = loggerFactory({
148+
streams: [
149+
{
150+
stream: new stream.Writable({
151+
write: (chunk, encoding, next) => {
152+
const json = JSON.parse(chunk);
153+
expect(json.severity).toBe('CRITICAL');
154+
loggerWrites();
155+
next();
156+
},
157+
}),
158+
},
159+
],
160+
});
161+
162+
logger.fatal('Hello');
163+
expect(loggerWrites).toBeCalled();
164+
});
165+
166+
test('automatic severity field can be disabled by options', () => {
167+
const loggerWrites = jest.fn();
168+
const logger = loggerFactory({
169+
disableStackdriverFormat: true,
170+
streams: [
171+
{
172+
stream: new stream.Writable({
173+
write: (chunk, encoding, next) => {
174+
const json = JSON.parse(chunk);
175+
expect(json.severity).toBe(undefined);
176+
loggerWrites();
177+
next();
178+
},
179+
}),
180+
},
181+
],
182+
});
183+
184+
logger.fatal('Hello');
185+
expect(loggerWrites).toBeCalled();
186+
});

0 commit comments

Comments
 (0)