From: Sakthipriyan Vairamani Date: Fri, 28 Aug 2015 01:17:10 +0000 (+0530) Subject: test: use tmpDir instead of fixtures in readdir X-Git-Tag: v4.1.1~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=816f609c8be319747b35f7e5adb91929396f5185;p=platform%2Fupstream%2Fnodejs.git 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 --- diff --git a/test/fixtures/readdir/are b/test/fixtures/readdir/are deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/dir/empty b/test/fixtures/readdir/dir/empty deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/empty b/test/fixtures/readdir/empty deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/files b/test/fixtures/readdir/files deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/for b/test/fixtures/readdir/for deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/just b/test/fixtures/readdir/just deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/testing.js b/test/fixtures/readdir/testing.js deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/readdir/these b/test/fixtures/readdir/these deleted file mode 100644 index e69de29..0000000 diff --git a/test/parallel/test-fs-readdir.js b/test/parallel/test-fs-readdir.js new file mode 100644 index 0000000..b08f42b --- /dev/null +++ b/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'); +})); diff --git a/test/sequential/test-readdir.js b/test/sequential/test-readdir.js deleted file mode 100644 index 4987dc1..0000000 --- a/test/sequential/test-readdir.js +++ /dev/null @@ -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); - }); -})();