test: update tests for issue #775

This commit is contained in:
bcheidemann 2021-05-29 12:20:13 +01:00 committed by David Humphrey
parent 576831370f
commit d055d8042e
1 changed files with 101 additions and 5 deletions

View File

@ -1,18 +1,114 @@
'use strict';
const util = require('../lib/test-utils.js');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.readdir fails when passing options, issue775', function () {
beforeEach(util.setup);
afterEach(util.cleanup);
it.skip('should create a directory then call fs.readdir with options', function (done) {
const fs = util.fs();
fs.mkdir('/test_dir', undefined, (err) => {
function setup(fs, dir, cb) {
fs.mkdir(dir, undefined, (err) => {
if (err) {
cb(err);
}
else {
fs.writeFile(dir + '/file', '', (err) => {
if (err) {
cb(err);
}
else {
fs.mkdir(dir + '/folder', (err) => {
if (err) {
cb(err);
}
else {
fs.symlink(dir + '/file', dir + '/symlink', (err) => {
if (err) {
cb(err);
}
else {
cb();
}
});
}
});
}
});
}
});
}
it('should create a directory, add a file, folder and symbolic link then call fs.readdir with buffer encoding', function (done) {
var fs = util.fs();
setup(fs, '/test_dir', (err) => {
if (err) {
done(err);
}
fs.readdir('/test_dir', 'buffer', (err, data) => {
if (err) {
done(err);
}
else {
expect(data).to.have.length(3);
expect(data[0].toString()).to.equal('file');
expect(data[1].toString()).to.equal('folder');
expect(data[2].toString()).to.equal('symlink');
done();
}
});
});
});
it('should create a directory, add a file, folder and symbolic link then call fs.readdir with withFileTypes and encoding options', function (done) {
var fs = util.fs();
setup(fs, '/test_dir', (err) => {
if (err) {
done(err);
}
fs.readdir('/test_dir', { encoding: 'base64', withFileTypes: true }, (err, data) => {
if (err) {
done(err);
}
else {
expect(data).to.have.length(3);
expect(Buffer.from(data[0].name, 'base64').toString()).to.equal('file');
expect(Buffer.from(data[1].name, 'base64').toString()).to.equal('folder');
expect(Buffer.from(data[2].name, 'base64').toString()).to.equal('symlink');
expect(data[0].isFile()).to.be.true;
expect(data[1].isDirectory()).to.be.true;
expect(data[2].isSymbolicLink()).to.be.true;
done();
}
});
});
});
it('should create a directory then call fs.readdir without options', function (done) {
var fs = util.fs();
setup(fs, '/test_dir', (err) => {
if (err) {
done(err);
}
else {
fs.readdir('/test_dir', { withFileTypes: true }, done);
fs.readdir('/test_dir', (err, data) => {
if (err) {
done(err);
}
else {
expect(data).to.have.length(3);
expect(data[0]).to.equal('file');
expect(data[1]).to.equal('folder');
expect(data[2]).to.equal('symlink');
done();
}
});
}
});
});