Skip to content

Commit

Permalink
Remove conditions for untested versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Sep 26, 2024
1 parent eb08cfa commit 9283179
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 83 deletions.
3 changes: 1 addition & 2 deletions test/lib/fs.link-symlink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fs = require('fs');
const mock = require('../../lib/index.js');

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

describe('fs.link(srcpath, dstpath, callback)', function () {
beforeEach(function () {
Expand Down Expand Up @@ -198,7 +197,7 @@ describe('fs.symlink(srcpath, dstpath, [type], callback)', function () {

// https://github.com/nodejs/node/issues/34514
if (process.platform === 'win32') {
inVersion('>=15.0.0').it('supports Buffer input', function (done) {
it('supports Buffer input', function (done) {
fs.symlink(
Buffer.from('../file.txt'),
Buffer.from('dir/link.txt'),
Expand Down
25 changes: 0 additions & 25 deletions test/lib/fs.open-close.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fs = require('fs');
const mock = require('../../lib/index.js');

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

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

inVersion('<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
103 changes: 49 additions & 54 deletions test/lib/fs.rmdir.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const fs = require('fs');
const mock = require('../../lib/index.js');

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

const testParentPerms = process.getuid && process.getgid;

Expand Down Expand Up @@ -116,58 +115,56 @@ describe('fs.rmdir(path, callback)', function () {
);
});

inVersion('>=12.10').run(function () {
it('recursively remove empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);
it('recursively remove empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);

fs.rmdir('path2/to/empty', {recursive: true}, function (err) {
if (err) {
return done(err);
}
fs.rmdir('path2/to/empty', {recursive: true}, function (err) {
if (err) {
return done(err);
}
assert.isFalse(fs.existsSync('path2/to/empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
done();
});
});

it('promise recursively remove empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);

fs.promises
.rmdir('path2/to/empty', {recursive: true})
.then(function () {
assert.isFalse(fs.existsSync('path2/to/empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
done();
});
});
})
.catch(done);
});

it('promise recursively remove empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);
it('recursively remove non-empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);

fs.promises
.rmdir('path2/to/empty', {recursive: true})
.then(function () {
assert.isFalse(fs.existsSync('path2/to/empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
done();
})
.catch(done);
fs.rmdir('path2/to/non-empty', {recursive: true}, function (err) {
if (err) {
return done(err);
}
assert.isFalse(fs.existsSync('path2/to/non-empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
done();
});
});

it('recursively remove non-empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);
it('promise recursively remove non-empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);

fs.rmdir('path2/to/non-empty', {recursive: true}, function (err) {
if (err) {
return done(err);
}
fs.promises
.rmdir('path2/to/non-empty', {recursive: true})
.then(function () {
assert.isFalse(fs.existsSync('path2/to/non-empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
done();
});
});

it('promise recursively remove non-empty directory', function (done) {
assert.equal(fs.statSync('path2/to').nlink, 4);

fs.promises
.rmdir('path2/to/non-empty', {recursive: true})
.then(function () {
assert.isFalse(fs.existsSync('path2/to/non-empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
done();
})
.catch(done);
});
})
.catch(done);
});

if (testParentPerms) {
Expand Down Expand Up @@ -221,20 +218,18 @@ describe('fs.rmdirSync(path)', function () {
});
});

inVersion('>=12.10').run(function () {
it('recursively remove empty directory', function () {
assert.equal(fs.statSync('path2/to').nlink, 4);
fs.rmdirSync('path2/to/empty', {recursive: true});
assert.isFalse(fs.existsSync('path2/to/empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
});
it('recursively remove empty directory', function () {
assert.equal(fs.statSync('path2/to').nlink, 4);
fs.rmdirSync('path2/to/empty', {recursive: true});
assert.isFalse(fs.existsSync('path2/to/empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
});

it('recursively remove non-empty directory', function () {
assert.equal(fs.statSync('path2/to').nlink, 4);
fs.rmdirSync('path2/to/non-empty', {recursive: true});
assert.isFalse(fs.existsSync('path2/to/non-empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
});
it('recursively remove non-empty directory', function () {
assert.equal(fs.statSync('path2/to').nlink, 4);
fs.rmdirSync('path2/to/non-empty', {recursive: true});
assert.isFalse(fs.existsSync('path2/to/non-empty'));
assert.equal(fs.statSync('path2/to').nlink, 3);
});

if (testParentPerms) {
Expand Down
3 changes: 1 addition & 2 deletions test/lib/readfilecontext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
} = require('../../lib/readfilecontext.js');

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

describe('getReadFileContextPrototype', function () {
it('provides access to the internal ReadFileContext', function () {
Expand Down Expand Up @@ -122,7 +121,7 @@ describe('fs.readFile() with ReadFileContext', function () {
});
afterEach(mock.restore);

inVersion('>=15.0.0').it('allows file reads to be aborted', function (done) {
it('allows file reads to be aborted', function (done) {
const controller = new AbortController();
const {signal} = controller;

Expand Down

0 comments on commit 9283179

Please sign in to comment.