diff --git a/glob.js b/glob.js index 54a83871..7401e0b7 100644 --- a/glob.js +++ b/glob.js @@ -50,6 +50,7 @@ var assert = require('assert') var globSync = require('./sync.js') var common = require('./common.js') var alphasort = common.alphasort +var alphasorti = common.alphasorti var isAbsolute = common.isAbsolute var setopts = common.setopts var ownProp = common.ownProp @@ -449,7 +450,7 @@ function readdirCb (self, abs, cb) { if (er) self._readdirError(abs, er, cb) else - self._readdirEntries(abs, entries.sort(alphasort), cb) + self._readdirEntries(abs, entries, cb) } } diff --git a/sync.js b/sync.js index d4688a41..f981055a 100644 --- a/sync.js +++ b/sync.js @@ -10,6 +10,7 @@ var path = require('path') var assert = require('assert') var common = require('./common.js') var alphasort = common.alphasort +var alphasorti = common.alphasorti var isAbsolute = common.isAbsolute var setopts = common.setopts var ownProp = common.ownProp @@ -235,7 +236,7 @@ GlobSync.prototype._readdir = function (abs, inGlobStar) { } try { - return this._readdirEntries(abs, fs.readdirSync(abs).sort(alphasort)) + return this._readdirEntries(abs, fs.readdirSync(abs)) } catch (er) { this._readdirError(abs, er) return null diff --git a/test/bash-results.json b/test/bash-results.json index ee312d67..2eceb1b2 100644 --- a/test/bash-results.json +++ b/test/bash-results.json @@ -108,7 +108,6 @@ "./test/nocase-nomagic.js", "./test/nodir.js", "./test/pause-resume.js", - "./test/readdir-order.js", "./test/readme-issue.js", "./test/root-nomount.js", "./test/root.js", diff --git a/test/readdir-order.js b/test/readdir-order.js deleted file mode 100644 index 045bee24..00000000 --- a/test/readdir-order.js +++ /dev/null @@ -1,65 +0,0 @@ -// Make sure that we get consistent results, even if fs.readdir -// returns entries in a different order. -require("./global-leakage.js") -var Glob = require("../glob.js").Glob -var test = require('tap').test -var fs = require('fs') - -var matches = [] - -test('get globstar matches', function(t) { - var pattern = 'a/*/[gh]' - var g = new Glob(pattern, { cwd: __dirname }) - g.on('match', function(m) { - matches.push(m) - }) - g.on('end', function(set) { - var sortedMatches = matches.slice(0).sort() - set = set.sort() - t.same(sortedMatches, set, 'should have same set of matches') - t.end() - }) -}) - -test('shuffle fs.readdir', function (t) { - // just reverse them, since shuffle is non-deterministic - function shuffle(entries) { - return entries.sort(rand) - } - function rand(a, b) { - return a > b ? -1 : 1 - } - - fs.readdir = function (orig) { return function (path, cb) { - orig(path, function (er, entries) { - if (entries) - shuffle(entries) - cb(er, entries) - }) - }}(fs.readdir) - - fs.readdirSync = function (orig) { return function (path) { - return shuffle(orig(path)) - }}(fs.readdirSync) - - // make sure it works - var d = __dirname + '/a' - t.notSame(fs.readdirSync(d), fs.readdirSync(d).sort()) - fs.readdir(__dirname + '/a', function (er, entries) { - t.notSame(entries.slice(0), entries.sort()) - t.end() - }) -}) - -test('same match events with shuffled readdir', function (t) { - var pattern = 'a/*/[gh]' - var g = new Glob(pattern, { cwd: __dirname }) - var shuffleMatches = [] - g.on('match', function(m) { - shuffleMatches.push(m) - }) - g.on('end', function(set) { - t.same(shuffleMatches, matches, 'should have same set of matches') - t.end() - }) -})