summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2018-06-04 13:52:58 +0200
committerRich Trott <rtrott@gmail.com>2018-06-06 21:00:52 -0700
commit97a4ba3d23b44d8e91980ebd641269572f56871a (patch)
treea5a5ea86db4e302079366f3b7dd63b03c915fb82 /test
parent16d63e629d433c27d431260322fd3cd53f910e0c (diff)
downloadandroid-node-v8-97a4ba3d23b44d8e91980ebd641269572f56871a.tar.gz
android-node-v8-97a4ba3d23b44d8e91980ebd641269572f56871a.tar.bz2
android-node-v8-97a4ba3d23b44d8e91980ebd641269572f56871a.zip
test: apply promises API to fourth appendFile test
Add tests for `fs.promises.appendFile()` to the fourth (of five) test case in `test-fs-access`. (The previous test cases already have promises API versions.) PR-URL: https://github.com/nodejs/node/pull/21131 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-append-file.js63
1 files changed, 42 insertions, 21 deletions
diff --git a/test/parallel/test-fs-append-file.js b/test/parallel/test-fs-append-file.js
index 05dcee43e6..2d4c64863f 100644
--- a/test/parallel/test-fs-append-file.js
+++ b/test/parallel/test-fs-append-file.js
@@ -132,29 +132,51 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
.catch(throwNextTick);
}
-// test that appendFile accepts numbers.
-const filename4 = join(tmpdir.path, 'append4.txt');
-fs.writeFileSync(filename4, currentFileData);
+// test that appendFile accepts numbers (callback API)
+{
+ const filename = join(tmpdir.path, 'append-numbers.txt');
+ fs.writeFileSync(filename, currentFileData);
-const m = 0o600;
-fs.appendFile(filename4, n, { mode: m }, function(e) {
- assert.ifError(e);
+ const m = 0o600;
+ fs.appendFile(filename, n, { mode: m }, common.mustCall((e) => {
+ assert.ifError(e);
- ncallbacks++;
+ // windows permissions aren't unix
+ if (!common.isWindows) {
+ const st = fs.statSync(filename);
+ assert.strictEqual(st.mode & 0o700, m);
+ }
- // windows permissions aren't unix
- if (!common.isWindows) {
- const st = fs.statSync(filename4);
- assert.strictEqual(st.mode & 0o700, m);
- }
+ fs.readFile(filename, common.mustCall((e, buffer) => {
+ assert.ifError(e);
+ assert.strictEqual(Buffer.byteLength(String(n)) + currentFileData.length,
+ buffer.length);
+ }));
+ }));
+}
- fs.readFile(filename4, function(e, buffer) {
- assert.ifError(e);
- ncallbacks++;
- assert.strictEqual(Buffer.byteLength(String(n)) + currentFileData.length,
- buffer.length);
- });
-});
+// test that appendFile accepts numbers (promises API)
+{
+ const filename = join(tmpdir.path, 'append-numbers-promises.txt');
+ fs.writeFileSync(filename, currentFileData);
+
+ const m = 0o600;
+ fs.promises.appendFile(filename, n, { mode: m })
+ .then(common.mustCall(() => {
+ // windows permissions aren't unix
+ if (!common.isWindows) {
+ const st = fs.statSync(filename);
+ assert.strictEqual(st.mode & 0o700, m);
+ }
+
+ return fs.promises.readFile(filename);
+ }))
+ .then((buffer) => {
+ assert.strictEqual(Buffer.byteLength(String(n)) + currentFileData.length,
+ buffer.length);
+ })
+ .catch(throwNextTick);
+}
// test that appendFile accepts file descriptors
const filename5 = join(tmpdir.path, 'append5.txt');
@@ -191,8 +213,7 @@ assert.throws(
{ code: 'ERR_INVALID_CALLBACK' });
process.on('exit', function() {
- assert.strictEqual(ncallbacks, 6);
+ assert.strictEqual(ncallbacks, 4);
- fs.unlinkSync(filename4);
fs.unlinkSync(filename5);
});