1
1
import { logger } from "@coder/logger"
2
- import { readFile , writeFile } from "fs/promises"
2
+ import { readFile , writeFile , stat } from "fs/promises"
3
3
import { Heart , heartbeatTimer } from "../../../src/node/heart"
4
4
import { clean , mockLogger , tmpdir } from "../../utils/helpers"
5
5
@@ -29,6 +29,7 @@ describe("Heart", () => {
29
29
} )
30
30
it ( "should write to a file when given a valid file path" , async ( ) => {
31
31
// Set up heartbeat file with contents
32
+ const before = Date . now ( )
32
33
const text = "test"
33
34
const pathToFile = `${ testDir } /file.txt`
34
35
await writeFile ( pathToFile , text )
@@ -40,6 +41,9 @@ describe("Heart", () => {
40
41
// Check that the heart wrote to the heartbeatFilePath and overwrote our text
41
42
const fileContentsAfterBeat = await readFile ( pathToFile , { encoding : "utf8" } )
42
43
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 )
43
47
} )
44
48
it ( "should log a warning when given an invalid file path" , async ( ) => {
45
49
heart = new Heart ( `fakeDir/fake.txt` , mockIsActive ( false ) )
0 commit comments