summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2018-05-10 16:48:45 -0700
committerAnna Henningsen <anna@addaleax.net>2018-05-14 18:38:31 +0200
commit617f0d27637b428c3eed1920d0c0da59f5b7d714 (patch)
tree28bffcf3a0feca35e4886f6d8ec206ebb02e10dd /test
parent2e4ee3dfa0676b639b23ed9e038ede313726af61 (diff)
downloadandroid-node-v8-617f0d27637b428c3eed1920d0c0da59f5b7d714.tar.gz
android-node-v8-617f0d27637b428c3eed1920d0c0da59f5b7d714.tar.bz2
android-node-v8-617f0d27637b428c3eed1920d0c0da59f5b7d714.zip
test: apply test-fs-access to promises API
Add tests for `fs.promises.access()` in all test cases in `test-fs-access` that are relevant to the Promises-based API. PR-URL: https://github.com/nodejs/node/pull/20667 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-access.js77
1 files changed, 52 insertions, 25 deletions
diff --git a/test/parallel/test-fs-access.js b/test/parallel/test-fs-access.js
index 20448ffde6..01dbe90eda 100644
--- a/test/parallel/test-fs-access.js
+++ b/test/parallel/test-fs-access.js
@@ -62,37 +62,64 @@ assert.strictEqual(typeof fs.R_OK, 'number');
assert.strictEqual(typeof fs.W_OK, 'number');
assert.strictEqual(typeof fs.X_OK, 'number');
+const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
+
fs.access(__filename, common.mustCall(assert.ifError));
+fs.promises.access(__filename)
+ .then(common.mustCall())
+ .catch(throwNextTick);
fs.access(__filename, fs.R_OK, common.mustCall(assert.ifError));
+fs.promises.access(__filename, fs.R_OK)
+ .then(common.mustCall())
+ .catch(throwNextTick);
fs.access(readOnlyFile, fs.F_OK | fs.R_OK, common.mustCall(assert.ifError));
+fs.promises.access(readOnlyFile, fs.F_OK | fs.R_OK)
+ .then(common.mustCall())
+ .catch(throwNextTick);
-fs.access(doesNotExist, common.mustCall((err) => {
- assert.notStrictEqual(err, null, 'error should exist');
- assert.strictEqual(err.code, 'ENOENT');
- assert.strictEqual(err.path, doesNotExist);
-}));
-
-fs.access(readOnlyFile, fs.W_OK, common.mustCall(function(err) {
- assert.strictEqual(this, undefined);
- if (hasWriteAccessForReadonlyFile) {
- assert.ifError(err);
- } else {
- assert.notStrictEqual(err, null, 'error should exist');
- assert.strictEqual(err.path, readOnlyFile);
- }
-}));
+{
+ const expectedError = (err) => {
+ assert.notStrictEqual(err, null);
+ assert.strictEqual(err.code, 'ENOENT');
+ assert.strictEqual(err.path, doesNotExist);
+ };
+ fs.access(doesNotExist, common.mustCall(expectedError));
+ fs.promises.access(doesNotExist)
+ .then(common.mustNotCall(), common.mustCall(expectedError))
+ .catch(throwNextTick);
+}
-common.expectsError(
- () => {
- fs.access(100, fs.F_OK, common.mustNotCall());
- },
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "path" argument must be one of type string, Buffer, or URL.' +
- ' Received type number'
+{
+ function expectedError(err) {
+ assert.strictEqual(this, undefined);
+ if (hasWriteAccessForReadonlyFile) {
+ assert.ifError(err);
+ } else {
+ assert.notStrictEqual(err, null);
+ assert.strictEqual(err.path, readOnlyFile);
+ }
}
-);
+ fs.access(readOnlyFile, fs.W_OK, common.mustCall(expectedError));
+ fs.promises.access(readOnlyFile, fs.W_OK)
+ .then(common.mustNotCall(), common.mustCall(expectedError))
+ .catch(throwNextTick);
+}
+
+{
+ const expectedError = (err) => {
+ assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE');
+ assert.ok(err instanceof TypeError);
+ return true;
+ };
+ assert.throws(
+ () => { fs.access(100, fs.F_OK, common.mustNotCall()); },
+ expectedError
+ );
+
+ fs.promises.access(100, fs.F_OK)
+ .then(common.mustNotCall(), common.mustCall(expectedError))
+ .catch(throwNextTick);
+}
common.expectsError(
() => {