11import "ts-jest" ;
2- import { IErrorObject , ILogObject , Logger } from "../src" ;
2+ import { IErrorObject , ILogObject , Logger , LoggerWithoutCallSite } from "../src" ;
33import { doesLogContain } from "./helper" ;
44
55let stdOut : string [ ] = [ ] ;
@@ -20,6 +20,7 @@ const loggerConfig = {
2020
2121const loggerPretty : Logger = new Logger ( { ...loggerConfig , type : "pretty" } ) ;
2222const loggerJson : Logger = new Logger ( { ...loggerConfig , type : "json" } ) ;
23+ const loggerJsonWithoutCallsite : Logger = new LoggerWithoutCallSite ( { ...loggerConfig , type : "json" } ) ;
2324
2425class TestError extends Error {
2526 constructor ( message : string ) {
@@ -65,6 +66,23 @@ describe("Logger: Error with details", () => {
6566 }
6667 } ) ;
6768
69+ test ( "JSON: Check if logger works without callsite wrapper" , ( ) : void => {
70+ try {
71+ let obj : any ;
72+ const id = obj . id ; // generating uncaught exception
73+ } catch ( err ) {
74+ loggerJsonWithoutCallsite . error ( err ) ;
75+ const logObj : ILogObject = JSON . parse ( stdErr [ 0 ] ) ;
76+ const errorObj : IErrorObject = logObj . argumentsArray ?. [ 0 ] as IErrorObject ;
77+
78+ expect ( errorObj ?. message ) . toContain (
79+ "Cannot read property 'id' of undefined"
80+ ) ;
81+
82+ expect ( errorObj ?. stack ?. [ 0 ] . fileName ) . toContain ( "error.test.ts" ) ;
83+ }
84+ } ) ;
85+
6886 test ( "Helper: Print error" , ( ) : void => {
6987 const error = new TestError ( "TestError" ) ;
7088 const errorObject = loggerJson . prettyError ( error , true ) ;
0 commit comments