Skip to content

Commit

Permalink
fixup! test: improve test-internal-fs-syncwritestream
Browse files Browse the repository at this point in the history
  • Loading branch information
sungpaks committed Sep 7, 2024
1 parent ccae120 commit 671a3ca
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions test/parallel/test-internal-fs-syncwritestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,25 @@ const filename = tmpdir.resolve('sync-write-stream.txt');
assert.strictEqual(stream.fd, null);
}

// Verify that the callback will be called when already destroy()ed.
// Verify behavior of destroy() when already destroy()ed
{
const fd = fs.openSync(filename, 'w');
const stream = new SyncWriteStream(fd);
const theErr = new Error('my error');
const cb = () => {};

stream.on('close', common.mustCall());
assert.strictEqual(stream.destroy(), stream);
stream.destroy(theErr, common.mustCall(cb));
stream.destroySoon(theErr, common.mustCall(cb));
stream._destroy(theErr, common.mustCall(cb));
assert.strictEqual(stream.destroy(), stream);
}

// 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.mustNotCall());
stream._destroy(null, () => {});
assert.strictEqual(stream.closed, false);
assert.strictEqual(stream.destroy(), stream);
fs.fstatSync(fd); // Does not throw
stream.on('close', common.mustCall());
fs.closeSync(fd);
}

// Verify that calling end() will also destroy the stream.
Expand Down

0 comments on commit 671a3ca

Please sign in to comment.