aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js/node/fs.js4
-rw-r--r--test/js/node/fs/fs.test.ts38
2 files changed, 40 insertions, 2 deletions
diff --git a/src/js/node/fs.js b/src/js/node/fs.js
index 2bd752d19..8d9f0d235 100644
--- a/src/js/node/fs.js
+++ b/src/js/node/fs.js
@@ -642,8 +642,8 @@ WriteStream = (function (InternalWriteStream) {
});
return Object.defineProperty(
- function WriteStream(options) {
- return new InternalWriteStream(options);
+ function WriteStream(path, options) {
+ return new InternalWriteStream(path, options);
},
Symbol.hasInstance,
{
diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts
index 37c3253a4..0353968fe 100644
--- a/test/js/node/fs/fs.test.ts
+++ b/test/js/node/fs/fs.test.ts
@@ -1068,6 +1068,44 @@ describe("createWriteStream", () => {
expect(exception.code).toBe("ERR_INVALID_ARG_TYPE");
}
});
+
+ it("writing in append mode should not truncate the file", async () => {
+ const path = `${tmpdir()}/fs.test.js/${Date.now()}.createWriteStreamAppend.txt`;
+ const stream = createWriteStream(path, {
+ // @ts-ignore-next-line
+ flags: "a",
+ });
+ stream.write("first line\n");
+ stream.end();
+
+ await new Promise((resolve, reject) => {
+ stream.on("error", e => {
+ reject(e);
+ });
+
+ stream.on("finish", () => {
+ resolve(true);
+ });
+ });
+
+ const stream2 = createWriteStream(path, {
+ // @ts-ignore-next-line
+ flags: "a",
+ });
+ stream2.write("second line\n");
+ stream2.end();
+
+ return await new Promise((resolve, reject) => {
+ stream2.on("error", e => {
+ reject(e);
+ });
+
+ stream2.on("finish", () => {
+ expect(readFileSync(path, "utf8")).toBe("first line\nsecond line\n");
+ resolve(true);
+ });
+ });
+ });
});
describe("fs/promises", () => {