File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export class Heart {
33
33
if ( typeof this . heartbeatTimer !== "undefined" ) {
34
34
clearTimeout ( this . heartbeatTimer )
35
35
}
36
- this . heartbeatTimer = setTimeout ( ( ) => heartbeatTimer ( this . isActive , this . beat ) , this . heartbeatInterval )
36
+ this . heartbeatTimer = setTimeout ( async ( ) => await heartbeatTimer ( this . isActive , this . beat ) , this . heartbeatInterval )
37
37
}
38
38
39
39
/**
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ describe("Heart", () => {
23
23
} )
24
24
afterEach ( ( ) => {
25
25
jest . resetAllMocks ( )
26
+ jest . useRealTimers ( )
26
27
if ( heart ) {
27
28
heart . dispose ( )
28
29
}
@@ -75,6 +76,17 @@ describe("Heart", () => {
75
76
const isAlive = heart . alive ( )
76
77
expect ( isAlive ) . toBe ( false )
77
78
} )
79
+ it ( "should beat twice and maintain reference to Heart" , async ( ) => {
80
+ // Use fake timers so we can speed up setTimeout
81
+ jest . useFakeTimers ( )
82
+ heart = new Heart ( `${ testDir } /hello.txt` , mockIsActive ( true ) )
83
+ heart . beat ( )
84
+ // we need to speed up clocks, timeouts
85
+ // call heartbeat again (and it won't be alive I think)
86
+ // then assert no warnings were called
87
+ jest . runAllTimers ( )
88
+ expect ( logger . warn ) . not . toHaveBeenCalled ( )
89
+ } )
78
90
} )
79
91
80
92
describe ( "heartbeatTimer" , ( ) => {
You can’t perform that action at this time.
0 commit comments