summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-access.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-01-31 09:47:43 -0800
committerJames M Snell <jasnell@gmail.com>2017-02-02 10:43:58 -0800
commitdfd30463276bc6e9a09c54588142eee227040e0e (patch)
treeda865f678d2f39f36a913ffce25f9e0b6899106e /test/parallel/test-fs-access.js
parentc9e5178f3c4081abdb1f2a138da6f8a4114d4905 (diff)
downloadandroid-node-v8-dfd30463276bc6e9a09c54588142eee227040e0e.tar.gz
android-node-v8-dfd30463276bc6e9a09c54588142eee227040e0e.tar.bz2
android-node-v8-dfd30463276bc6e9a09c54588142eee227040e0e.zip
test: make test-fs-access stricter
Change regular expression matching in `assert.throws()` to match the entire error message. In `assert.throws()` that uses a function for matching rather than a regular expression, add checks for the `message` property and the error's constructor. Also, refactored to remove unnecessary temp file handling. No need to remove temp files after the test. Each test is responsible for clearing the temp directory if it needs to use it. PR-URL: https://github.com/nodejs/node/pull/11087 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Diffstat (limited to 'test/parallel/test-fs-access.js')
-rw-r--r--test/parallel/test-fs-access.js40
1 files changed, 17 insertions, 23 deletions
diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js
index 4157f92f8b..34077ce1ff 100644
--- a/test/parallel/test-fs-access.js
+++ b/test/parallel/test-fs-access.js
@@ -7,16 +7,7 @@ const doesNotExist = path.join(common.tmpDir, '__this_should_not_exist');
const readOnlyFile = path.join(common.tmpDir, 'read_only_file');
const readWriteFile = path.join(common.tmpDir, 'read_write_file');
-const removeFile = function(file) {
- try {
- fs.unlinkSync(file);
- } catch (err) {
- // Ignore error
- }
-};
-
const createFileWithPerms = function(file, mode) {
- removeFile(file);
fs.writeFileSync(file, '');
fs.chmodSync(file, mode);
};
@@ -91,16 +82,16 @@ fs.access(readOnlyFile, fs.W_OK, common.mustCall((err) => {
}));
assert.throws(() => {
- fs.access(100, fs.F_OK, (err) => {});
-}, /path must be a string or Buffer/);
+ fs.access(100, fs.F_OK, () => { common.fail('callback should not run'); });
+}, /^TypeError: path must be a string or Buffer$/);
assert.throws(() => {
fs.access(__filename, fs.F_OK);
-}, /"callback" argument must be a function/);
+}, /^TypeError: "callback" argument must be a function$/);
assert.throws(() => {
fs.access(__filename, fs.F_OK, {});
-}, /"callback" argument must be a function/);
+}, /^TypeError: "callback" argument must be a function$/);
assert.doesNotThrow(() => {
fs.accessSync(__filename);
@@ -112,13 +103,16 @@ assert.doesNotThrow(() => {
fs.accessSync(readWriteFile, mode);
});
-assert.throws(() => {
- fs.accessSync(doesNotExist);
-}, (err) => {
- return err.code === 'ENOENT' && err.path === doesNotExist;
-});
-
-process.on('exit', () => {
- removeFile(readOnlyFile);
- removeFile(readWriteFile);
-});
+assert.throws(
+ () => { fs.accessSync(doesNotExist); },
+ (err) => {
+ assert.strictEqual(err.code, 'ENOENT');
+ assert.strictEqual(err.path, doesNotExist);
+ assert.strictEqual(
+ err.message,
+ `ENOENT: no such file or directory, access '${doesNotExist}'`
+ );
+ assert.strictEqual(err.constructor, Error);
+ return true;
+ }
+);