From 415905712e59c0d8d7270de27a3b789a121968cd Mon Sep 17 00:00:00 2001 From: Sunghoon <122661764+sungpaks@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:31:13 +0900 Subject: [PATCH] test: improve test-internal-fs-syncwritestream A subtest about the behavior when `autoClose=false`. PR-URL: https://github.com/nodejs/node/pull/54671 Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli Reviewed-By: Luigi Pinca --- test/parallel/test-internal-fs-syncwritestream.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/parallel/test-internal-fs-syncwritestream.js b/test/parallel/test-internal-fs-syncwritestream.js index 93fbfbc9f4c..9f36102e894 100644 --- a/test/parallel/test-internal-fs-syncwritestream.js +++ b/test/parallel/test-internal-fs-syncwritestream.js @@ -66,6 +66,18 @@ const filename = tmpdir.resolve('sync-write-stream.txt'); assert.strictEqual(stream.fd, null); } +// Verify that the file is not closed when autoClose=false +{ + const fd = fs.openSync(filename, 'w'); + const stream = new SyncWriteStream(fd, { autoClose: false }); + + stream.on('close', common.mustCall()); + + assert.strictEqual(stream.destroy(), stream); + fs.fstatSync(fd); // Does not throw + fs.closeSync(fd); +} + // Verify that calling end() will also destroy the stream. { const fd = fs.openSync(filename, 'w');