Skip to content

Commit

Permalink
Merge pull request #20 from kellyselden/posix-path
Browse files Browse the repository at this point in the history
added tests that work in Windows CI
  • Loading branch information
joliss committed Nov 11, 2015
2 parents 0423373 + 6b9d030 commit d9fd7b9
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ function walkSync(baseDir, _options) {
module.exports.entries = function entries(baseDir, _options) {
var options = handleOptions(_options);


return _walkSync(ensurePosix(baseDir), options);
};

Expand Down
70 changes: 70 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var path = require('path');
var tap = require('tap');
var test = tap.test;
var walkSync = require('../');
Expand All @@ -25,6 +26,22 @@ tap.Test.prototype.addAssert('matchThrows', 2, function(fn, expectedError) {
symlink('./some-other-dir', 'test/fixtures/symlink1');
symlink('doesnotexist', 'test/fixtures/symlink2', true);

// this allows us to call walkSync with fixed path separators,
// but CI will use it's native format (Windows testing).
// we can't duplicate our tests hardcoding windows paths
// because walkSync checks path.sep, not your supplied path format
var oldWalkSync = walkSync;
function normalizeArgs(args) {
var baseDir = path.normalize(args[0]);
return [baseDir].concat(Array.prototype.slice.call(args, 1));
}
walkSync = function() {
return oldWalkSync.apply(this, normalizeArgs(arguments));
};
walkSync.entries = function() {
return oldWalkSync.entries.apply(this, normalizeArgs(arguments));
};

test('walkSync', function (t) {
t.deepEqual(walkSync('test/fixtures'), [
'dir/',
Expand Down Expand Up @@ -63,6 +80,59 @@ function appearsAsDir(entry) {

test('entries', function (t) {
function expectAllEntries(array) {
t.deepEqual(array.map(function(entry) {
return {
basePath: entry.basePath,
fullPath: entry.fullPath
};
}),
[
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/dir/'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/dir/bar.txt'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/dir/subdir/'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/dir/subdir/baz.txt'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/dir/zzz.txt'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/foo.txt'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/some-other-dir/'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/some-other-dir/qux.txt'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/symlink1/'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/symlink1/qux.txt'
},
{
basePath: 'test/fixtures',
fullPath: 'test/fixtures/symlink2'
}
]);

array.forEach(function(entry) {
if (entry.relativePath === 'symlink2') {
t.assert(!entry.isDirectory());
Expand Down

0 comments on commit d9fd7b9

Please sign in to comment.