smartcontext/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 11:58:34 +01:00
import * as logcontext from '../ts/index.js';
2017-10-16 09:07:19 +02:00
2018-03-03 14:11:27 +01:00
let testLogger = new logcontext.Logger('testNamespace');
2017-10-16 09:07:19 +02:00
2018-03-03 14:11:27 +01:00
tap.test('should log for .error()', async () => {
2021-09-17 19:21:34 +02:00
testLogger.error('first error message');
2018-03-03 14:11:27 +01: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 14:11:27 +01:00
testLogger.scope(async () => {
2021-09-17 19:21:34 +02:00
testLogger.logmap.addData('paramName1', {
2020-07-20 11:57:20 +00:00
someData: 'someValue',
2018-03-03 14:11:27 +01:00
});
await tools.delayFor(10).then(async () => {
testLogger.log('hi');
2021-09-17 19:21:34 +02:00
testLogger.error('custom error message');
2018-03-03 14:11:27 +01: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 14:11:27 +01:00
});
testLogger.info('anything');
});
});
2023-01-12 11:58:34 +01:00
tap.test('should log within default scope', async (toolsArg) => {
await toolsArg.delayFor(3000);
2018-03-03 14:11:27 +01:00
testLogger.log('message without context');
});
tap.start();