forked from isaacs/node-glob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom fs adapter to be passed as option (isaacs#280)
- Loading branch information
1 parent
98327d8
commit 551f67a
Showing
4 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require("./global-leakage.js") | ||
|
||
var fs = require('fs') | ||
var test = require('tap').test | ||
var glob = require('../') | ||
|
||
// pattern to (potentially) trigger all fs calls | ||
var pattern = 'a/symlink/**/c' | ||
|
||
// on win32, the fixtures will not include symlink, so use a different pattern | ||
// and adjust expectations of stat being called | ||
var win32 = process.platform === 'win32' | ||
if (win32) | ||
pattern = 'a/bc/**/f' | ||
|
||
|
||
// [ expected calls ] | ||
var cases = [ | ||
// all adapter functions are called for our pattern, excepting stat on win32 | ||
{ readdir: true, stat: !win32, lstat: true, realpath: true }, | ||
|
||
// realpath isn't called if adapter doesn't have it | ||
{ readdir: true, stat: !win32, lstat: true }, | ||
|
||
// stat is called instead of lstat if adapter doesn't have lstat | ||
{ readdir: true, stat: true } | ||
] | ||
|
||
|
||
process.chdir(__dirname + '/fixtures') | ||
|
||
|
||
cases.forEach(function(exp, i) { | ||
test('custom fs ' + i + ' ' + JSON.stringify(exp), function(t) { | ||
var fns = Object.keys(exp) | ||
var opt = { realpath: true } | ||
var spy = {} | ||
|
||
opt.fs = {} | ||
fns.forEach(function(fn) { | ||
opt.fs[fn] = function() { | ||
spy[fn] = true | ||
return fs[fn].apply(null, [].slice.call(arguments, 0)) | ||
} | ||
spy[fn] = false | ||
}) | ||
|
||
glob(pattern, opt, function(err) { | ||
t.ok(!err, 'expect no error') | ||
fns.forEach(function(fn) { | ||
t.ok(spy[fn] === exp[fn], 'expect ' + fn + ' called: ' + exp[fn]) | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
}) |