@@ -44,7 +44,9 @@ describe("Heart", () => {
44
44
// Check that the heart wrote to the heartbeatFilePath and overwrote our text
45
45
const fileContentsAfterBeat = await readFile ( pathToFile , { encoding : "utf8" } )
46
46
expect ( fileContentsAfterBeat ) . not . toBe ( text )
47
- } catch ( _e ) { }
47
+ } catch ( _e ) {
48
+ // nothing here
49
+ }
48
50
heart . dispose ( )
49
51
} )
50
52
@@ -58,21 +60,45 @@ describe("Heart", () => {
58
60
await new Promise ( ( r ) => setTimeout ( r , 100 ) )
59
61
expect ( logger . trace ) . toHaveBeenCalled ( )
60
62
expect ( logger . warn ) . toHaveBeenCalled ( )
61
- } catch ( _e ) { }
63
+ } catch ( _e ) {
64
+ // nothing here
65
+ }
62
66
heart . dispose ( )
63
67
} )
64
68
65
69
// TODO@jsjoeio make isActive reject, check for warning
66
70
it . only ( "should log a warning when isActive rejects" , async ( ) => {
71
+ /*
72
+ NOTES
73
+ argh running into problems here.
74
+
75
+ it's supposed to call logger warn if you
76
+ - call beat()
77
+ - and this.alive() is false
78
+ - then it goes through the logic
79
+ - then it calls trace
80
+ - then writes to file
81
+ - then heartbeatTimer
82
+ - then isActive, which rejects
83
+
84
+ I don't think I need to mock or spy on date.now actually
85
+ just copy other test and then make isActive() reject...
86
+ maybe write a custom function and then try that and make sure
87
+ warn is called
88
+
89
+
90
+ */
67
91
jest . spyOn ( global . Date , "now" ) . mockImplementationOnce ( ( ) => 60002 )
68
92
const rejectMessage = "oh no"
69
93
const heart = new Heart ( `${ testDir } /path.txt` , isFakeActive ( false , rejectMessage ) )
70
94
try {
71
95
heart . beat ( )
96
+ } catch ( _e ) {
97
+ // nothing here
98
+ }
72
99
// HACK@jsjoeio - beat has some async logic but is not an async method
73
100
// Therefore, we have to create an artificial wait in order to make sure
74
101
// all async code has completed before asserting
75
- } catch ( _e ) { }
76
102
await new Promise ( ( r ) => setTimeout ( r , 200 ) )
77
103
expect ( logger . warn ) . toBeCalled ( )
78
104
heart . dispose ( )
@@ -82,7 +108,9 @@ describe("Heart", () => {
82
108
const heart = new Heart ( `${ testDir } /shutdown.txt` , isFakeActive ( true ) )
83
109
try {
84
110
heart . beat ( )
85
- } catch ( _e ) { }
111
+ } catch ( _e ) {
112
+ // nothing here
113
+ }
86
114
87
115
const isAlive = heart . alive ( )
88
116
expect ( isAlive ) . toBe ( true )
@@ -96,6 +124,8 @@ describe("Heart", () => {
96
124
97
125
const isAlive = heart . alive ( )
98
126
expect ( isAlive ) . toBe ( false )
99
- } catch ( _e ) { }
127
+ } catch ( _e ) {
128
+ // nothing here
129
+ }
100
130
} )
101
131
} )
0 commit comments