Skip to content

Commit 809dc09

Browse files
Patrick Heneiseevanlucas
Patrick Heneise
authored andcommitted
test: refactor fs.write() test
PR-URL: #16827 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 35fc317 commit 809dc09

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

test/parallel/test-fs-write.js

+31-28
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)