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 27, 2015
1 parent 4c78e58 commit 253be9a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"devDependencies": {
"mkdirp": "0",
"mock-fs": "^2.6.0",
"rimraf": "^2.2.8",
"tap": "^0.5.0",
"tick": "0.0.6"
Expand Down
2 changes: 2 additions & 0 deletions test/bash-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"./node_modules/inherits",
"./node_modules/minimatch",
"./node_modules/mkdirp",
"./node_modules/mock-fs",
"./node_modules/once",
"./node_modules/path-is-absolute",
"./node_modules/rimraf",
Expand Down Expand Up @@ -119,6 +120,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
58 changes: 58 additions & 0 deletions test/unc-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var test = require('tap').test;
var glob = require('../');
var fs = require('fs');
var mock = require('mock-fs');

test('glob doesn\'t choke on UNC paths', function(t) {
stubPlatform('win32', function(restorePlatform) {
mock({
'\\vmware-share\\share-name\\baz': {
'some-file.txt': 'content 1',
'some-other-file.txt': 'content 2'
}
});

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 sep = path.sep;
var resolve = path.resolve;

function restore() {
path.resolve = resolve;
path.sep = sep;
Object.defineProperty(process, 'platform', descriptor);
}

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

path.sep = '\\';
path.resolve = path[platform].resolve;

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

0 comments on commit 253be9a

Please sign in to comment.