|
1 | | -var path = require('path'), |
2 | | - should = require('should'), |
3 | | - dir = require('..'), |
4 | | - fixturesDir = path.join(__dirname, 'fixtures'), |
5 | | - tdir = path.join(fixturesDir, 'testdir'), |
6 | | - tdir2 = path.join(fixturesDir, 'testdir2'), |
7 | | - tdir3 = path.join(fixturesDir, 'testdir3'), |
8 | | - tdir4 = path.join(fixturesDir, 'testdir4'), |
9 | | - tdir5 = path.join(fixturesDir, 'testdir5'), |
10 | | - tdir6 = path.join(fixturesDir, 'testdir6'), |
11 | | - assert = require('assert'), |
12 | | - isWin = require('os').type()=='Windows_NT', |
13 | | - winIt = isWin ? it.skip : it//skip all symlink based testing |
14 | | - |
15 | | -//create empty folder |
16 | | -require('fs').mkdirSync( tdir6 ) |
| 1 | +var fs = require('fs') |
| 2 | +var path = require('path') |
| 3 | +var should = require('should') |
| 4 | +var dir = require('..') |
| 5 | +var fixturesDir = path.join(__dirname, 'fixtures') |
| 6 | + |
| 7 | +var tdir = path.join(fixturesDir, 'testdir') |
| 8 | +var tdir2 = path.join(fixturesDir, 'testdir2') |
| 9 | +var tdir3 = path.join(fixturesDir, 'testdir3') |
| 10 | +var tdir4 = path.join(fixturesDir, 'testdir4') |
| 11 | +var tdir5 = path.join(fixturesDir, 'testdir5') |
| 12 | +//empty dirs that may not exist |
| 13 | +var tdir6 = path.join(fixturesDir, 'testdir6') |
| 14 | +var tdir7 = path.join(fixturesDir, 'testdir7') |
| 15 | +var tdir8 = path.join(fixturesDir, 'testdir7', 'testdir8') |
| 16 | + |
| 17 | +var assert = require('assert') |
| 18 | +var isWin = require('os').type()=='Windows_NT' |
| 19 | +var winIt = isWin ? it.skip : it//skip all symlink based testing |
| 20 | + |
| 21 | +//param empty folder |
| 22 | +function paramDir(pathTo){ |
| 23 | + try{ |
| 24 | + fs.mkdirSync( pathTo ) |
| 25 | + }catch(e){ |
| 26 | + if( !e.code || e.code!='EEXIST' ){ |
| 27 | + throw e |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +paramDir( tdir6 ) |
| 33 | +paramDir( tdir7 ) |
| 34 | +paramDir( tdir8 ) |
17 | 35 |
|
18 | 36 | describe('readfiles method', function() { |
19 | 37 |
|
@@ -1266,28 +1284,42 @@ describe("files method", function() { |
1266 | 1284 | relFile.should.eql(cmp)//This test does not pass on all Systems |
1267 | 1285 | }); |
1268 | 1286 |
|
1269 | | - it("empty-folder", function() { |
1270 | | - var files = dir.files(tdir6,'file', function(){}, {sync:true, excludeHidden:true}); |
1271 | | - assert.equal(files.length, 0) |
1272 | | - }); |
1273 | | - |
1274 | | - it("empty-folder-promise", function(done) { |
1275 | | - dir.promiseFiles(tdir6,'file', {excludeHidden:true}) |
1276 | | - .then(function(files){ |
1277 | | - assert.equal(files.length, 0) |
| 1287 | + describe('empty-folders',function(){ |
| 1288 | + it("empty-folder", function() { |
| 1289 | + var files = dir.files(tdir6,'file', function(){}, {sync:true, excludeHidden:true}); |
| 1290 | + assert.equal(files.length, 0) |
1278 | 1291 | }) |
1279 | | - .then(done).catch(done) |
1280 | | - }); |
1281 | 1292 |
|
1282 | | - it("empty-folder-callback", function(done) { |
1283 | | - dir.files(tdir6,'file', function(err,files){ |
1284 | | - if(err)return done(err) |
| 1293 | + it("folder-with-folder-only", function() { |
| 1294 | + var files = dir.files(tdir7,'file', function(){}, {sync:true, excludeHidden:true}); |
1285 | 1295 | assert.equal(files.length, 0) |
1286 | | - done() |
1287 | | - }, {excludeHidden:true}) |
1288 | | - }); |
1289 | | -}); |
| 1296 | + }) |
| 1297 | + |
| 1298 | + it("folder-with-folder-only-promise", function(done) { |
| 1299 | + dir.promiseFiles(tdir7,'file', {excludeHidden:true}) |
| 1300 | + .then(function(files){ |
| 1301 | + assert.equal(files.length, 0) |
| 1302 | + }) |
| 1303 | + .then(done).catch(done) |
| 1304 | + }) |
| 1305 | + |
| 1306 | + it("empty-folder-promise", function(done) { |
| 1307 | + dir.promiseFiles(tdir6,'file', {excludeHidden:true}) |
| 1308 | + .then(function(files){ |
| 1309 | + assert.equal(files.length, 0) |
| 1310 | + }) |
| 1311 | + .then(done).catch(done) |
| 1312 | + }) |
1290 | 1313 |
|
| 1314 | + it("empty-folder-callback", function(done) { |
| 1315 | + dir.files(tdir6,'file', function(err,files){ |
| 1316 | + if(err)return done(err) |
| 1317 | + assert.equal(files.length, 0) |
| 1318 | + done() |
| 1319 | + }, {excludeHidden:true}) |
| 1320 | + }) |
| 1321 | + }) |
| 1322 | +}) |
1291 | 1323 |
|
1292 | 1324 | describe('subdirs method', function() { |
1293 | 1325 | it('should pass an array of the subdir paths of every subdir in a directory (recursive) to a callback', function(done) { |
|
0 commit comments