5
5
*/
6
6
'use strict' ;
7
7
8
- jest . mock ( 'raven ' ) ;
8
+ jest . mock ( '@sentry/node ' ) ;
9
9
10
- const raven = require ( 'raven ' ) ;
10
+ const sentryNode = require ( '@sentry/node ' ) ;
11
11
const Sentry = require ( '../../lib/sentry.js' ) ;
12
12
13
13
/* eslint-env jest */
@@ -27,9 +27,14 @@ describe('Sentry', () => {
27
27
// We want to have a fresh state for every test.
28
28
originalSentry = { ...Sentry } ;
29
29
30
- raven . config = jest . fn ( ) . mockReturnValue ( { install : jest . fn ( ) } ) ;
31
- raven . mergeContext = jest . fn ( ) ;
32
- raven . captureException = jest . fn ( ) . mockImplementation ( ( err , opts , cb ) => cb ( ) ) ;
30
+ sentryNode . init = jest . fn ( ) . mockReturnValue ( { install : jest . fn ( ) } ) ;
31
+ sentryNode . setExtras = jest . fn ( ) ;
32
+ sentryNode . captureException = jest . fn ( ) ;
33
+ sentryNode . withScope = ( fn ) => fn ( {
34
+ setLevel : ( ) => { } ,
35
+ setTags : ( ) => { } ,
36
+ setExtras : ( ) => { } ,
37
+ } ) ;
33
38
Sentry . _shouldSample = jest . fn ( ) . mockReturnValue ( true ) ;
34
39
} ) ;
35
40
@@ -41,18 +46,18 @@ describe('Sentry', () => {
41
46
describe ( '.init' , ( ) => {
42
47
it ( 'should noop when !enableErrorReporting' , ( ) => {
43
48
Sentry . init ( { url : 'http://example.com' , flags : { } } ) ;
44
- expect ( raven . config ) . not . toHaveBeenCalled ( ) ;
49
+ expect ( sentryNode . init ) . not . toHaveBeenCalled ( ) ;
45
50
Sentry . init ( { url : 'http://example.com' , flags : { enableErrorReporting : false } } ) ;
46
- expect ( raven . config ) . not . toHaveBeenCalled ( ) ;
51
+ expect ( sentryNode . init ) . not . toHaveBeenCalled ( ) ;
47
52
} ) ;
48
53
49
54
it ( 'should noop when not picked for sampling' , ( ) => {
50
55
Sentry . _shouldSample . mockReturnValue ( false ) ;
51
56
Sentry . init ( { url : 'http://example.com' , flags : { enableErrorReporting : true } } ) ;
52
- expect ( raven . config ) . not . toHaveBeenCalled ( ) ;
57
+ expect ( sentryNode . init ) . not . toHaveBeenCalled ( ) ;
53
58
} ) ;
54
59
55
- it ( 'should initialize the raven client when enableErrorReporting' , ( ) => {
60
+ it ( 'should initialize the Sentry client when enableErrorReporting' , ( ) => {
56
61
Sentry . init ( {
57
62
url : 'http://example.com' ,
58
63
flags : {
@@ -63,26 +68,25 @@ describe('Sentry', () => {
63
68
environmentData : { } ,
64
69
} ) ;
65
70
66
- expect ( raven . config ) . toHaveBeenCalled ( ) ;
67
- expect ( raven . mergeContext ) . toHaveBeenCalled ( ) ;
68
- expect ( raven . mergeContext . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
69
- extra : {
70
- url : 'http://example.com' ,
71
- formFactor : 'desktop' ,
72
- throttlingMethod : 'devtools' ,
73
- } ,
71
+ expect ( sentryNode . init ) . toHaveBeenCalled ( ) ;
72
+ expect ( sentryNode . setExtras ) . toHaveBeenCalled ( ) ;
73
+ expect ( sentryNode . setExtras . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
74
+ channel : 'cli' ,
75
+ url : 'http://example.com' ,
76
+ formFactor : 'desktop' ,
77
+ throttlingMethod : 'devtools' ,
74
78
} ) ;
75
79
} ) ;
76
80
} ) ;
77
81
78
82
describe ( '.captureException' , ( ) => {
79
- it ( 'should forward exceptions to raven client' , async ( ) => {
83
+ it ( 'should forward exceptions to Sentry client' , async ( ) => {
80
84
Sentry . init ( configPayload ) ;
81
85
const error = new Error ( 'oops' ) ;
82
86
await Sentry . captureException ( error ) ;
83
87
84
- expect ( raven . captureException ) . toHaveBeenCalled ( ) ;
85
- expect ( raven . captureException . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
88
+ expect ( sentryNode . captureException ) . toHaveBeenCalled ( ) ;
89
+ expect ( sentryNode . captureException . mock . calls [ 0 ] [ 0 ] ) . toBe ( error ) ;
86
90
} ) ;
87
91
88
92
it ( 'should skip expected errors' , async ( ) => {
@@ -91,7 +95,7 @@ describe('Sentry', () => {
91
95
error . expected = true ;
92
96
await Sentry . captureException ( error ) ;
93
97
94
- expect ( raven . captureException ) . not . toHaveBeenCalled ( ) ;
98
+ expect ( sentryNode . captureException ) . not . toHaveBeenCalled ( ) ;
95
99
} ) ;
96
100
97
101
it ( 'should skip duplicate audit errors' , async ( ) => {
@@ -100,7 +104,7 @@ describe('Sentry', () => {
100
104
await Sentry . captureException ( error , { tags : { audit : 'my-audit' } } ) ;
101
105
await Sentry . captureException ( error , { tags : { audit : 'my-audit' } } ) ;
102
106
103
- expect ( raven . captureException ) . toHaveBeenCalledTimes ( 1 ) ;
107
+ expect ( sentryNode . captureException ) . toHaveBeenCalledTimes ( 1 ) ;
104
108
} ) ;
105
109
106
110
it ( 'should still allow different audit errors' , async ( ) => {
@@ -110,7 +114,7 @@ describe('Sentry', () => {
110
114
await Sentry . captureException ( errorA , { tags : { audit : 'my-audit' } } ) ;
111
115
await Sentry . captureException ( errorB , { tags : { audit : 'my-audit' } } ) ;
112
116
113
- expect ( raven . captureException ) . toHaveBeenCalledTimes ( 2 ) ;
117
+ expect ( sentryNode . captureException ) . toHaveBeenCalledTimes ( 2 ) ;
114
118
} ) ;
115
119
116
120
it ( 'should skip duplicate gatherer errors' , async ( ) => {
@@ -119,7 +123,7 @@ describe('Sentry', () => {
119
123
await Sentry . captureException ( error , { tags : { gatherer : 'my-gatherer' } } ) ;
120
124
await Sentry . captureException ( error , { tags : { gatherer : 'my-gatherer' } } ) ;
121
125
122
- expect ( raven . captureException ) . toHaveBeenCalledTimes ( 1 ) ;
126
+ expect ( sentryNode . captureException ) . toHaveBeenCalledTimes ( 1 ) ;
123
127
} ) ;
124
128
} ) ;
125
129
} ) ;
0 commit comments