diff options
author | 2023-04-06 14:01:49 -0700 | |
---|---|---|
committer | 2023-04-06 14:01:49 -0700 | |
commit | 1d138057cb861fe540cfe5ef49905225cee40ae8 (patch) | |
tree | 9289a28c1e29a67f68b5d30142026dc56aa9953d /test | |
parent | f788519263b5713cd5655a6e3bcf3e3f9b1aea02 (diff) | |
download | bun-1d138057cb861fe540cfe5ef49905225cee40ae8.tar.gz bun-1d138057cb861fe540cfe5ef49905225cee40ae8.tar.zst bun-1d138057cb861fe540cfe5ef49905225cee40ae8.zip |
Add last modify field "mtime" for FileBlob (#1431) (#2491)
* Add lastModified field for FileBlob (#1431)
lastModified value is epoch timestamp in millisecond unit.
* update according to review comment.
Diffstat (limited to 'test')
-rw-r--r-- | test/js/bun/io/bun-write.test.js | 18 | ||||
-rw-r--r-- | test/js/web/fetch/fetch.test.ts | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js index c3b9b187b..ab8063f16 100644 --- a/test/js/bun/io/bun-write.test.js +++ b/test/js/bun/io/bun-write.test.js @@ -2,6 +2,7 @@ import fs from "fs"; import { it, expect, describe } from "bun:test"; import path from "path"; import { gcTick, withoutAggressiveGC } from "harness"; +import { tmpdir } from "os"; it("Bun.write blob", async () => { await Bun.write(Bun.file("/tmp/response-file.test.txt"), Bun.file(path.join(import.meta.dir, "fetch.js.txt"))); @@ -147,6 +148,23 @@ it("Bun.file empty file", async () => { await gcTick(); }); +it("Bun.file lastModified update", async () => { + const file = Bun.file(tmpdir() + "/bun.test.lastModified.txt"); + await gcTick(); + // setup + await Bun.write(file, "test text."); + const lastModified0 = file.lastModified; + + // sleep some time and write the file again. + await Bun.sleep(10); + await Bun.write(file, "test text2."); + const lastModified1 = file.lastModified; + + // ensure the last modified timestamp is updated. + expect(lastModified1).toBeGreaterThan(lastModified0); + await gcTick(); +}); + it("Bun.file as a Blob", async () => { const filePath = path.join(import.meta.path, "../fetch.js.txt"); const fixture = fs.readFileSync(filePath, "utf8"); diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 183c5dc77..cc59ba3f6 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -540,6 +540,7 @@ describe("Bun.file", () => { writeFileSync(path, buffer); const file = Bun.file(path); expect(blob.size).toBe(file.size); + expect(file.lastModified).toBeGreaterThan(0); return file; }); |