aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-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", () => {