diff options
Diffstat (limited to 'tests/node_compat/test/parallel/test-fs-access.js')
-rw-r--r-- | tests/node_compat/test/parallel/test-fs-access.js | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/tests/node_compat/test/parallel/test-fs-access.js b/tests/node_compat/test/parallel/test-fs-access.js index a67f9fe07..8add7d553 100644 --- a/tests/node_compat/test/parallel/test-fs-access.js +++ b/tests/node_compat/test/parallel/test-fs-access.js @@ -20,15 +20,14 @@ if (common.isIBMi) const assert = require('assert'); const fs = require('fs'); -const path = require('path'); const { internalBinding } = require('internal/test/binding'); const { UV_ENOENT } = internalBinding('uv'); const tmpdir = require('../common/tmpdir'); -const doesNotExist = path.join(tmpdir.path, '__this_should_not_exist'); -const readOnlyFile = path.join(tmpdir.path, 'read_only_file'); -const readWriteFile = path.join(tmpdir.path, 'read_write_file'); +const doesNotExist = tmpdir.resolve('__this_should_not_exist'); +const readOnlyFile = tmpdir.resolve('read_only_file'); +const readWriteFile = tmpdir.resolve('read_write_file'); function createFileWithPerms(file, mode) { fs.writeFileSync(file, ''); @@ -71,10 +70,10 @@ if (!common.isWindows && process.getuid() === 0) { } } -assert.strictEqual(typeof fs.F_OK, 'number'); -assert.strictEqual(typeof fs.R_OK, 'number'); -assert.strictEqual(typeof fs.W_OK, 'number'); -assert.strictEqual(typeof fs.X_OK, 'number'); +assert.strictEqual(typeof fs.constants.F_OK, 'number'); +assert.strictEqual(typeof fs.constants.R_OK, 'number'); +assert.strictEqual(typeof fs.constants.W_OK, 'number'); +assert.strictEqual(typeof fs.constants.X_OK, 'number'); const throwNextTick = (e) => { process.nextTick(() => { throw e; }); }; @@ -84,16 +83,16 @@ fs.access(__filename, common.mustCall(function(...args) { fs.promises.access(__filename) .then(common.mustCall()) .catch(throwNextTick); -fs.access(__filename, fs.R_OK, common.mustCall(function(...args) { +fs.access(__filename, fs.constants.R_OK, common.mustCall(function(...args) { assert.deepStrictEqual(args, [null]); })); -fs.promises.access(__filename, fs.R_OK) +fs.promises.access(__filename, fs.constants.R_OK) .then(common.mustCall()) .catch(throwNextTick); -fs.access(readOnlyFile, fs.R_OK, common.mustCall(function(...args) { +fs.access(readOnlyFile, fs.constants.R_OK, common.mustCall(function(...args) { assert.deepStrictEqual(args, [null]); })); -fs.promises.access(readOnlyFile, fs.R_OK) +fs.promises.access(readOnlyFile, fs.constants.R_OK) .then(common.mustCall()) .catch(throwNextTick); @@ -119,8 +118,8 @@ fs.promises.access(readOnlyFile, fs.R_OK) assert.strictEqual(err.path, readOnlyFile); } } - fs.access(readOnlyFile, fs.W_OK, common.mustCall(expectedError)); - fs.promises.access(readOnlyFile, fs.W_OK) + fs.access(readOnlyFile, fs.constants.W_OK, common.mustCall(expectedError)); + fs.promises.access(readOnlyFile, fs.constants.W_OK) .then(common.mustNotCall(), common.mustCall(expectedError)) .catch(throwNextTick); } @@ -132,18 +131,18 @@ fs.promises.access(readOnlyFile, fs.R_OK) return true; }; assert.throws( - () => { fs.access(100, fs.F_OK, common.mustNotCall()); }, + () => { fs.access(100, fs.constants.F_OK, common.mustNotCall()); }, expectedError ); - fs.promises.access(100, fs.F_OK) + fs.promises.access(100, fs.constants.F_OK) .then(common.mustNotCall(), common.mustCall(expectedError)) .catch(throwNextTick); } assert.throws( () => { - fs.access(__filename, fs.F_OK); + fs.access(__filename, fs.constants.F_OK); }, { code: 'ERR_INVALID_ARG_TYPE', @@ -152,7 +151,7 @@ assert.throws( assert.throws( () => { - fs.access(__filename, fs.F_OK, common.mustNotMutateObjectDeep({})); + fs.access(__filename, fs.constants.F_OK, common.mustNotMutateObjectDeep({})); }, { code: 'ERR_INVALID_ARG_TYPE', @@ -161,14 +160,14 @@ assert.throws( // Regular access should not throw. fs.accessSync(__filename); -const mode = fs.R_OK | fs.W_OK; +const mode = fs.constants.R_OK | fs.constants.W_OK; fs.accessSync(readWriteFile, mode); // Invalid modes should throw. [ false, 1n, - { [Symbol.toPrimitive]() { return fs.R_OK; } }, + { [Symbol.toPrimitive]() { return fs.constants.R_OK; } }, [1], 'r', ].forEach((mode, i) => { |