1 var fs = require('graceful-fs');
2 var test = require('tap').test;
3 var glob = require('../');
5 test('mock fs', function(t) {
7 var statSync = fs.statSync
8 var readdir = fs.readdir
9 var readdirSync = fs.readdirSync
11 function fakeStat(path) {
13 switch (path.toLowerCase()) {
14 case '/tmp': case '/tmp/':
15 ret = { isDirectory: function() { return true } }
18 ret = { isDirectory: function() { return false } }
24 fs.stat = function(path, cb) {
25 var f = fakeStat(path);
27 process.nextTick(function() {
31 stat.call(fs, path, cb)
35 fs.statSync = function(path) {
36 return fakeStat(path) || statSync.call(fs, path)
39 function fakeReaddir(path) {
41 switch (path.toLowerCase()) {
42 case '/tmp': case '/tmp/':
46 ret = ['tmp', 'tMp', 'tMP', 'TMP']
51 fs.readdir = function(path, cb) {
52 var f = fakeReaddir(path)
54 process.nextTick(function() {
58 readdir.call(fs, path, cb)
61 fs.readdirSync = function(path) {
62 return fakeReaddir(path) || readdirSync.call(fs, path)
69 test('nocase, nomagic', function(t) {
71 var want = [ '/TMP/A',
79 glob('/tmp/a', { nocase: true }, function(er, res) {
82 t.same(res.sort(), want)
83 if (--n === 0) t.end()
85 glob('/tmp/A', { nocase: true }, function(er, res) {
88 t.same(res.sort(), want)
89 if (--n === 0) t.end()
93 test('nocase, with some magic', function(t) {
95 var want = [ '/TMP/A',
103 glob('/tmp/*', { nocase: true }, function(er, res) {
106 t.same(res.sort(), want)
108 glob('/tmp/*', { nocase: true }, function(er, res) {
111 t.same(res.sort(), want)