smartlog/test/test.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-07-12 17:21:36 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2022-06-26 08:35:35 +00:00
import * as smartlog from '../ts/index.js';
2018-01-28 03:31:06 +00:00
2020-06-08 18:51:11 +00:00
let testConsoleLog: smartlog.ConsoleLog;
let testSmartLog: smartlog.Smartlog;
tap.test('should produce a valid ConsoleLog instance', async () => {
testConsoleLog = new smartlog.ConsoleLog();
testConsoleLog.log('ok', 'this is ok');
2020-06-08 20:45:02 +00:00
});
2018-01-28 03:31:06 +00:00
2018-06-05 18:48:14 +00:00
tap.test('should produce instance of Smartlog', async () => {
2020-06-08 18:51:11 +00:00
testSmartLog = new smartlog.Smartlog({
logContext: {
environment: 'test',
runtime: 'node',
zone: 'gitzone',
company: 'Lossless GmbH',
companyunit: 'Lossless Cloud',
2020-09-07 21:30:02 +00:00
containerName: 'testing',
},
2020-06-08 18:51:11 +00:00
});
2018-01-28 03:31:06 +00:00
});
2018-06-05 18:48:14 +00:00
tap.test('should enable console logging', async () => {
2020-06-08 18:51:11 +00:00
testSmartLog.enableConsole({
2020-09-07 21:30:02 +00:00
captureAll: true,
2020-06-05 01:53:09 +00:00
});
console.log('this is a normal log that should be captured');
console.log(new Error('hi there'));
2020-06-08 18:51:11 +00:00
testSmartLog.log('info', 'this should only be printed once');
2018-01-28 03:31:06 +00:00
});
2018-06-05 18:48:14 +00:00
tap.test('should be able to log things', async () => {
2020-06-08 18:51:11 +00:00
testSmartLog.log('silly', 'hi');
2018-01-28 03:31:06 +00:00
});
2020-06-08 20:39:40 +00:00
tap.test('should create a log group', async () => {
const logGroup = testSmartLog.createLogGroup('some cool transaction');
logGroup.log('info', 'this is logged from a log group');
2020-06-08 20:45:02 +00:00
});
2020-06-08 20:39:40 +00:00
2020-06-11 13:50:35 +00:00
tap.test('should catch error', async () => {
console.error(new Error('hey'));
2020-06-11 14:28:03 +00:00
// throw new Error('hey');
2020-06-11 13:50:35 +00:00
});
2024-05-17 23:23:09 +00:00
export default tap.start();