Skip to content

Commit 01c5691

Browse files
author
Joe Previte
committed
fixup!: add stat test for timestamp check
1 parent d41f198 commit 01c5691

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

test/unit/node/heart.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { logger } from "@coder/logger"
2-
import { readFile, writeFile } from "fs/promises"
2+
import { readFile, writeFile, stat } from "fs/promises"
33
import { Heart, heartbeatTimer } from "../../../src/node/heart"
44
import { clean, mockLogger, tmpdir } from "../../utils/helpers"
55

@@ -29,6 +29,7 @@ describe("Heart", () => {
2929
})
3030
it("should write to a file when given a valid file path", async () => {
3131
// Set up heartbeat file with contents
32+
const before = Date.now()
3233
const text = "test"
3334
const pathToFile = `${testDir}/file.txt`
3435
await writeFile(pathToFile, text)
@@ -40,6 +41,9 @@ describe("Heart", () => {
4041
// Check that the heart wrote to the heartbeatFilePath and overwrote our text
4142
const fileContentsAfterBeat = await readFile(pathToFile, { encoding: "utf8" })
4243
expect(fileContentsAfterBeat).not.toBe(text)
44+
// Make sure the modified timestamp was updated.
45+
const status = await stat(pathToFile)
46+
expect(status.mtimeMs).toBeGreaterThan(before)
4347
})
4448
it("should log a warning when given an invalid file path", async () => {
4549
heart = new Heart(`fakeDir/fake.txt`, mockIsActive(false))

0 commit comments

Comments
 (0)