@@ -24,6 +24,7 @@ describe('sentry mocked', () => {
2424 jest . mock ( '@sentry/node' , ( ) => {
2525 return {
2626 captureException,
27+ captureMessage,
2728 withScope,
2829 Severity : {
2930 Debug : 'debug' ,
@@ -36,35 +37,33 @@ describe('sentry mocked', () => {
3637 } ) ;
3738 loggerFactory = require ( '..' ) . default ;
3839 } ) ;
40+ beforeEach ( ( ) => {
41+ captureException . mockReset ( ) ;
42+ captureMessage . mockReset ( ) ;
43+ } ) ;
3944 test ( 'can create logger with options' , ( ) => {
4045 expect ( ( ) => loggerFactory ( ) ) . not . toThrowError ( ) ;
4146 expect ( ( ) => loggerFactory ( { sentryDsn : 'DSN' } ) ) . not . toThrowError ( ) ;
4247 } ) ;
4348
44- test ( 'sentry is called with correct scope' , async ( ) => {
49+ test ( 'sentry captureMessage is called with correct scope' , async ( ) => {
4550 await new Promise ( ( resolve , reject ) => {
4651 const logger = loggerFactory ( {
4752 sentryDsn : 'DSN' ,
4853 } ) ;
49- captureException . mockImplementation ( createCapture ( resolve ) ) ;
54+ captureMessage . mockImplementation ( createCapture ( resolve ) ) ;
5055 logger . info ( 'Foo' ) ;
5156 } ) ;
52- expect ( captureException . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
57+ expect ( captureMessage ) . toHaveBeenCalledTimes ( 1 ) ;
58+ expect ( captureException ) . not . toHaveBeenCalled ( ) ;
59+ expect ( captureMessage . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
5360 Array [
54- Object {
55- "level": 30,
56- "message": "Foo",
57- "v": 1,
58- },
61+ "Foo",
5962 ]
6063 ` ) ;
61- expect ( captureException . mock . results [ 0 ] . value ) . toMatchInlineSnapshot ( `
64+ expect ( captureMessage . mock . results [ 0 ] . value ) . toMatchInlineSnapshot ( `
6265 Object {
63- "data": Object {
64- "level": 30,
65- "message": "Foo",
66- "v": 1,
67- },
66+ "data": "Foo",
6867 "scope": Object {
6968 "context": Object {
7069 "data": Object {
@@ -78,4 +77,27 @@ describe('sentry mocked', () => {
7877 }
7978 ` ) ;
8079 } ) ;
80+
81+ test ( 'sentry captureException with stack and correct levels' , async ( ) => {
82+ await new Promise ( ( resolve , reject ) => {
83+ const logger = loggerFactory ( {
84+ sentryDsn : 'DSN' ,
85+ } ) ;
86+ captureException . mockReset ( ) ;
87+ captureException . mockImplementation ( createCapture ( resolve ) ) ;
88+ logger . error ( new Error ( ) ) ;
89+ } ) ;
90+ expect ( captureException ) . toHaveBeenCalledTimes ( 1 ) ;
91+ expect ( captureMessage ) . not . toHaveBeenCalled ( ) ;
92+ expect ( captureException . mock . results [ 0 ] . value ) . toMatchObject ( {
93+ data : {
94+ level : 50 ,
95+ message : expect . any ( String ) ,
96+ stack : expect . any ( String ) ,
97+ } ,
98+ scope : {
99+ level : 'error' ,
100+ } ,
101+ } ) ;
102+ } ) ;
81103} ) ;
0 commit comments