summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-12-13 14:24:34 -0800
committerJames M Snell <jasnell@gmail.com>2017-12-22 12:49:10 -0800
commit6100e12667429acad1827b6d918e512e55a7a6a7 (patch)
tree4fac815add3abf5d54112723798ecc78cb3e06fa /test
parent92fc14a4595d460394cad8ad5a091dcc450068a5 (diff)
downloadnode-new-6100e12667429acad1827b6d918e512e55a7a6a7.tar.gz
fs: move type checking to js
PR-URL: https://github.com/nodejs/node/pull/17667 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-chmod.js22
-rw-r--r--test/parallel/test-fs-chown-type-check.js52
-rw-r--r--test/parallel/test-fs-close-errors.js23
-rw-r--r--test/parallel/test-fs-copyfile.js38
-rw-r--r--test/parallel/test-fs-fchown.js65
-rw-r--r--test/parallel/test-fs-fsync.js27
-rw-r--r--test/parallel/test-fs-link.js43
-rw-r--r--test/parallel/test-fs-mkdir.js17
-rw-r--r--test/parallel/test-fs-open.js17
-rw-r--r--test/parallel/test-fs-readdir.js17
-rw-r--r--test/parallel/test-fs-readlink-type-check.js21
-rw-r--r--test/parallel/test-fs-rename-type-check.js43
-rw-r--r--test/parallel/test-fs-rmdir-type-check.js21
-rw-r--r--test/parallel/test-fs-stat.js34
-rw-r--r--test/parallel/test-fs-symlink.js57
-rw-r--r--test/parallel/test-fs-truncate.js25
-rw-r--r--test/parallel/test-fs-unlink-type-check.js21
-rw-r--r--test/parallel/test-fs-utimes.js27
-rw-r--r--test/parallel/test-fs-write.js17
19 files changed, 412 insertions, 175 deletions
diff --git a/test/parallel/test-fs-chmod.js b/test/parallel/test-fs-chmod.js
index 9eae75c3c7..92d420a081 100644
--- a/test/parallel/test-fs-chmod.js
+++ b/test/parallel/test-fs-chmod.js
@@ -113,7 +113,7 @@ fs.open(file2, 'w', common.mustCall((err, fd) => {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "mode" argument must be of type number'
+ message: 'The "mode" argument must be of type integer'
}
);
@@ -151,7 +151,7 @@ if (fs.lchmod) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -159,26 +159,24 @@ if (fs.lchmod) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
});
-[-1, 0xFFFFFFFF + 1].forEach((i) => {
+[false, 1, {}, [], null, undefined].forEach((i) => {
common.expectsError(
- () => fs.fchmod(i, 0o000),
+ () => fs.chmod(i, 1, common.mustNotCall()),
{
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
}
);
common.expectsError(
- () => fs.fchmodSync(i, 0o000),
+ () => fs.chmodSync(i, 1),
{
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
}
);
});
diff --git a/test/parallel/test-fs-chown-type-check.js b/test/parallel/test-fs-chown-type-check.js
new file mode 100644
index 0000000000..897c3e1de2
--- /dev/null
+++ b/test/parallel/test-fs-chown-type-check.js
@@ -0,0 +1,52 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+[false, 1, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.chown(i, 1, 1, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.chownSync(i, 1, 1),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
+
+[false, 'test', {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.chown('not_a_file_that_exists', i, 1, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.chown('not_a_file_that_exists', 1, i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.chownSync('not_a_file_that_exists', i, 1),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.chownSync('not_a_file_that_exists', 1, i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-close-errors.js b/test/parallel/test-fs-close-errors.js
index 040f6def44..cadcf2f78c 100644
--- a/test/parallel/test-fs-close-errors.js
+++ b/test/parallel/test-fs-close-errors.js
@@ -9,7 +9,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -17,26 +17,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
- }
- );
-});
-
-[-1, 0xFFFFFFFF + 1].forEach((i) => {
- common.expectsError(
- () => fs.close(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
- }
- );
- common.expectsError(
- () => fs.closeSync(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ message: 'The "fd" argument must be of type integer'
}
);
});
diff --git a/test/parallel/test-fs-copyfile.js b/test/parallel/test-fs-copyfile.js
index 2977a59847..bfda5ccfd7 100644
--- a/test/parallel/test-fs-copyfile.js
+++ b/test/parallel/test-fs-copyfile.js
@@ -70,9 +70,36 @@ common.expectsError(() => {
});
// Throws if the source path is not a string.
-assert.throws(() => {
- fs.copyFileSync(null, dest);
-}, /^TypeError: src must be a string$/);
+[false, 1, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.copyFile(i, dest, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.copyFile(src, i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.copyFileSync(i, dest),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.copyFileSync(src, i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
// Throws if the source path is an invalid path.
common.expectsError(() => {
@@ -84,11 +111,6 @@ common.expectsError(() => {
' Received type string'
});
-// Throws if the destination path is not a string.
-assert.throws(() => {
- fs.copyFileSync(src, null);
-}, /^TypeError: dest must be a string$/);
-
// Throws if the destination path is an invalid path.
common.expectsError(() => {
fs.copyFileSync(src, '\u0000');
diff --git a/test/parallel/test-fs-fchown.js b/test/parallel/test-fs-fchown.js
index 2e75c6b909..8812fbbe3f 100644
--- a/test/parallel/test-fs-fchown.js
+++ b/test/parallel/test-fs-fchown.js
@@ -9,7 +9,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -17,7 +17,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
@@ -26,7 +26,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "uid" argument must be of type number'
+ message: 'The "uid" argument must be of type integer'
}
);
common.expectsError(
@@ -34,7 +34,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "uid" argument must be of type number'
+ message: 'The "uid" argument must be of type integer'
}
);
@@ -43,7 +43,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "gid" argument must be of type number'
+ message: 'The "gid" argument must be of type integer'
}
);
common.expectsError(
@@ -51,60 +51,7 @@ const fs = require('fs');
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "gid" argument must be of type number'
+ message: 'The "gid" argument must be of type integer'
}
);
});
-
-[-1, 0xFFFFFFFF + 1].forEach((i) => {
- common.expectsError(
- () => fs.fchown(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
- }
- );
- common.expectsError(
- () => fs.fchownSync(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
- }
- );
-});
-
-common.expectsError(
- () => fs.fchown(1, -1),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "uid" argument is out of range'
- }
-);
-common.expectsError(
- () => fs.fchownSync(1, -1),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "uid" argument is out of range'
- }
-);
-
-common.expectsError(
- () => fs.fchown(1, 1, -1),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "gid" argument is out of range'
- }
-);
-common.expectsError(
- () => fs.fchownSync(1, 1, -1),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "gid" argument is out of range'
- }
-);
diff --git a/test/parallel/test-fs-fsync.js b/test/parallel/test-fs-fsync.js
index 80443662c2..ea80d4cbcd 100644
--- a/test/parallel/test-fs-fsync.js
+++ b/test/parallel/test-fs-fsync.js
@@ -55,7 +55,7 @@ fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -63,7 +63,7 @@ fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -71,7 +71,7 @@ fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -79,26 +79,7 @@ fs.open(fileTemp, 'a', 0o777, common.mustCall(function(err, fd) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
- }
- );
-});
-
-[-1, 0xFFFFFFFF + 1].forEach((i) => {
- common.expectsError(
- () => fs.fsync(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
- }
- );
- common.expectsError(
- () => fs.fsyncSync(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ message: 'The "fd" argument must be of type integer'
}
);
});
diff --git a/test/parallel/test-fs-link.js b/test/parallel/test-fs-link.js
index 525392aa2b..7cbfe5a15e 100644
--- a/test/parallel/test-fs-link.js
+++ b/test/parallel/test-fs-link.js
@@ -21,16 +21,33 @@ fs.link(srcPath, dstPath, common.mustCall(callback));
// test error outputs
-assert.throws(
- function() {
- fs.link();
- },
- /src must be a string or Buffer/
-);
-
-assert.throws(
- function() {
- fs.link('abc');
- },
- /dest must be a string or Buffer/
-);
+[false, 1, [], {}, null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.link(i, '', common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.link('', i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.linkSync(i, ''),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.linkSync('', i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-mkdir.js b/test/parallel/test-fs-mkdir.js
index 54585a3f12..7cfb09295e 100644
--- a/test/parallel/test-fs-mkdir.js
+++ b/test/parallel/test-fs-mkdir.js
@@ -53,6 +53,23 @@ common.refreshTmpDir();
assert.strictEqual(exists, true);
}
+[false, 1, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.mkdir(i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.mkdirSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
+
// Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop).
process.nextTick(() => {});
diff --git a/test/parallel/test-fs-open.js b/test/parallel/test-fs-open.js
index 94817844bd..e988a7e197 100644
--- a/test/parallel/test-fs-open.js
+++ b/test/parallel/test-fs-open.js
@@ -43,3 +43,20 @@ fs.open(__filename, 'r', common.mustCall((err) => {
fs.open(__filename, 'rs', common.mustCall((err) => {
assert.ifError(err);
}));
+
+[false, 1, [], {}, null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.open(i, 'r', common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.openSync(i, 'r', common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-readdir.js b/test/parallel/test-fs-readdir.js
index a5c7ebfe68..76e6a4dc37 100644
--- a/test/parallel/test-fs-readdir.js
+++ b/test/parallel/test-fs-readdir.js
@@ -33,3 +33,20 @@ assert.throws(function() {
fs.readdir(__filename, common.mustCall(function(e) {
assert.strictEqual(e.code, 'ENOTDIR');
}));
+
+[false, 1, [], {}, null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.readdir(i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.readdirSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-readlink-type-check.js b/test/parallel/test-fs-readlink-type-check.js
new file mode 100644
index 0000000000..914c1e55af
--- /dev/null
+++ b/test/parallel/test-fs-readlink-type-check.js
@@ -0,0 +1,21 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+[false, 1, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.readlink(i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.readlinkSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-rename-type-check.js b/test/parallel/test-fs-rename-type-check.js
new file mode 100644
index 0000000000..68126e9f7e
--- /dev/null
+++ b/test/parallel/test-fs-rename-type-check.js
@@ -0,0 +1,43 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+[false, 1, [], {}, null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.rename(i, 'does-not-exist', common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "oldPath" argument must be one of type string, Buffer, or URL'
+ }
+ );
+ common.expectsError(
+ () => fs.rename('does-not-exist', i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "newPath" argument must be one of type string, Buffer, or URL'
+ }
+ );
+ common.expectsError(
+ () => fs.renameSync(i, 'does-not-exist'),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "oldPath" argument must be one of type string, Buffer, or URL'
+ }
+ );
+ common.expectsError(
+ () => fs.renameSync('does-not-exist', i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "newPath" argument must be one of type string, Buffer, or URL'
+ }
+ );
+});
diff --git a/test/parallel/test-fs-rmdir-type-check.js b/test/parallel/test-fs-rmdir-type-check.js
new file mode 100644
index 0000000000..fc2106b8ca
--- /dev/null
+++ b/test/parallel/test-fs-rmdir-type-check.js
@@ -0,0 +1,21 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+[false, 1, [], {}, null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.rmdir(i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.rmdirSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js
index 57fccc1586..7f0f535d0c 100644
--- a/test/parallel/test-fs-stat.js
+++ b/test/parallel/test-fs-stat.js
@@ -137,7 +137,7 @@ fs.stat(__filename, common.mustCall(function(err, s) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -145,26 +145,38 @@ fs.stat(__filename, common.mustCall(function(err, s) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
});
-[-1, 0xFFFFFFFF + 1].forEach((i) => {
+[false, 1, {}, [], null, undefined].forEach((i) => {
common.expectsError(
- () => fs.fstat(i),
+ () => fs.lstat(i, common.mustNotCall()),
{
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
}
);
common.expectsError(
- () => fs.fstatSync(i),
+ () => fs.lstatSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.stat(i, common.mustNotCall()),
{
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.statSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
}
);
});
diff --git a/test/parallel/test-fs-symlink.js b/test/parallel/test-fs-symlink.js
index 1de7532068..a830b12c24 100644
--- a/test/parallel/test-fs-symlink.js
+++ b/test/parallel/test-fs-symlink.js
@@ -57,6 +57,63 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) {
}));
}));
+[false, 1, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.symlink(i, '', common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "target" argument must be one of type string, Buffer, or URL'
+ }
+ );
+ common.expectsError(
+ () => fs.symlink('', i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "path" argument must be one of type string, Buffer, or URL'
+ }
+ );
+ common.expectsError(
+ () => fs.symlinkSync(i, ''),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "target" argument must be one of type string, Buffer, or URL'
+ }
+ );
+ common.expectsError(
+ () => fs.symlinkSync('', i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message:
+ 'The "path" argument must be one of type string, Buffer, or URL'
+ }
+ );
+});
+
+common.expectsError(
+ () => fs.symlink('', '', '🍏', common.mustNotCall()),
+ {
+ code: 'ERR_FS_INVALID_SYMLINK_TYPE',
+ type: Error,
+ message:
+ 'Symlink type must be one of "dir", "file", or "junction". Received "🍏"'
+ }
+);
+common.expectsError(
+ () => fs.symlinkSync('', '', '🍏'),
+ {
+ code: 'ERR_FS_INVALID_SYMLINK_TYPE',
+ type: Error,
+ message:
+ 'Symlink type must be one of "dir", "file", or "junction". Received "🍏"'
+ }
+);
process.on('exit', function() {
assert.notStrictEqual(linkTime, fileTime);
diff --git a/test/parallel/test-fs-truncate.js b/test/parallel/test-fs-truncate.js
index 7690ec7c24..b32d1ceb2b 100644
--- a/test/parallel/test-fs-truncate.js
+++ b/test/parallel/test-fs-truncate.js
@@ -187,7 +187,7 @@ function testFtruncate(cb) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "len" argument must be of type number'
+ message: 'The "len" argument must be of type integer'
}
);
});
@@ -215,7 +215,7 @@ function testFtruncate(cb) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
+ message: 'The "fd" argument must be of type integer'
}
);
common.expectsError(
@@ -223,26 +223,7 @@ function testFtruncate(cb) {
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
- message: 'The "fd" argument must be of type number'
- }
- );
-});
-
-[-1, 0xFFFFFFFF + 1].forEach((i) => {
- common.expectsError(
- () => fs.ftruncate(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
- }
- );
- common.expectsError(
- () => fs.ftruncateSync(i),
- {
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ message: 'The "fd" argument must be of type integer'
}
);
});
diff --git a/test/parallel/test-fs-unlink-type-check.js b/test/parallel/test-fs-unlink-type-check.js
new file mode 100644
index 0000000000..7fe3ce946c
--- /dev/null
+++ b/test/parallel/test-fs-unlink-type-check.js
@@ -0,0 +1,21 @@
+'use strict';
+
+const common = require('../common');
+const fs = require('fs');
+
+[false, 1, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.unlink(i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.unlinkSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js
index c945548683..ca3471cddf 100644
--- a/test/parallel/test-fs-utimes.js
+++ b/test/parallel/test-fs-utimes.js
@@ -100,9 +100,8 @@ function testIt(atime, mtime, callback) {
common.expectsError(
() => fs.futimesSync(-1, atime, mtime),
{
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
}
);
tests_run++;
@@ -130,9 +129,8 @@ function testIt(atime, mtime, callback) {
common.expectsError(
() => fs.futimes(-1, atime, mtime, common.mustNotCall()),
{
- code: 'ERR_OUT_OF_RANGE',
- type: RangeError,
- message: 'The "fd" argument is out of range'
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
}
);
@@ -206,3 +204,20 @@ if (common.isWindows) {
const overflow_stats = fs.statSync(path);
assert.strictEqual(overflow_mtime, overflow_stats.mtime.getTime());
}
+
+[false, 0, {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.utimes(i, new Date(), new Date(), common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.utimesSync(i, new Date(), new Date()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});
diff --git a/test/parallel/test-fs-write.js b/test/parallel/test-fs-write.js
index ccf2d9b40f..cd52a57c36 100644
--- a/test/parallel/test-fs-write.js
+++ b/test/parallel/test-fs-write.js
@@ -86,3 +86,20 @@ fs.open(fn3, 'w', 0o644, common.mustCall(function(err, fd) {
fs.write(fd, expected, done);
}));
+
+[false, 'test', {}, [], null, undefined].forEach((i) => {
+ common.expectsError(
+ () => fs.write(i, common.mustNotCall()),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+ common.expectsError(
+ () => fs.writeSync(i),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError
+ }
+ );
+});