Skip to content

Commit

Permalink
test: nodejs v14+ silently ignores closing closed file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Mar 16, 2021
1 parent 819f809 commit 91e85c2
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions test/lib/fs.open-close.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const mock = require('../../lib/index');

const assert = helper.assert;
const withPromise = helper.withPromise;
const inVersion = helper.inVersion;

describe('fs.open(path, flags, [mode], callback)', function() {
beforeEach(function() {
Expand Down Expand Up @@ -220,25 +221,29 @@ describe('fs.close(fd, callback)', function() {
});
});

withPromise.it('promise fails for closed file descriptors', function(done) {
fs.promises
.open('dir/file.txt', 'w')
.then(function(fd) {
return fd.close().then(function() {
return fd.close();
});
})
.then(
function() {
done(new Error('should not succeed.'));
},
function(err) {
assert.instanceOf(err, Error);
assert.equal(err.code, 'EBADF');
done();
}
);
});
inVersion('>=10.0.0 <14.0.0').it(
'promise fails for closed file descriptors',
function(done) {
fs.promises
.open('dir/file.txt', 'w')
.then(function(fd) {
return fd.close().then(function() {
// in Nodejs v14+, closing on closed file descriptor is silently ignored.
return fd.close();
});
})
.then(
function() {
done(new Error('should not succeed.'));
},
function(err) {
assert.instanceOf(err, Error);
assert.equal(err.code, 'EBADF');
done();
}
);
}
);
});

describe('fs.closeSync(fd)', function() {
Expand Down

0 comments on commit 91e85c2

Please sign in to comment.