summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-write-optional-params.js
diff options
context:
space:
mode:
authorLivia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com>2022-07-24 22:29:06 +0900
committerGitHub <noreply@github.com>2022-07-24 14:29:06 +0100
commit050d974a2552a7974f53559133d468722d9d96ac (patch)
tree8289adf3482acd43af69b15c71fb30d8f6a5dfcd /test/parallel/test-fs-write-optional-params.js
parenteb4dca030de8349e65297a75817d8f449ee27a05 (diff)
downloadnode-new-050d974a2552a7974f53559133d468722d9d96ac.tar.gz
test: use `common.mustNotMutateObjectDeep()` in fs tests
PR-URL: https://github.com/nodejs/node/pull/43819 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-write-optional-params.js')
-rw-r--r--test/parallel/test-fs-write-optional-params.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/test/parallel/test-fs-write-optional-params.js b/test/parallel/test-fs-write-optional-params.js
index 2173211415..9a1e1cce73 100644
--- a/test/parallel/test-fs-write-optional-params.js
+++ b/test/parallel/test-fs-write-optional-params.js
@@ -18,13 +18,16 @@ const buffer = Buffer.from('zyx');
function testInvalidCb(fd, expectedCode, buffer, options, callback) {
assert.throws(
- () => fs.write(fd, buffer, options, common.mustNotCall()),
+ () => fs.write(fd, buffer, common.mustNotMutateObjectDeep(options), common.mustNotCall()),
{ code: expectedCode }
);
callback(0);
}
function testValidCb(buffer, options, index, callback) {
+ options = common.mustNotMutateObjectDeep(options);
+ const length = options?.length;
+ const offset = options?.offset;
const dest = path.resolve(tmpdir.path, `rwopt_valid_${index}`);
fs.open(dest, 'w+', common.mustSucceed((fd) => {
fs.write(fd, buffer, options, common.mustSucceed((bytesWritten, bufferWritten) => {
@@ -34,10 +37,10 @@ function testValidCb(buffer, options, index, callback) {
const readBufCopy = Uint8Array.prototype.slice.call(bufferRead);
assert.ok(bytesWritten >= bytesRead);
- if (options.length !== undefined && options.length !== null) {
- assert.strictEqual(bytesWritten, options.length);
+ if (length !== undefined && length !== null) {
+ assert.strictEqual(bytesWritten, length);
}
- if (options.offset === undefined || options.offset === 0) {
+ if (offset === undefined || offset === 0) {
assert.deepStrictEqual(writeBufCopy, readBufCopy);
}
assert.deepStrictEqual(bufferWritten, bufferRead);
@@ -56,6 +59,8 @@ async function runTests(fd) {
for (const badBuffer of [
undefined, null, true, 42, 42n, Symbol('42'), NaN, [], () => {},
Promise.resolve(new Uint8Array(1)),
+ common.mustNotCall(),
+ common.mustNotMutateObjectDeep({}),
{},
{ buffer: 'amNotParam' },
{ string: 'amNotParam' },
@@ -81,9 +86,13 @@ async function runTests(fd) {
await testInvalid(fd, 'ERR_OUT_OF_RANGE', buffer, { offset: -1 });
await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, { offset: false });
await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, { offset: true });
+ await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, true);
+ await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, '42');
+ await testInvalid(fd, 'ERR_INVALID_ARG_TYPE', buffer, Symbol('42'));
// Test compatibility with fs.read counterpart
for (const [ index, options ] of [
+ null,
{},
{ length: 1 },
{ position: 5 },