mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Add more tests for Node FS
This commit is contained in:
@@ -5,6 +5,11 @@ import {
|
||||
readFileSync,
|
||||
writeFileSync,
|
||||
readFile,
|
||||
read,
|
||||
openSync,
|
||||
readSync,
|
||||
closeSync,
|
||||
writeSync,
|
||||
} from "node:fs";
|
||||
|
||||
const Buffer = globalThis.Buffer || Uint8Array;
|
||||
@@ -24,6 +29,57 @@ describe("mkdirSync", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("readSync", () => {
|
||||
const firstFourBytes = new Uint32Array(
|
||||
new TextEncoder().encode("File").buffer
|
||||
)[0];
|
||||
it("works with a position set to 0", () => {
|
||||
const fd = openSync(import.meta.dir + "/readFileSync.txt", "r");
|
||||
const four = new Uint8Array(4);
|
||||
|
||||
{
|
||||
const count = readSync(fd, four, 0, 4, 0);
|
||||
const u32 = new Uint32Array(four.buffer)[0];
|
||||
expect(u32).toBe(firstFourBytes);
|
||||
expect(count).toBe(4);
|
||||
}
|
||||
closeSync(fd);
|
||||
});
|
||||
it("works without position set", () => {
|
||||
const fd = openSync(import.meta.dir + "/readFileSync.txt", "r");
|
||||
const four = new Uint8Array(4);
|
||||
{
|
||||
const count = readSync(fd, four);
|
||||
const u32 = new Uint32Array(four.buffer)[0];
|
||||
expect(u32).toBe(firstFourBytes);
|
||||
expect(count).toBe(4);
|
||||
}
|
||||
closeSync(fd);
|
||||
});
|
||||
});
|
||||
|
||||
describe("writeSync", () => {
|
||||
it("works with a position set to 0", () => {
|
||||
const fd = openSync(import.meta.dir + "/writeFileSync.txt", "w+");
|
||||
const four = new Uint8Array(4);
|
||||
|
||||
{
|
||||
const count = writeSync(fd, new TextEncoder().encode("File"), 0, 4, 0);
|
||||
expect(count).toBe(4);
|
||||
}
|
||||
closeSync(fd);
|
||||
});
|
||||
it("works without position set", () => {
|
||||
const fd = openSync(import.meta.dir + "/writeFileSync.txt", "w+");
|
||||
const four = new Uint8Array(4);
|
||||
{
|
||||
const count = writeSync(fd, new TextEncoder().encode("File"));
|
||||
expect(count).toBe(4);
|
||||
}
|
||||
closeSync(fd);
|
||||
});
|
||||
});
|
||||
|
||||
describe("readFileSync", () => {
|
||||
it("works", () => {
|
||||
const text = readFileSync(import.meta.dir + "/readFileSync.txt", "utf8");
|
||||
|
||||
1
integration/bunjs-only-snippets/writeFileSync.txt
Normal file
1
integration/bunjs-only-snippets/writeFileSync.txt
Normal file
@@ -0,0 +1 @@
|
||||
File
|
||||
@@ -51,9 +51,10 @@ pub const AllocatorConfiguration = struct {
|
||||
long_running: bool = false,
|
||||
};
|
||||
|
||||
pub const Mimalloc = @import("./allocators/mimalloc.zig");
|
||||
|
||||
pub inline fn mimalloc_cleanup(force: bool) void {
|
||||
if (comptime use_mimalloc) {
|
||||
const Mimalloc = @import("./allocators/mimalloc.zig");
|
||||
Mimalloc.mi_collect(force);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ typedef struct {
|
||||
uint32_t len;
|
||||
uint32_t byte_len;
|
||||
uint8_t cell_type;
|
||||
uint64_t _value;
|
||||
} Bun__ArrayBuffer;
|
||||
|
||||
#ifndef STRING_POINTER
|
||||
|
||||
Reference in New Issue
Block a user