55 * LICENSE file in the root directory of this source tree.
66 */
77
8- import { bigIntUtils } from '@hathor/wallet-lib' ;
98import { eventHandler , getSettings } from '../../src/plugins/hathor_debug' ;
9+ import * as logger from '../../src/logger' ;
1010
1111test ( 'settings' , ( ) => {
1212 const oldArgs = process . argv ;
@@ -27,10 +27,11 @@ test('settings', () => {
2727
2828test ( 'event handler' , ( ) => {
2929 const oldArgs = process . argv ;
30- const logSpy = jest . spyOn ( console , 'log' ) ;
31- const smallMsg = { type : 'small' , walletId : 'default' , foo : 'bar' , bigInt : BigInt ( Number . MAX_SAFE_INTEGER ) + 1n } ;
30+ const mockLoggerInfo = jest . fn ( ) ;
31+ const buildAppLoggerSpy = jest . spyOn ( logger , 'buildAppLogger' ) . mockReturnValue ( { info : mockLoggerInfo } ) ;
32+ const smallMsg = { type : 'small' , walletId : 'default' , foo : 'bar' } ;
3233 const bigMsg = { type : 'big' , walletId : 'default' } ;
33- const bigCompleteMsg = { ...bigMsg , message : '' , bigInt : BigInt ( Number . MAX_SAFE_INTEGER ) + 1n } ;
34+ const bigCompleteMsg = { ...bigMsg , message : '' } ;
3435 for ( let i = 0 ; i < 200 ; i ++ ) {
3536 // 200 * 'aaaaa'(length of 5) -> lenght of 1000
3637 bigCompleteMsg . message += 'aaaaa' ;
@@ -46,30 +47,30 @@ test('event handler', () => {
4647 '--plugin_debug_long' , 'off' ,
4748 ] ;
4849 getSettings ( ) ; // set debugLong value
49- logSpy . mockReset ( ) ;
50+ mockLoggerInfo . mockReset ( ) ;
5051 // small message: always log
5152 eventHandler ( smallMsg ) ;
52- expect ( logSpy ) . toHaveBeenCalledWith ( toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( smallMsg ) ) ) ;
53- logSpy . mockReset ( ) ;
53+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( toDebugMessage ( JSON . stringify ( smallMsg ) ) ) ;
54+ mockLoggerInfo . mockReset ( ) ;
5455 // big message: should not log
5556 eventHandler ( bigCompleteMsg ) ;
56- expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
57+ expect ( mockLoggerInfo ) . not . toHaveBeenCalled ( ) ;
5758
5859 // debugLong: all
5960 process . argv = [
6061 'node' , 'a_script_file.js' , // not used but a value is required
6162 '--plugin_debug_long' , 'all' ,
6263 ] ;
6364 getSettings ( ) ; // set debugLong value
64- logSpy . mockReset ( ) ;
65+ mockLoggerInfo . mockReset ( ) ;
6566 // small message: always log
6667 eventHandler ( smallMsg ) ;
67- expect ( logSpy ) . toHaveBeenCalledWith ( toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( smallMsg ) ) ) ;
68- logSpy . mockReset ( ) ;
68+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( toDebugMessage ( JSON . stringify ( smallMsg ) ) ) ;
69+ mockLoggerInfo . mockReset ( ) ;
6970 // big message: should log the entire message
7071 eventHandler ( bigCompleteMsg ) ;
71- expect ( logSpy ) . toHaveBeenCalledWith (
72- toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( bigCompleteMsg ) )
72+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith (
73+ toDebugMessage ( JSON . stringify ( bigCompleteMsg ) )
7374 ) ;
7475
7576 // debugLong: unexpected value
@@ -78,30 +79,30 @@ test('event handler', () => {
7879 '--plugin_debug_long' , 'any-unexpected-value' ,
7980 ] ;
8081 getSettings ( ) ; // set debugLong value
81- logSpy . mockReset ( ) ;
82+ mockLoggerInfo . mockReset ( ) ;
8283 // small message: always log
8384 eventHandler ( smallMsg ) ;
84- expect ( logSpy ) . toHaveBeenCalledWith ( toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( smallMsg ) ) ) ;
85- logSpy . mockReset ( ) ;
85+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( toDebugMessage ( JSON . stringify ( smallMsg ) ) ) ;
86+ mockLoggerInfo . mockReset ( ) ;
8687 // big message: should log partially
8788 eventHandler ( bigCompleteMsg ) ;
88- expect ( logSpy ) . toHaveBeenCalledWith ( toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( bigMsg ) ) ) ;
89+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( toDebugMessage ( JSON . stringify ( bigMsg ) ) ) ;
8990
9091 // debugLong: default (should be the same as unexpected)
9192 process . argv = [
9293 'node' , 'a_script_file.js' , // not used but a value is required
9394 ] ;
9495 getSettings ( ) ; // set debugLong value
95- logSpy . mockReset ( ) ;
96+ mockLoggerInfo . mockReset ( ) ;
9697 // small message: always log
9798 eventHandler ( smallMsg ) ;
98- expect ( logSpy ) . toHaveBeenCalledWith ( toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( smallMsg ) ) ) ;
99- logSpy . mockReset ( ) ;
99+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( toDebugMessage ( JSON . stringify ( smallMsg ) ) ) ;
100+ mockLoggerInfo . mockReset ( ) ;
100101 // big message: should log partially
101102 eventHandler ( bigCompleteMsg ) ;
102- expect ( logSpy ) . toHaveBeenCalledWith ( toDebugMessage ( bigIntUtils . JSONBigInt . stringify ( bigMsg ) ) ) ;
103+ expect ( mockLoggerInfo ) . toHaveBeenCalledWith ( toDebugMessage ( JSON . stringify ( bigMsg ) ) ) ;
103104
104105 // Restore original argv state
105106 process . argv = oldArgs ;
106- logSpy . mockRestore ( ) ;
107+ buildAppLoggerSpy . mockRestore ( ) ;
107108} ) ;
0 commit comments