Skip to content

Commit 0e33e7f

Browse files
committedNov 18, 2020
test: Add tests for makeDirectoryIterator()
1 parent 6896989 commit 0e33e7f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
 

‎test/makeDirectoryIterator.spec.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { makeDirectoryIterator } from '../src/lib/iac/makeDirectoryIterator';
2+
import * as path from 'path';
3+
4+
describe('makeDirectoryIterator', () => {
5+
const fixturePath = path.join(__dirname, 'fixtures/iac/depth_detection');
6+
7+
it('iterates over all files in the directory tree', () => {
8+
const it = makeDirectoryIterator(fixturePath);
9+
const result = Array.from(it);
10+
11+
expect(result).toEqual([
12+
expect.stringContaining('one.tf'),
13+
expect.stringContaining('five.tf'),
14+
expect.stringContaining('six.tf'),
15+
expect.stringContaining('four.tf'),
16+
expect.stringContaining('three.tf'),
17+
expect.stringContaining('two.tf'),
18+
expect.stringContaining('root.tf'),
19+
]);
20+
});
21+
22+
it('includes dotfiles when the includeDotfiles flag is provided', () => {
23+
const it = makeDirectoryIterator(fixturePath, { includeDotfiles: true });
24+
const result = Array.from(it);
25+
26+
expect(result).toEqual([
27+
expect.stringContaining('hidden.tf'),
28+
expect.stringContaining('.hidden.tf'),
29+
expect.stringContaining('one.tf'),
30+
expect.stringContaining('five.tf'),
31+
expect.stringContaining('six.tf'),
32+
expect.stringContaining('four.tf'),
33+
expect.stringContaining('three.tf'),
34+
expect.stringContaining('two.tf'),
35+
expect.stringContaining('root.tf'),
36+
]);
37+
});
38+
39+
it('limits the subdirectory depth when maxDepth option is provided', () => {
40+
const it = makeDirectoryIterator(fixturePath, { maxDepth: 3 });
41+
const result = Array.from(it);
42+
43+
expect(result).toEqual([
44+
expect.stringContaining('one.tf'),
45+
expect.stringContaining('two.tf'),
46+
expect.stringContaining('root.tf'),
47+
]);
48+
});
49+
50+
it('throws an error if the path provided is not a directory', () => {
51+
const it = makeDirectoryIterator('missing_path');
52+
expect(() => Array.from(it)).toThrowError();
53+
});
54+
});

0 commit comments

Comments
 (0)
Please sign in to comment.