Stat largefile test (#3870)

* Add test for stat on a large file

* Update fs.test.ts

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Jarred Sumner
2023-07-28 18:55:04 -07:00
committed by GitHub
parent 4f914cbfe8
commit 05716ff39b

View File

@@ -1,4 +1,5 @@
import { describe, expect, it } from "bun:test";
import { dirname } from "node:path";
import { gc } from "harness";
import fs, {
closeSync,
@@ -31,6 +32,7 @@ import fs, {
symlinkSync,
writevSync,
readvSync,
fstatSync,
} from "node:fs";
import _promises from "node:fs/promises";
@@ -1432,6 +1434,26 @@ describe("fs/promises", () => {
});
});
it("stat on a large file", () => {
var dest: string = "",
fd;
try {
dest = `${tmpdir()}/fs.test.js/${Math.trunc(Math.random() * 10000000000).toString(32)}.stat.txt`;
mkdirSync(dirname(dest), { recursive: true });
const bigBuffer = new Uint8Array(1024 * 1024 * 1024);
fd = openSync(dest, "w");
let offset = 0;
while (offset < 5 * 1024 * 1024 * 1024) {
offset += writeSync(fd, bigBuffer, 0, bigBuffer.length, offset);
}
expect(fstatSync(fd).size).toEqual(offset);
} finally {
if (fd) closeSync(fd);
unlinkSync(dest);
}
});
it("fs.constants", () => {
expect(constants).toBeDefined();
expect(constants.F_OK).toBeDefined();