aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/fs/fs.test.ts
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-08-29 09:44:45 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-29 09:44:45 -0700
commitde58e9d583ab9f2a5a96401d5f650dd310ca01e3 (patch)
tree0dc74dd42a370116d045c3410c2aa176c281c42b /test/js/node/fs/fs.test.ts
parent07d8623976cd5fe1b11dd13f6988cd02e4fc5c15 (diff)
downloadbun-de58e9d583ab9f2a5a96401d5f650dd310ca01e3.tar.gz
bun-de58e9d583ab9f2a5a96401d5f650dd310ca01e3.tar.zst
bun-de58e9d583ab9f2a5a96401d5f650dd310ca01e3.zip
emit open and call close callback (#4384)
Diffstat (limited to 'test/js/node/fs/fs.test.ts')
-rw-r--r--test/js/node/fs/fs.test.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 5cca5fce9..a3522b486 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -1205,6 +1205,23 @@ describe("createReadStream", () => {
});
});
});
+
+ it("should emit open", done => {
+ const ws = createReadStream(join(import.meta.dir, "readFileSync.txt"));
+ ws.on("open", data => {
+ expect(data).toBeDefined();
+ done();
+ });
+ });
+
+ it("should call close callback", done => {
+ const ws = createReadStream(join(import.meta.dir, "readFileSync.txt"));
+ ws.close(err => {
+ expect(err).toBeDefined();
+ expect(err?.message).toContain("Premature close");
+ done();
+ });
+ });
});
describe("fs.WriteStream", () => {
@@ -1519,6 +1536,44 @@ describe("createWriteStream", () => {
});
});
});
+
+ it("should emit open and call close callback", done => {
+ const ws = createWriteStream(join(tmpdir(), "fs"));
+ ws.on("open", data => {
+ expect(data).toBeDefined();
+ done();
+ });
+ });
+
+ it("should call close callback", done => {
+ const ws = createWriteStream(join(tmpdir(), "fs"));
+ ws.close(err => {
+ expect(err).toBeUndefined();
+ done();
+ });
+ });
+
+ it("should call callbacks in the correct order", done => {
+ const ws = createWriteStream(join(tmpdir(), "fs"));
+ let counter = 0;
+ ws.on("open", () => {
+ expect(counter++).toBe(1);
+ });
+
+ ws.close(() => {
+ expect(counter++).toBe(3);
+ done();
+ });
+
+ const rs = createReadStream(join(import.meta.dir, "readFileSync.txt"));
+ rs.on("open", () => {
+ expect(counter++).toBe(0);
+ });
+
+ rs.close(() => {
+ expect(counter++).toBe(2);
+ });
+ });
});
describe("fs/promises", () => {