-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
ignore.spec.ts
95 lines (83 loc) · 2.64 KB
/
ignore.spec.ts
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { vol } from 'memfs';
import { createTree } from '../generators/testing-utils/create-tree';
import { Tree } from '../generators/tree';
import {
createCombinedIgnore,
createIgnore,
createIgnoreFromTree,
} from './ignore';
import { stripIndents } from './strip-indents';
jest.mock('fs', () => require('memfs').fs);
describe('createIgnore', () => {
afterEach(() => {
vol.reset();
});
it('should combine all ignore files in tree', () => {
vol.fromJSON(
{
'.ignore': 'a',
'b/.ignore': 'c',
},
'/root'
);
const ignore = createIgnore('/root', ['.ignore']);
expect(ignore.ignores('a')).toBe(true);
expect(ignore.ignores('b/c')).toBe(true);
});
});
describe('createIgnoreFromTree', () => {
let tree: Tree;
beforeEach(() => {
tree = createTree();
});
it('should combine all ignore files in tree', () => {
tree.write('.ignore', 'a');
tree.write('b/.ignore', 'c');
const ignore = createIgnoreFromTree(tree, ['.ignore']);
expect(ignore.ignores('a')).toBe(true);
expect(ignore.ignores('b/c')).toBe(true);
});
});
describe('createCombinedIgnore', () => {
it('should support ignore file at root', () => {
const ignore = createCombinedIgnore([{ path: '.ignore', content: 'b' }]);
expect(ignore.ignores('b')).toBe(true);
expect(ignore.ignores('c')).toBe(false);
});
it('should support ignoring root directory from file at root', () => {
const ignore = createCombinedIgnore([{ path: '.ignore', content: '/b' }]);
expect(ignore.ignores('b')).toBe(true);
expect(ignore.ignores('path/to/b')).toBe(false);
expect(ignore.ignores('c')).toBe(false);
});
it('should support nested ignore file', () => {
const ignore = createCombinedIgnore([{ path: 'a/.ignore', content: 'b' }]);
expect(ignore.ignores('a/b')).toBe(true);
expect(ignore.ignores('a/c')).toBe(false);
expect(ignore.ignores('d')).toBe(false);
});
it('should support ignore files at multiple levels', () => {
const ignore = createCombinedIgnore([
{ path: '.ignore', content: 'a' },
{ path: 'b/.ignore', content: 'c' },
]);
expect(ignore.ignores('a')).toBe(true);
expect(ignore.ignores('a/a')).toBe(true);
expect(ignore.ignores('a/c')).toBe(true);
expect(ignore.ignores('c')).toBe(false);
expect(ignore.ignores('b/d')).toBe(false);
});
it('should support negating rules', () => {
const ignore = createCombinedIgnore([
{
path: '.ignore',
content: stripIndents`
a*
!a
`,
},
]);
expect(ignore.ignores('aa')).toBe(true);
expect(ignore.ignores('a')).toBe(false);
});
});