GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: apply promises API to fourth appendFile test · nodejs/node@aa9dbf6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-fs-append-file.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-fs-append-file.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-append-file.js
+42-21Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,51 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
132132
.catch(throwNextTick);
133133
}
134134

135-
// test that appendFile accepts numbers.
136-
const filename4 = join(tmpdir.path, 'append4.txt');
137-
fs.writeFileSync(filename4, currentFileData);
135+
// test that appendFile accepts numbers (callback API)
136+
{
137+
const filename = join(tmpdir.path, 'append-numbers.txt');
138+
fs.writeFileSync(filename, currentFileData);
138139

139-
const m = 0o600;
140-
fs.appendFile(filename4, n, { mode: m }, function(e) {
141-
assert.ifError(e);
140+
const m = 0o600;
141+
fs.appendFile(filename, n, { mode: m }, common.mustCall((e) => {
142+
assert.ifError(e);
142143

143-
ncallbacks++;
144+
// windows permissions aren't unix
145+
if (!common.isWindows) {
146+
const st = fs.statSync(filename);
147+
assert.strictEqual(st.mode & 0o700, m);
148+
}
144149

145-
// windows permissions aren't unix
146-
if (!common.isWindows) {
147-
const st = fs.statSync(filename4);
148-
assert.strictEqual(st.mode & 0o700, m);
149-
}
150+
fs.readFile(filename, common.mustCall((e, buffer) => {
151+
assert.ifError(e);
152+
assert.strictEqual(Buffer.byteLength(String(n)) + currentFileData.length,
153+
buffer.length);
154+
}));
155+
}));
156+
}
150157

151-
fs.readFile(filename4, function(e, buffer) {
152-
assert.ifError(e);
153-
ncallbacks++;
154-
assert.strictEqual(Buffer.byteLength(String(n)) + currentFileData.length,
155-
buffer.length);
156-
});
157-
});
158+
// test that appendFile accepts numbers (promises API)
159+
{
160+
const filename = join(tmpdir.path, 'append-numbers-promises.txt');
161+
fs.writeFileSync(filename, currentFileData);
162+
163+
const m = 0o600;
164+
fs.promises.appendFile(filename, n, { mode: m })
165+
.then(common.mustCall(() => {
166+
// windows permissions aren't unix
167+
if (!common.isWindows) {
168+
const st = fs.statSync(filename);
169+
assert.strictEqual(st.mode & 0o700, m);
170+
}
171+
172+
return fs.promises.readFile(filename);
173+
}))
174+
.then((buffer) => {
175+
assert.strictEqual(Buffer.byteLength(String(n)) + currentFileData.length,
176+
buffer.length);
177+
})
178+
.catch(throwNextTick);
179+
}
158180

159181
// test that appendFile accepts file descriptors
160182
const filename5 = join(tmpdir.path, 'append5.txt');
@@ -191,8 +213,7 @@ assert.throws(
191213
{ code: 'ERR_INVALID_CALLBACK' });
192214

193215
process.on('exit', function() {
194-
assert.strictEqual(ncallbacks, 6);
216+
assert.strictEqual(ncallbacks, 4);
195217

196-
fs.unlinkSync(filename4);
197218
fs.unlinkSync(filename5);
198219
});

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.