Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c8fb6a

Browse filesBrowse files
Patrick HeneiseMylesBorins
authored andcommitted
test: refactor fs.write() test
PR-URL: #16827 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent 4f587e5 commit 5c8fb6a
Copy full SHA for 5c8fb6a

File tree

Expand file treeCollapse file tree

1 file changed

+31
-28
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-28
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-fs-write.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-write.js
+31-28Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,43 @@ common.refreshTmpDir();
3333

3434
fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
3535
assert.ifError(err);
36-
console.log('open done');
37-
fs.write(fd, '', 0, 'utf8', function(err, written) {
38-
assert.strictEqual(0, written);
39-
});
40-
fs.write(fd, expected, 0, 'utf8', common.mustCall(function(err, written) {
41-
console.log('write done');
36+
37+
const done = common.mustCall(function(err, written) {
4238
assert.ifError(err);
4339
assert.strictEqual(Buffer.byteLength(expected), written);
4440
fs.closeSync(fd);
4541
const found = fs.readFileSync(fn, 'utf8');
46-
console.log('expected: "%s"', expected);
47-
console.log('found: "%s"', found);
4842
fs.unlinkSync(fn);
4943
assert.strictEqual(expected, found);
50-
}));
44+
});
45+
46+
const written = common.mustCall(function(err, written) {
47+
assert.ifError(err);
48+
assert.strictEqual(0, written);
49+
});
50+
51+
fs.write(fd, '', 0, 'utf8', written);
52+
fs.write(fd, expected, 0, 'utf8', done);
5153
}));
5254

55+
const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
56+
fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
57+
assert.ifError(err);
5358

54-
fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 0o644,
55-
common.mustCall((err, fd) => {
56-
assert.ifError(err);
57-
console.log('open done');
58-
fs.write(fd, '', 0, 'utf8', (err, written) => {
59-
assert.strictEqual(0, written);
60-
});
61-
fs.write(fd, expected, 0, 'utf8', common.mustCall((err, written) => {
62-
console.log('write done');
63-
assert.ifError(err);
64-
assert.strictEqual(Buffer.byteLength(expected), written);
65-
fs.closeSync(fd);
66-
const found = fs.readFileSync(fn2, 'utf8');
67-
console.log('expected: "%s"', expected);
68-
console.log('found: "%s"', found);
69-
fs.unlinkSync(fn2);
70-
assert.strictEqual(expected, found);
71-
}));
72-
}));
59+
const done = common.mustCall((err, written) => {
60+
assert.ifError(err);
61+
assert.strictEqual(Buffer.byteLength(expected), written);
62+
fs.closeSync(fd);
63+
const found = fs.readFileSync(fn2, 'utf8');
64+
fs.unlinkSync(fn2);
65+
assert.strictEqual(expected, found);
66+
});
67+
68+
const written = common.mustCall(function(err, written) {
69+
assert.ifError(err);
70+
assert.strictEqual(0, written);
71+
});
72+
73+
fs.write(fd, '', 0, 'utf8', written);
74+
fs.write(fd, expected, 0, 'utf8', done);
75+
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.