Browse Source

test: use tmpDir instead of fixtures in readdir

This patch

 - makes the test use tmp directory instead of the fixtures directory,
 - simplifies the code
 - moves the test to `parallel`.

PR-URL: https://github.com/nodejs/node/pull/2587

Reviewed-By: Rich Trott <rtrott@gmail.com>
v4.x
Sakthipriyan Vairamani 9 years ago
committed by Jeremiah Senkpiel
parent
commit
816f609c8b
  1. 0
      test/fixtures/readdir/are
  2. 0
      test/fixtures/readdir/dir/empty
  3. 0
      test/fixtures/readdir/empty
  4. 0
      test/fixtures/readdir/files
  5. 0
      test/fixtures/readdir/for
  6. 0
      test/fixtures/readdir/just
  7. 0
      test/fixtures/readdir/testing.js
  8. 0
      test/fixtures/readdir/these
  9. 36
      test/parallel/test-fs-readdir.js
  10. 71
      test/sequential/test-readdir.js

0
test/fixtures/readdir/are

0
test/fixtures/readdir/dir/empty

0
test/fixtures/readdir/empty

0
test/fixtures/readdir/files

0
test/fixtures/readdir/for

0
test/fixtures/readdir/just

0
test/fixtures/readdir/testing.js

0
test/fixtures/readdir/these

36
test/parallel/test-fs-readdir.js

@ -0,0 +1,36 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const readdirDir = common.tmpDir;
const files = ['empty', 'files', 'for', 'just', 'testing'];
// Make sure tmp directory is clean
common.refreshTmpDir();
// Create the necessary files
files.forEach(function(currentFile) {
fs.closeSync(fs.openSync(readdirDir + '/' + currentFile, 'w'));
});
// Check the readdir Sync version
assert.deepEqual(files, fs.readdirSync(readdirDir).sort());
// Check the readdir async version
fs.readdir(readdirDir, common.mustCall(function(err, f) {
assert.ifError(err);
assert.deepEqual(files, f.sort());
}));
// readdir() on file should throw ENOTDIR
// https://github.com/joyent/node/issues/1869
assert.throws(function() {
fs.readdirSync(__filename);
}, /Error: ENOTDIR: not a directory/);
fs.readdir(__filename, common.mustCall(function(e) {
assert.equal(e.code, 'ENOTDIR');
}));

71
test/sequential/test-readdir.js

@ -1,71 +0,0 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var got_error = false,
readdirDir = path.join(common.fixturesDir, 'readdir');
var files = ['are',
'dir',
'empty',
'files',
'for',
'just',
'testing.js',
'these'];
console.log('readdirSync ' + readdirDir);
var f = fs.readdirSync(readdirDir);
console.dir(f);
assert.deepEqual(files, f.sort());
console.log('readdir ' + readdirDir);
fs.readdir(readdirDir, function(err, f) {
if (err) {
console.log('error');
got_error = true;
} else {
console.dir(f);
assert.deepEqual(files, f.sort());
}
});
process.on('exit', function() {
assert.equal(false, got_error);
console.log('exit');
});
// readdir() on file should throw ENOTDIR
// https://github.com/joyent/node/issues/1869
(function() {
var has_caught = false;
try {
fs.readdirSync(__filename);
}
catch (e) {
has_caught = true;
assert.equal(e.code, 'ENOTDIR');
}
assert(has_caught);
})();
(function() {
var readdir_cb_called = false;
fs.readdir(__filename, function(e) {
readdir_cb_called = true;
assert.equal(e.code, 'ENOTDIR');
});
process.on('exit', function() {
assert(readdir_cb_called);
});
})();
Loading…
Cancel
Save