@@ -8,20 +8,43 @@ describe('instrumentDurableObjectWithSentry', () => {
8
8
afterEach ( ( ) => {
9
9
vi . restoreAllMocks ( ) ;
10
10
} ) ;
11
+
11
12
it ( 'Generic functionality' , ( ) => {
12
13
const options = vi . fn ( ) ;
13
14
const instrumented = instrumentDurableObjectWithSentry ( options , vi . fn ( ) ) ;
14
15
expect ( instrumented ) . toBeTypeOf ( 'function' ) ;
15
16
expect ( ( ) => Reflect . construct ( instrumented , [ ] ) ) . not . toThrow ( ) ;
16
17
expect ( options ) . toHaveBeenCalledOnce ( ) ;
17
18
} ) ;
18
- it ( 'Instruments prototype methods and defines implementation in the object' , ( ) => {
19
+
20
+ it ( 'Instruments sync prototype methods and defines implementation in the object' , ( ) => {
19
21
const testClass = class {
20
- method ( ) { }
22
+ method ( ) {
23
+ return 'sync-result' ;
24
+ }
21
25
} ;
22
26
const obj = Reflect . construct ( instrumentDurableObjectWithSentry ( vi . fn ( ) , testClass as any ) , [ ] ) as any ;
23
27
expect ( obj . method ) . toBe ( obj . method ) ;
28
+
29
+ const result = obj . method ( ) ;
30
+ expect ( result ) . not . toBeInstanceOf ( Promise ) ;
31
+ expect ( result ) . toEqual ( 'sync-result' ) ;
24
32
} ) ;
33
+
34
+ it ( 'Instruments async prototype methods and returns a promise' , async ( ) => {
35
+ const testClass = class {
36
+ async asyncMethod ( ) {
37
+ return 'async-result' ;
38
+ }
39
+ } ;
40
+ const obj = Reflect . construct ( instrumentDurableObjectWithSentry ( vi . fn ( ) , testClass as any ) , [ ] ) as any ;
41
+ expect ( obj . asyncMethod ) . toBe ( obj . asyncMethod ) ;
42
+
43
+ const result = obj . asyncMethod ( ) ;
44
+ expect ( result ) . toBeInstanceOf ( Promise ) ;
45
+ expect ( await result ) . toBe ( 'async-result' ) ;
46
+ } ) ;
47
+
25
48
it ( 'Instruments prototype methods without "sticking" to the options' , ( ) => {
26
49
const initCore = vi . spyOn ( SentryCore , 'initAndBind' ) ;
27
50
vi . spyOn ( SentryCore , 'getClient' ) . mockReturnValue ( undefined ) ;
@@ -41,6 +64,7 @@ describe('instrumentDurableObjectWithSentry', () => {
41
64
expect ( initCore ) . nthCalledWith ( 1 , expect . any ( Function ) , expect . objectContaining ( { orgId : 1 } ) ) ;
42
65
expect ( initCore ) . nthCalledWith ( 2 , expect . any ( Function ) , expect . objectContaining ( { orgId : 2 } ) ) ;
43
66
} ) ;
67
+
44
68
it ( 'All available durable object methods are instrumented' , ( ) => {
45
69
const testClass = class {
46
70
propertyFunction = vi . fn ( ) ;
@@ -72,6 +96,7 @@ describe('instrumentDurableObjectWithSentry', () => {
72
96
expect ( isInstrumented ( ( obj as any ) [ method_name ] ) , `Method ${ method_name } is instrumented` ) . toBeTruthy ( ) ;
73
97
}
74
98
} ) ;
99
+
75
100
it ( 'flush performs after all waitUntil promises are finished' , async ( ) => {
76
101
vi . useFakeTimers ( ) ;
77
102
onTestFinished ( ( ) => {
0 commit comments