1 | import fs from 'fs';
|
2 | import path from 'path';
|
3 | import test from 'ava';
|
4 | import async from 'async';
|
5 | import fn from './';
|
6 |
|
7 | test.cb('fn accepts valid path to contents', t => {
|
8 | fn(__dirname, 'directory', (err, dirs) => {
|
9 | t.is(err, null);
|
10 | t.deepEqual(dirs, ['.git', 'node_modules']);
|
11 | t.end();
|
12 | })
|
13 | })
|
14 |
|
15 | test.cb('fn returns array of items only of `type`', t => {
|
16 | fn(__dirname, 'file', (err, files) => {
|
17 | t.ifError(err);
|
18 |
|
19 | async.every(files, (file, cb) => {
|
20 | fs.stat(path.join(__dirname, file), (err, stats) => {
|
21 | if (err) return cb(err);
|
22 |
|
23 | cb(null, stats.isFile());
|
24 | })
|
25 | }, (err, p) => {
|
26 | t.ifError(err);
|
27 | t.is(p, true);
|
28 | t.end();
|
29 | })
|
30 | })
|
31 | })
|
32 |
|
33 | test.cb('fn returns empty array when no items of `type` in `ptc`', t => {
|
34 | fn(__dirname, 'symbolicLink', (err, symLinks) => {
|
35 | t.is(err, null);
|
36 | t.deepEqual(symLinks, []);
|
37 | t.end();
|
38 | })
|
39 | })
|
40 |
|
41 | test.cb('fn rejects invalid path to contents', t => {
|
42 | const pathTo = path.join(__dirname, 'x');
|
43 |
|
44 | fn(pathTo, 'file', (err, result) => {
|
45 | t.is(err.message, `${pathTo} is not a valid path\n`);
|
46 | t.end();
|
47 | })
|
48 | })
|