Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fs.write() if 3rd argument is a callback, not offset #17045

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: fs.write() if 3rd argument is a callback, not offset; easier wa…
…y to resolve conflicts from #16822 and #16827
  • Loading branch information
Patrick Heneise committed Nov 15, 2017
commit 7e3635f8adfcce8dde4c39f4d640708dd2a96c7b
24 changes: 16 additions & 8 deletions test/parallel/test-fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
assert.ifError(err);

const done = common.mustCall((err, written) => {
console.log('open done');
fs.write(fd, '', 0, 'utf8', (err, written) => {
assert.strictEqual(0, written);
});
fs.write(fd, expected, 0, 'utf8', common.mustCall((err, written) => {
console.log('write done');
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
const found = fs.readFileSync(fn2, 'utf8');
console.log('expected: "%s"', expected);
console.log('found: "%s"', found);
fs.unlinkSync(fn2);
assert.strictEqual(expected, found);
});
}));
}));

const written = common.mustCall(function(err, written) {
fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use something other than fn to prevent any issues with the tests interacting with one another.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

assert.ifError(err);
const done = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(0, written);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
});

fs.write(fd, '', 0, 'utf8', written);
fs.write(fd, expected, 0, 'utf8', done);
fs.write(fd, expected, done);
}));