-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreateFilePathFilter.spec.ts
More file actions
77 lines (63 loc) · 2.48 KB
/
createFilePathFilter.spec.ts
File metadata and controls
77 lines (63 loc) · 2.48 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { createFilePathFilter } from './createFilePathFilter';
import { isMatch } from 'micromatch';
describe('createFilePathFilter', () => {
it('options empty', () => {
const fileList = ['abc/def/abc.ts', 'abc', 'def.js', 'readme.md', ''] as const;
const r = createFilePathFilter();
expect(fileList.filter(d => r(d)).length).toBe(fileList.length);
});
it('options.extensions', () => {
const fileList = ['abc/def/abc.ts', 'abc', 'def.js', 'readme.md', '', null, '\0abc.ts'] as const;
const r = createFilePathFilter({
extensions: ['ts', '.abc'],
});
expect(r(fileList[0])).toBeTruthy();
expect(r(fileList[1])).toBeFalsy();
expect(r(fileList[2])).toBeFalsy();
expect(fileList.filter(d => r(d)).length === 1).toBeTruthy();
});
it('options.include', () => {
const fileList = ['abc/def/abc.ts', 'abc', 'def.js', 'readme.md', ''] as const;
const r = createFilePathFilter({
include: ['abc'],
});
expect(r(fileList[0])).toBeTruthy();
expect(r(fileList[1])).toBeTruthy();
expect(r(fileList[2])).toBeFalsy();
});
it('options.exclude', () => {
const fileList = ['abc/def/abc.ts', 'abc', 'def.js', 'readme.md', ''] as const;
const r = createFilePathFilter({
exclude: ['abc'],
});
expect(r(fileList[0])).toBeFalsy();
expect(r(fileList[1])).toBeFalsy();
expect(r(fileList[2])).toBeTruthy();
});
it('options.globMatcher.include', () => {
const fileList = ['abc/def/abc.ts', 'abc', 'def.js', 'readme.md', ''] as const;
const r = createFilePathFilter({
include: ['**/*.{ts,js}'],
resolve: false,
globMatcher: (pathId, ruleIdNormalized) => isMatch(pathId, ruleIdNormalized, { dot: true }),
});
expect(r(fileList[0])).toBeTruthy();
expect(r(fileList[1])).toBeFalsy();
expect(r(fileList[2])).toBeTruthy();
expect(r(fileList[3])).toBeFalsy();
});
it('options.globMatcher.exclude', () => {
const fileList = ['abc/def/abc.ts', 'abc', 'def.js', 'readme.md', '/abcd'] as const;
const r = createFilePathFilter({
exclude: ['**/*.{ts,js}', /\.ts$/],
resolve: process.cwd(),
globMatcher: (pathId, ruleIdNormalized) => isMatch(pathId, ruleIdNormalized, { dot: true }),
});
expect(r(fileList[0])).toBeFalsy();
expect(r(fileList[1])).toBeTruthy();
expect(r(fileList[2])).toBeFalsy();
expect(r(fileList[3])).toBeTruthy();
expect(fileList.filter(d => r(d)).length > 1).toBeTruthy();
expect(r('/abc/def.ts')).toBeFalsy();
});
});