-
-
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.
- Loading branch information
Showing
4 changed files
with
89 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
sandbox.js | ||
.nyc_output |
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 |
---|---|---|
@@ -1,94 +1,92 @@ | ||
const tape = require('tape'); | ||
const ptape = require('tape-promise').default; | ||
const { asyncFolderWalker, allFiles } = require('.'); | ||
const path = require('path'); | ||
const tmp = require('p-temporary-directory'); | ||
const test = ptape(tape); | ||
const tap = require('tap') | ||
const { asyncFolderWalker, allFiles } = require('.') | ||
const path = require('path') | ||
const tmp = require('p-temporary-directory') | ||
|
||
const fixtures = path.join(__dirname, 'fixtures'); | ||
const fixtures = path.join(__dirname, 'fixtures') | ||
|
||
test('for of multiple folders', async t => { | ||
tap.test('for of multiple folders', async t => { | ||
for await (const file of asyncFolderWalker([ | ||
path.join(fixtures, 'sub-folder'), | ||
path.join(fixtures, 'another-folder') | ||
])) { | ||
t.ok(file, file); | ||
t.ok(file, file) | ||
} | ||
}); | ||
}) | ||
|
||
test('Array from async iterator', async t => { | ||
tap.test('Array from async iterator', async t => { | ||
const files = await allFiles([ | ||
path.join(fixtures, 'sub-folder'), | ||
path.join(fixtures, 'another-folder') | ||
]); | ||
t.equal(files.length, 4, 'expected number of files are found'); | ||
}); | ||
]) | ||
t.equal(files.length, 4, 'expected number of files are found') | ||
}) | ||
|
||
test('No args', async t => { | ||
tap.test('No args', async t => { | ||
for await (const file of asyncFolderWalker()) { | ||
t.fail(file, 'no files should be found!'); | ||
t.fail(file, 'no files should be found!') | ||
} | ||
t.pass('for of executed'); | ||
}); | ||
t.pass('for of executed') | ||
}) | ||
|
||
test('No folders', async t => { | ||
const [dir, cleanup] = await tmp(); | ||
tap.test('No folders', async t => { | ||
const [dir, cleanup] = await tmp() | ||
try { | ||
for await (const file of asyncFolderWalker(dir)) { | ||
t.fail(file, 'no files should be found!'); | ||
t.fail(file, 'no files should be found!') | ||
} | ||
t.pass('for of executed'); | ||
t.pass('for of executed') | ||
} finally { | ||
await cleanup(); | ||
await cleanup() | ||
} | ||
}); | ||
}) | ||
|
||
test('When you just pass a file', async t => { | ||
const [dir, cleanup] = await tmp(); | ||
tap.test('When you just pass a file', async t => { | ||
const [dir, cleanup] = await tmp() | ||
try { | ||
const theFile = path.join(fixtures, 'test.json'); | ||
const files = await allFiles([theFile, dir]); | ||
t.equal(files.length, 1, 'only one file is found'); | ||
t.equal(theFile, files[0], 'only one file is found'); | ||
const theFile = path.join(fixtures, 'test.json') | ||
const files = await allFiles([theFile, dir]) | ||
t.equal(files.length, 1, 'only one file is found') | ||
t.equal(theFile, files[0], 'only one file is found') | ||
} finally { | ||
await cleanup(); | ||
await cleanup() | ||
} | ||
}); | ||
}) | ||
|
||
test('pathFilter works', async t => { | ||
const filterStrig = 'sub-folder'; | ||
tap.test('pathFilter works', async t => { | ||
const filterStrig = 'sub-folder' | ||
const files = await allFiles(fixtures, { | ||
pathFilter: p => !p.includes(filterStrig) | ||
}); | ||
}) | ||
|
||
t.false(files.some(f => f.includes(filterStrig)), 'No paths include the excluded string'); | ||
}); | ||
t.false(files.some(f => f.includes(filterStrig)), 'No paths include the excluded string') | ||
}) | ||
|
||
test('statFilter works', async t => { | ||
tap.test('statFilter works', async t => { | ||
const stats = await allFiles(fixtures, { | ||
statFilter: st => !st.isDirectory(), // Exclude files | ||
shaper: ({ root, filepath, stat, relname, basename }) => stat // Lets get the stats instead of paths | ||
}); | ||
}) | ||
|
||
for (const st of stats) { | ||
t.false(st.isDirectory(), 'none of the files are directories'); | ||
t.false(st.isDirectory(), 'none of the files are directories') | ||
} | ||
}); | ||
}) | ||
|
||
test('dont include root directory in response', async (t) => { | ||
const root = process.cwd(); | ||
tap.test('dont include root directory in response', async (t) => { | ||
const root = process.cwd() | ||
for await (const file of asyncFolderWalker(root)) { | ||
if (file === root) t.fail('root directory should not be in results'); | ||
if (file === root) t.fail('root directory should not be in results') | ||
} | ||
t.pass('The root was not included in results.'); | ||
}); | ||
t.pass('The root was not included in results.') | ||
}) | ||
|
||
test('dont walk past the maxDepth', async t => { | ||
const maxDepth = 3; | ||
const walker = asyncFolderWalker(['.git', 'node_modules'], { maxDepth }); | ||
tap.test('dont walk past the maxDepth', async t => { | ||
const maxDepth = 3 | ||
const walker = asyncFolderWalker(['.git', 'node_modules'], { maxDepth }) | ||
for await (const file of walker) { | ||
const correctLength = file.split(path.sep).length - process.cwd().split(path.sep).length <= maxDepth; | ||
if (!correctLength) t.fail('walker walked past the depth it was supposed to'); | ||
const correctLength = file.split(path.sep).length - process.cwd().split(path.sep).length <= maxDepth | ||
if (!correctLength) t.fail('walker walked past the depth it was supposed to') | ||
} | ||
t.pass('Walker was depth limited'); | ||
}); | ||
t.pass('Walker was depth limited') | ||
}) |