@@ -28,39 +28,42 @@ it('complains if the value is a primitive', () => {
2828 expect ( ( ) => new LeakDetector ( NaN ) ) . toThrowErrorMatchingSnapshot ( ) ;
2929} ) ;
3030
31- it ( 'does not show the GC if hidden' , ( ) => {
31+ it ( 'does not show the GC if hidden' , async ( ) => {
3232 const detector = new LeakDetector ( { } ) ;
3333
3434 // @ts -ignore: purposefully removed
3535 global . gc = undefined ;
36- detector . isLeaking ( ) ;
36+ await detector . isLeaking ( ) ;
3737 expect ( global . gc ) . not . toBeDefined ( ) ;
3838} ) ;
3939
40- it ( 'does not hide the GC if visible' , ( ) => {
40+ it ( 'does not hide the GC if visible' , async ( ) => {
4141 const detector = new LeakDetector ( { } ) ;
4242
4343 global . gc = ( ) => { } ;
44- detector . isLeaking ( ) ;
44+ await detector . isLeaking ( ) ;
4545 expect ( global . gc ) . toBeDefined ( ) ;
4646} ) ;
4747
48- it ( 'correctly checks simple leaks' , ( ) => {
48+ it ( 'correctly checks simple leaks' , async ( ) => {
4949 let reference : unknown = { } ;
50+ let isLeaking : boolean ;
5051
5152 const detector = new LeakDetector ( reference ) ;
5253
5354 // Reference is still held in memory.
54- expect ( detector . isLeaking ( ) ) . toBe ( true ) ;
55+ isLeaking = await detector . isLeaking ( ) ;
56+ expect ( isLeaking ) . toBe ( true ) ;
5557
5658 // We destroy the only reference to the object we had.
5759 reference = null ;
5860
5961 // Reference should be gone.
60- expect ( detector . isLeaking ( ) ) . toBe ( false ) ;
62+ isLeaking = await detector . isLeaking ( ) ;
63+ expect ( isLeaking ) . toBe ( false ) ;
6164} ) ;
6265
63- it ( 'tests different objects' , ( ) => {
66+ it ( 'tests different objects' , async ( ) => {
6467 const refs = [
6568 function ( ) { } ,
6669 ( ) => { } ,
@@ -73,12 +76,20 @@ it('tests different objects', () => {
7376
7477 const detectors = refs . map ( ref => new LeakDetector ( ref ) ) ;
7578
76- detectors . forEach ( detector => expect ( detector . isLeaking ( ) ) . toBe ( true ) ) ;
77- refs . forEach ( ( _ , i ) => ( refs [ i ] = null ) ) ;
78- detectors . forEach ( detector => expect ( detector . isLeaking ( ) ) . toBe ( false ) ) ;
79+ let isLeaking : boolean ;
80+ for ( const i in detectors ) {
81+ isLeaking = await detectors [ i ] . isLeaking ( ) ;
82+ expect ( isLeaking ) . toBe ( true ) ;
83+ refs [ i ] = null ;
84+ }
85+
86+ for ( const i in detectors ) {
87+ isLeaking = await detectors [ i ] . isLeaking ( ) ;
88+ expect ( isLeaking ) . toBe ( false ) ;
89+ }
7990} ) ;
8091
81- it ( 'correctly checks more complex leaks' , ( ) => {
92+ it ( 'correctly checks more complex leaks' , async ( ) => {
8293 let ref1 : any = { } ;
8394 let ref2 : any = { } ;
8495
@@ -89,21 +100,30 @@ it('correctly checks more complex leaks', () => {
89100 const detector1 = new LeakDetector ( ref1 ) ;
90101 const detector2 = new LeakDetector ( ref2 ) ;
91102
103+ let isLeaking1 : boolean ;
104+ let isLeaking2 : boolean ;
105+
92106 // References are still held in memory.
93- expect ( detector1 . isLeaking ( ) ) . toBe ( true ) ;
94- expect ( detector2 . isLeaking ( ) ) . toBe ( true ) ;
107+ isLeaking1 = await detector1 . isLeaking ( ) ;
108+ expect ( isLeaking1 ) . toBe ( true ) ;
109+ isLeaking2 = await detector2 . isLeaking ( ) ;
110+ expect ( isLeaking2 ) . toBe ( true ) ;
95111
96112 // We destroy the reference to ref1.
97113 ref1 = null ;
98114
99115 // It will still be referenced by ref2, so both references are still leaking.
100- expect ( detector1 . isLeaking ( ) ) . toBe ( true ) ;
101- expect ( detector2 . isLeaking ( ) ) . toBe ( true ) ;
116+ isLeaking1 = await detector1 . isLeaking ( ) ;
117+ expect ( isLeaking1 ) . toBe ( true ) ;
118+ isLeaking2 = await detector2 . isLeaking ( ) ;
119+ expect ( isLeaking2 ) . toBe ( true ) ;
102120
103121 // We destroy the reference to ref2.
104122 ref2 = null ;
105123
106124 // Now both references should be gone (yay mark & sweep!).
107- expect ( detector1 . isLeaking ( ) ) . toBe ( false ) ;
108- expect ( detector2 . isLeaking ( ) ) . toBe ( false ) ;
125+ isLeaking1 = await detector1 . isLeaking ( ) ;
126+ expect ( isLeaking1 ) . toBe ( false ) ;
127+ isLeaking2 = await detector2 . isLeaking ( ) ;
128+ expect ( isLeaking2 ) . toBe ( false ) ;
109129} ) ;
0 commit comments