Repository navigation
Expand file tree
/
Copy pathutils.test.ts
More file actions
53 lines (45 loc) · 1.52 KB
/
Copy pathutils.test.ts
File metadata and controls
53 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { deepReadDirSync } from '../src/utils';
// The parent directory for the new temporary directory
describe('deepReadDirSync', () => {
it('handles nested files', () => {
const expected = [
// root level
'debra.txt',
// one level deep
'cats/eddy.txt',
'cats/persephone.txt',
'cats/piper.txt',
'cats/sassafras.txt',
'cats/teaberry.txt',
// two levels deep
'dogs/theBigs/charlie.txt',
'dogs/theBigs/maisey.txt',
'dogs/theSmalls/bodhi.txt',
'dogs/theSmalls/cory.txt',
].map(p => (process.platform === 'win32' ? p.replace(/\//g, '\\') : p));
// compare sets so that order doesn't matter
expect(new Set(deepReadDirSync('./test/fixtures/testDeepReadDirSync'))).toEqual(new Set(expected));
});
it('handles empty target directory', (done: (error?: Error) => void) => {
expect.assertions(1);
const tmpDir = os.tmpdir();
fs.mkdtemp(`${tmpDir}${path.sep}`, (err, dirPath) => {
if (err) throw err;
try {
expect(deepReadDirSync(dirPath)).toEqual([]);
done();
} catch (error) {
done(error);
}
});
});
it('errors if directory does not exist', () => {
expect(() => deepReadDirSync('./IDontExist')).toThrowError('Directory does not exist.');
});
it('errors if given path is not a directory', () => {
expect(() => deepReadDirSync('package.json')).toThrowError('it is not a directory');
});
});