/
ignore.js
executable file
路78 lines (65 loc) 路 1.44 KB
/
ignore.js
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
const {
test,
only
} = require('tap')
const ignore = require('..')
const {
cases,
checkEnv,
SHOULD_TEST_WINDOWS
} = require('./fixtures/cases')
const make_win32 = path => path.replace(/\//g, '\\')
cases(({
description,
patterns,
paths_object,
test_only,
paths,
expect_result
}) => {
const tt = test_only
? only
: test
checkEnv('IGNORE_ONLY_FILTER')
&& tt(`.filter(): ${description}`, t => {
const ig = ignore()
const result = ig
.addPattern(patterns)
.filter(paths)
expect_result(t, result)
t.end()
})
checkEnv('IGNORE_ONLY_CREATE_FILTER')
&& tt(`.createFilter(): ${description}`, t => {
const result = paths.filter(
ignore()
.addPattern(patterns)
.createFilter(),
// thisArg should be binded
null
)
expect_result(t, result)
t.end()
})
checkEnv('IGNORE_ONLY_IGNORES')
&& tt(`.ignores(path): ${description}`, t => {
const ig = ignore().addPattern(patterns)
Object.keys(paths_object).forEach(path => {
t.equal(ig.ignores(path), !!paths_object[path], `path: "${path}"`)
})
t.end()
})
if (!SHOULD_TEST_WINDOWS) {
return
}
checkEnv('IGNORE_ONLY_WIN32')
&& tt(`win32: .filter(): ${description}`, t => {
const win_paths = paths.map(make_win32)
const ig = ignore()
const result = ig
.addPattern(patterns)
.filter(win_paths)
expect_result(t, result, make_win32)
t.end()
})
})