Skip to content

Commit 6bc122f

Browse files
LiviaMedeirosalexfernandez
authored andcommitted
test: use fs.constants for fs.access constants
PR-URL: nodejs#49685 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent cdc6f45 commit 6bc122f

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

test/parallel/test-fs-access.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ if (!common.isWindows && process.getuid() === 0) {
6363
}
6464
}
6565

66-
assert.strictEqual(typeof fs.F_OK, 'number');
67-
assert.strictEqual(typeof fs.R_OK, 'number');
68-
assert.strictEqual(typeof fs.W_OK, 'number');
69-
assert.strictEqual(typeof fs.X_OK, 'number');
66+
assert.strictEqual(typeof fs.constants.F_OK, 'number');
67+
assert.strictEqual(typeof fs.constants.R_OK, 'number');
68+
assert.strictEqual(typeof fs.constants.W_OK, 'number');
69+
assert.strictEqual(typeof fs.constants.X_OK, 'number');
7070

7171
const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
7272

@@ -76,16 +76,16 @@ fs.access(__filename, common.mustCall(function(...args) {
7676
fs.promises.access(__filename)
7777
.then(common.mustCall())
7878
.catch(throwNextTick);
79-
fs.access(__filename, fs.R_OK, common.mustCall(function(...args) {
79+
fs.access(__filename, fs.constants.R_OK, common.mustCall(function(...args) {
8080
assert.deepStrictEqual(args, [null]);
8181
}));
82-
fs.promises.access(__filename, fs.R_OK)
82+
fs.promises.access(__filename, fs.constants.R_OK)
8383
.then(common.mustCall())
8484
.catch(throwNextTick);
85-
fs.access(readOnlyFile, fs.R_OK, common.mustCall(function(...args) {
85+
fs.access(readOnlyFile, fs.constants.R_OK, common.mustCall(function(...args) {
8686
assert.deepStrictEqual(args, [null]);
8787
}));
88-
fs.promises.access(readOnlyFile, fs.R_OK)
88+
fs.promises.access(readOnlyFile, fs.constants.R_OK)
8989
.then(common.mustCall())
9090
.catch(throwNextTick);
9191

@@ -111,8 +111,8 @@ fs.promises.access(readOnlyFile, fs.R_OK)
111111
assert.strictEqual(err.path, readOnlyFile);
112112
}
113113
}
114-
fs.access(readOnlyFile, fs.W_OK, common.mustCall(expectedError));
115-
fs.promises.access(readOnlyFile, fs.W_OK)
114+
fs.access(readOnlyFile, fs.constants.W_OK, common.mustCall(expectedError));
115+
fs.promises.access(readOnlyFile, fs.constants.W_OK)
116116
.then(common.mustNotCall(), common.mustCall(expectedError))
117117
.catch(throwNextTick);
118118
}
@@ -124,18 +124,18 @@ fs.promises.access(readOnlyFile, fs.R_OK)
124124
return true;
125125
};
126126
assert.throws(
127-
() => { fs.access(100, fs.F_OK, common.mustNotCall()); },
127+
() => { fs.access(100, fs.constants.F_OK, common.mustNotCall()); },
128128
expectedError
129129
);
130130

131-
fs.promises.access(100, fs.F_OK)
131+
fs.promises.access(100, fs.constants.F_OK)
132132
.then(common.mustNotCall(), common.mustCall(expectedError))
133133
.catch(throwNextTick);
134134
}
135135

136136
assert.throws(
137137
() => {
138-
fs.access(__filename, fs.F_OK);
138+
fs.access(__filename, fs.constants.F_OK);
139139
},
140140
{
141141
code: 'ERR_INVALID_ARG_TYPE',
@@ -144,7 +144,7 @@ assert.throws(
144144

145145
assert.throws(
146146
() => {
147-
fs.access(__filename, fs.F_OK, common.mustNotMutateObjectDeep({}));
147+
fs.access(__filename, fs.constants.F_OK, common.mustNotMutateObjectDeep({}));
148148
},
149149
{
150150
code: 'ERR_INVALID_ARG_TYPE',
@@ -153,14 +153,14 @@ assert.throws(
153153

154154
// Regular access should not throw.
155155
fs.accessSync(__filename);
156-
const mode = fs.R_OK | fs.W_OK;
156+
const mode = fs.constants.R_OK | fs.constants.W_OK;
157157
fs.accessSync(readWriteFile, mode);
158158

159159
// Invalid modes should throw.
160160
[
161161
false,
162162
1n,
163-
{ [Symbol.toPrimitive]() { return fs.R_OK; } },
163+
{ [Symbol.toPrimitive]() { return fs.constants.R_OK; } },
164164
[1],
165165
'r',
166166
].forEach((mode, i) => {

test/parallel/test-fs-null-bytes.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function check(async, sync) {
5252
}
5353

5454
check(fs.access, fs.accessSync, 'foo\u0000bar');
55-
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.F_OK);
55+
check(fs.access, fs.accessSync, 'foo\u0000bar', fs.constants.F_OK);
5656
check(fs.appendFile, fs.appendFileSync, 'foo\u0000bar', 'abc');
5757
check(fs.chmod, fs.chmodSync, 'foo\u0000bar', '0644');
5858
check(fs.chown, fs.chownSync, 'foo\u0000bar', 12, 34);
@@ -87,7 +87,7 @@ const fileUrl = new URL('file:///C:/foo\u0000bar');
8787
const fileUrl2 = new URL('file:///C:/foo%00bar');
8888

8989
check(fs.access, fs.accessSync, fileUrl);
90-
check(fs.access, fs.accessSync, fileUrl, fs.F_OK);
90+
check(fs.access, fs.accessSync, fileUrl, fs.constants.F_OK);
9191
check(fs.appendFile, fs.appendFileSync, fileUrl, 'abc');
9292
check(fs.chmod, fs.chmodSync, fileUrl, '0644');
9393
check(fs.chown, fs.chownSync, fileUrl, 12, 34);
@@ -119,7 +119,7 @@ check(null, fs.watchFile, fileUrl, assert.fail);
119119
check(fs.writeFile, fs.writeFileSync, fileUrl, 'abc');
120120

121121
check(fs.access, fs.accessSync, fileUrl2);
122-
check(fs.access, fs.accessSync, fileUrl2, fs.F_OK);
122+
check(fs.access, fs.accessSync, fileUrl2, fs.constants.F_OK);
123123
check(fs.appendFile, fs.appendFileSync, fileUrl2, 'abc');
124124
check(fs.chmod, fs.chmodSync, fileUrl2, '0644');
125125
check(fs.chown, fs.chownSync, fileUrl2, 12, 34);

test/sequential/test-async-wrap-getasyncid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
165165
req.oncomplete = () => { };
166166

167167
testInitialized(req, 'FSReqCallback');
168-
binding.access(path.toNamespacedPath('../'), fs.F_OK, req);
168+
binding.access(path.toNamespacedPath('../'), fs.constants.F_OK, req);
169169

170170
const StatWatcher = binding.StatWatcher;
171171
testInitialized(new StatWatcher(), 'StatWatcher');

0 commit comments

Comments
 (0)