Skip to content

Commit

Permalink
UNC path integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Apr 28, 2015
1 parent 4c78e58 commit 2ec5321
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/bash-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"./test/slash-cwd.js",
"./test/stat.js",
"./test/sync-cb-throw.js",
"./test/unc-path.js",
"./test/win-path.js",
"./test/zz-cleanup.js",
"/tmp/glob-test/asdf",
Expand Down
71 changes: 71 additions & 0 deletions test/unc-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var test = require('tap').test;
var glob = require('../');
var fs = require('fs');
var path = require('path');

test('glob doesn\'t choke on UNC paths', function(t) {
stubPlatform('win32', function(restorePlatform) {
var readdir = fs.readdir;

fs.readdir = function(path, cb) {
if (path === '\\\\vmware-share\\share-name\\baz') {
return cb(undefined, [
'some-file.txt',
'some-other-file.txt'
])
}

readdir(path, cb)
}

var results = glob('\\\\vmware-share\\share-name\\baz\\*', function (er, results) {
restorePlatform();

if (er)
throw er

t.same(results, [
'\\\\vmware-share\\share-name\\baz\\some-file.txt',
'\\\\vmware-share\\share-name\\baz\\some-other-file.txt'
])

t.end()
})
})
})

function stubPlatform(platform, fn) {
var descriptor = Object.getOwnPropertyDescriptor(process, 'platform')
var path = require('path');
var join = path.join;
var normalize = path.normalize;
var sep = path.sep;
var resolve = path.resolve;
var isAbsolute = require('path-is-absolute');

function restore() {
path.resolve = resolve;
path.sep = sep;
path.join = join;
path.normalize = normalize;
var isAbsolute = require('path-is-absolute');
Object.defineProperty(process, 'platform', descriptor);
}

try {
Object.defineProperty(process, 'platform', {
value: platform,
writable: false
});

path.sep = '\\';
path.resolve = path[platform].resolve;
path.join = path.win32.join;
path.normalize = path.win32.normalize;

return fn(restore);
} catch(e) {
restore();
throw e;
}
}

0 comments on commit 2ec5321

Please sign in to comment.