Skip to content

Commit 2b26a57

Browse files
author
Joe Previte
committed
wip
1 parent 1eb4641 commit 2b26a57

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

test/unit/node/heart.test.ts

+35-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ describe("Heart", () => {
4444
// Check that the heart wrote to the heartbeatFilePath and overwrote our text
4545
const fileContentsAfterBeat = await readFile(pathToFile, { encoding: "utf8" })
4646
expect(fileContentsAfterBeat).not.toBe(text)
47-
} catch (_e) {}
47+
} catch (_e) {
48+
// nothing here
49+
}
4850
heart.dispose()
4951
})
5052

@@ -58,21 +60,45 @@ describe("Heart", () => {
5860
await new Promise((r) => setTimeout(r, 100))
5961
expect(logger.trace).toHaveBeenCalled()
6062
expect(logger.warn).toHaveBeenCalled()
61-
} catch (_e) {}
63+
} catch (_e) {
64+
// nothing here
65+
}
6266
heart.dispose()
6367
})
6468

6569
// TODO@jsjoeio make isActive reject, check for warning
6670
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+
*/
6791
jest.spyOn(global.Date, "now").mockImplementationOnce(() => 60002)
6892
const rejectMessage = "oh no"
6993
const heart = new Heart(`${testDir}/path.txt`, isFakeActive(false, rejectMessage))
7094
try {
7195
heart.beat()
96+
} catch (_e) {
97+
// nothing here
98+
}
7299
// HACK@jsjoeio - beat has some async logic but is not an async method
73100
// Therefore, we have to create an artificial wait in order to make sure
74101
// all async code has completed before asserting
75-
} catch (_e) {}
76102
await new Promise((r) => setTimeout(r, 200))
77103
expect(logger.warn).toBeCalled()
78104
heart.dispose()
@@ -82,7 +108,9 @@ describe("Heart", () => {
82108
const heart = new Heart(`${testDir}/shutdown.txt`, isFakeActive(true))
83109
try {
84110
heart.beat()
85-
} catch (_e) {}
111+
} catch (_e) {
112+
// nothing here
113+
}
86114

87115
const isAlive = heart.alive()
88116
expect(isAlive).toBe(true)
@@ -96,6 +124,8 @@ describe("Heart", () => {
96124

97125
const isAlive = heart.alive()
98126
expect(isAlive).toBe(false)
99-
} catch (_e) {}
127+
} catch (_e) {
128+
// nothing here
129+
}
100130
})
101131
})

0 commit comments

Comments
 (0)