1
1
import { getDefaultTestClientOptions , TestClient } from '../mocks/client' ;
2
2
import { AddAttachmentTestIntegration } from '../mocks/integration' ;
3
3
import { initAndBind } from '../../src/sdk' ;
4
- import { captureEvent } from '@sentry/hub' ;
4
+ import { captureEvent , configureScope } from '@sentry/hub' ;
5
+ import { getGlobalObject } from '@sentry/utils' ;
5
6
6
7
const PUBLIC_DSN = 'https://username@domain/123' ;
7
8
const sendEvent = jest . spyOn ( TestClient . prototype , 'sendEvent' ) ;
@@ -14,73 +15,87 @@ describe('Hint', () => {
14
15
15
16
afterEach ( ( ) => {
16
17
jest . clearAllMocks ( ) ;
18
+ delete getGlobalObject ( ) . __SENTRY__ ;
17
19
} ) ;
18
20
19
- test ( 'can be mutated in beforeSend' , ( ) => {
20
- expect . assertions ( 1 ) ;
21
+ describe ( 'attachments' , ( ) => {
22
+ test ( 'can be mutated in beforeSend' , ( ) => {
23
+ expect . assertions ( 1 ) ;
21
24
22
- const options = getDefaultTestClientOptions ( {
23
- dsn : PUBLIC_DSN ,
24
- beforeSend : ( event , hint ) => {
25
- if ( hint ) {
26
- hint . attachments = [ ...( hint ?. attachments || [ ] ) , { filename : 'another.file' , data : 'more text' } ] ;
27
- }
25
+ const options = getDefaultTestClientOptions ( {
26
+ dsn : PUBLIC_DSN ,
27
+ beforeSend : ( event , hint ) => {
28
+ if ( hint ) {
29
+ hint . attachments = [ ...( hint ?. attachments || [ ] ) , { filename : 'another.file' , data : 'more text' } ] ;
30
+ }
28
31
29
- return event ;
30
- } ,
31
- } ) ;
32
-
33
- const client = new TestClient ( options ) ;
34
- client . captureEvent ( { } ) ;
32
+ return event ;
33
+ } ,
34
+ } ) ;
35
35
36
- const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
36
+ const client = new TestClient ( options ) ;
37
+ client . captureEvent ( { } ) ;
37
38
38
- expect ( hint ) . toEqual ( {
39
- attachments : [ { filename : 'another.file' , data : 'more text' } ] ,
39
+ const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
40
+ expect ( hint ) . toEqual ( { attachments : [ { filename : 'another.file' , data : 'more text' } ] } ) ;
40
41
} ) ;
41
- } ) ;
42
42
43
- test ( 'gets passed through to beforeSend and can be further mutated' , ( ) => {
44
- expect . assertions ( 1 ) ;
45
-
46
- const options = getDefaultTestClientOptions ( {
47
- dsn : PUBLIC_DSN ,
48
- beforeSend : ( event , hint ) => {
49
- if ( hint ) {
50
- hint . attachments = [ ...( hint ?. attachments || [ ] ) , { filename : 'another.file' , data : 'more text' } ] ;
51
- }
52
-
53
- return event ;
54
- } ,
43
+ test ( 'gets passed through to beforeSend and can be further mutated' , ( ) => {
44
+ expect . assertions ( 1 ) ;
45
+
46
+ const options = getDefaultTestClientOptions ( {
47
+ dsn : PUBLIC_DSN ,
48
+ beforeSend : ( event , hint ) => {
49
+ if ( hint ) {
50
+ hint . attachments = [ ...( hint ?. attachments || [ ] ) , { filename : 'another.file' , data : 'more text' } ] ;
51
+ }
52
+
53
+ return event ;
54
+ } ,
55
+ } ) ;
56
+
57
+ const client = new TestClient ( options ) ;
58
+ client . captureEvent ( { } , { attachments : [ { filename : 'some-file.txt' , data : 'Hello' } ] } ) ;
59
+
60
+ const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
61
+ expect ( hint ) . toEqual ( {
62
+ attachments : [
63
+ { filename : 'some-file.txt' , data : 'Hello' } ,
64
+ { filename : 'another.file' , data : 'more text' } ,
65
+ ] ,
66
+ } ) ;
55
67
} ) ;
56
68
57
- const client = new TestClient ( options ) ;
58
- client . captureEvent ( { } , { attachments : [ { filename : 'some-file.txt' , data : 'Hello' } ] } ) ;
59
-
60
- const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
69
+ test ( 'can be mutated by an integration via event processor' , ( ) => {
70
+ expect . assertions ( 1 ) ;
61
71
62
- expect ( hint ) . toEqual ( {
63
- attachments : [
64
- { filename : 'some-file.txt' , data : 'Hello' } ,
65
- { filename : 'another.file' , data : 'more text' } ,
66
- ] ,
67
- } ) ;
68
- } ) ;
72
+ const options = getDefaultTestClientOptions ( {
73
+ dsn : PUBLIC_DSN ,
74
+ integrations : [ new AddAttachmentTestIntegration ( ) ] ,
75
+ } ) ;
69
76
70
- test ( 'can be mutated by an integration via event processor' , ( ) => {
71
- expect . assertions ( 1 ) ;
77
+ initAndBind ( TestClient , options ) ;
78
+ captureEvent ( { } ) ;
72
79
73
- const options = getDefaultTestClientOptions ( {
74
- dsn : PUBLIC_DSN ,
75
- integrations : [ new AddAttachmentTestIntegration ( ) ] ,
80
+ const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
81
+ expect ( hint ?. attachments ) . toEqual ( [ { filename : 'integration.file' , data : 'great content!' } ] ) ;
76
82
} ) ;
77
83
78
- initAndBind ( TestClient , options ) ;
84
+ test ( 'get copied from scope to hint' , ( ) => {
85
+ expect . assertions ( 1 ) ;
79
86
80
- captureEvent ( { } ) ;
87
+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN } ) ;
88
+ initAndBind ( TestClient , options ) ;
81
89
82
- const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
90
+ configureScope ( scope => scope . addAttachment ( { filename : 'scope.file' , data : 'great content!' } ) ) ;
83
91
84
- expect ( hint ?. attachments ) . toEqual ( [ { filename : 'integration.file' , data : 'great content!' } ] ) ;
92
+ captureEvent ( { } , { attachments : [ { filename : 'some-file.txt' , data : 'Hello' } ] } ) ;
93
+
94
+ const [ , hint ] = sendEvent . mock . calls [ 0 ] ;
95
+ expect ( hint ?. attachments ) . toEqual ( [
96
+ { filename : 'some-file.txt' , data : 'Hello' } ,
97
+ { filename : 'scope.file' , data : 'great content!' } ,
98
+ ] ) ;
99
+ } ) ;
85
100
} ) ;
86
101
} ) ;
0 commit comments