react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / node_modules / glob / test / nocase-nomagic.js
80713 viewsvar fs = require('fs');1var test = require('tap').test;2var glob = require('../');34test('mock fs', function(t) {5var stat = fs.stat6var statSync = fs.statSync7var readdir = fs.readdir8var readdirSync = fs.readdirSync910function fakeStat(path) {11var ret12switch (path.toLowerCase()) {13case '/tmp': case '/tmp/':14ret = { isDirectory: function() { return true } }15break16case '/tmp/a':17ret = { isDirectory: function() { return false } }18break19}20return ret21}2223fs.stat = function(path, cb) {24var f = fakeStat(path);25if (f) {26process.nextTick(function() {27cb(null, f)28})29} else {30stat.call(fs, path, cb)31}32}3334fs.statSync = function(path) {35return fakeStat(path) || statSync.call(fs, path)36}3738function fakeReaddir(path) {39var ret40switch (path.toLowerCase()) {41case '/tmp': case '/tmp/':42ret = [ 'a', 'A' ]43break44case '/':45ret = ['tmp', 'tMp', 'tMP', 'TMP']46}47return ret48}4950fs.readdir = function(path, cb) {51var f = fakeReaddir(path)52if (f)53process.nextTick(function() {54cb(null, f)55})56else57readdir.call(fs, path, cb)58}5960fs.readdirSync = function(path) {61return fakeReaddir(path) || readdirSync.call(fs, path)62}6364t.pass('mocked')65t.end()66})6768test('nocase, nomagic', function(t) {69var n = 270var want = [ '/TMP/A',71'/TMP/a',72'/tMP/A',73'/tMP/a',74'/tMp/A',75'/tMp/a',76'/tmp/A',77'/tmp/a' ]78glob('/tmp/a', { nocase: true }, function(er, res) {79if (er)80throw er81t.same(res.sort(), want)82if (--n === 0) t.end()83})84glob('/tmp/A', { nocase: true }, function(er, res) {85if (er)86throw er87t.same(res.sort(), want)88if (--n === 0) t.end()89})90})9192test('nocase, with some magic', function(t) {93t.plan(2)94var want = [ '/TMP/A',95'/TMP/a',96'/tMP/A',97'/tMP/a',98'/tMp/A',99'/tMp/a',100'/tmp/A',101'/tmp/a' ]102glob('/tmp/*', { nocase: true }, function(er, res) {103if (er)104throw er105t.same(res.sort(), want)106})107glob('/tmp/*', { nocase: true }, function(er, res) {108if (er)109throw er110t.same(res.sort(), want)111})112})113114115