mirror of https://github.com/lukechilds/node.git
Browse Source
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
10 changed files with 36 additions and 71 deletions
@ -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'); |
|||
})); |
@ -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…
Reference in new issue