logcontext/test/test.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-07-20 11:57:20 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2023-01-12 10:58:34 +00:00
import * as logcontext from '../ts/index.js';
2017-10-16 07:07:19 +00:00
2018-03-03 13:11:27 +00:00
let testLogger = new logcontext.Logger('testNamespace');
2017-10-16 07:07:19 +00:00
2018-03-03 13:11:27 +00:00
tap.test('should log for .error()', async () => {
2021-09-17 17:21:34 +00:00
testLogger.error('first error message');
2018-03-03 13:11:27 +00:00
});
tap.test('should log for .fatal()', async () => {
testLogger.fatal('this is fatal');
});
// set up independent log context
2020-07-20 11:57:20 +00:00
tap.testParallel('should create an async LogContext', async (tools) => {
2018-03-03 13:11:27 +00:00
testLogger.scope(async () => {
2021-09-17 17:21:34 +00:00
testLogger.logmap.addData('paramName1', {
2020-07-20 11:57:20 +00:00
someData: 'someValue',
2018-03-03 13:11:27 +00:00
});
await tools.delayFor(10).then(async () => {
testLogger.log('hi');
2021-09-17 17:21:34 +00:00
testLogger.error('custom error message');
2018-03-03 13:11:27 +00:00
});
});
});
tap.testParallel('should create a new scope', async () => {
testLogger.scope(async () => {
testLogger.logmap.addData('id1', {
2020-07-20 11:57:20 +00:00
someData: 'otherValue',
2018-03-03 13:11:27 +00:00
});
testLogger.info('anything');
});
});
2023-01-12 10:58:34 +00:00
tap.test('should log within default scope', async (toolsArg) => {
await toolsArg.delayFor(3000);
2018-03-03 13:11:27 +00:00
testLogger.log('message without context');
});
tap.start();