-
-
Notifications
You must be signed in to change notification settings - Fork 412
/
generateTasks.spec.js
170 lines (157 loc) Β· 5.25 KB
/
generateTasks.spec.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import expect from 'expect'
import generateTasks from '../src/generateTasks'
const files = {
'test.js': '/root/test.js',
'deeper/test.js': '/root/deeper/test.js',
'deeper/test2.js': '/root/deeper/test2.js',
'even/deeper/test.js': '/root/even/deeper/test.js',
'.hidden/test.js': '/root/.hidden/test.js',
'test.css': '/root/test.css',
'deeper/test.css': '/root/deeper/test.css',
'deeper/test2.css': '/root/deeper/test2.css',
'even/deeper/test.css': '/root/even/deeper/test.css',
'.hidden/test.css': '/root/.hidden/test.css',
'test.txt': '/root/test.txt',
'deeper/test.txt': '/root/deeper/test.txt',
'deeper/test2.txt': '/root/deeper/test2.txt',
'even/deeper/test.txt': '/root/even/deeper/test.txt',
'.hidden/test.txt': '/root/.hidden/test.txt'
}
const linters = {
'*.js': 'root-js',
'**/*.js': 'any-js',
'deeper/*.js': 'deeper-js',
'.hidden/*.js': 'hidden-js',
'unknown/*.js': 'unknown-js',
'*.{css,js}': 'root-css-or-js'
}
describe('generateTasks', () => {
it('should work with simple configuration', () => {
const result = generateTasks({
'*.js': 'lint'
}, {
'test.js': '/root/test.js'
})
const commands = result.map(match => match.commands)
expect(commands).toEqual([
'lint'
])
})
it('should work with advanced configuration', () => {
const result = generateTasks({
gitDir: '../',
linters: {
'*.js': 'lint'
}
}, {
'test.js': '/root/test.js'
})
const commands = result.map(match => match.commands)
expect(commands).toEqual([
'lint'
])
})
it('should return an empty file list for linters with no matches.', () => {
const result = generateTasks(linters, files)
for (const task of result) {
if (task.commands === 'unknown-js') {
expect(task.fileList.length).toEqual(0)
} else {
expect(task.fileList.length).toNotEqual(0)
}
}
})
it('should match pattern "*.js"', () => {
const result = generateTasks(linters, files)
const linter = result.find(item => item.pattern === '*.js')
expect(linter).toEqual({
pattern: '*.js',
commands: 'root-js',
fileList: [
'/root/test.js',
'/root/deeper/test.js',
'/root/deeper/test2.js',
'/root/even/deeper/test.js',
'/root/.hidden/test.js'
]
})
})
it('should match pattern "**/*.js"', () => {
const result = generateTasks(linters, files)
const linter = result.find(item => item.pattern === '**/*.js')
expect(linter).toEqual({
pattern: '**/*.js',
commands: 'any-js',
fileList: [
'/root/test.js',
'/root/deeper/test.js',
'/root/deeper/test2.js',
'/root/even/deeper/test.js',
'/root/.hidden/test.js'
]
})
})
it('should match pattern "deeper/*.js"', () => {
const result = generateTasks(linters, files)
const linter = result.find(item => item.pattern === 'deeper/*.js')
expect(linter).toEqual({
pattern: 'deeper/*.js',
commands: 'deeper-js',
fileList: [
'/root/deeper/test.js',
'/root/deeper/test2.js'
]
})
})
it('should match pattern ".hidden/*.js"', () => {
const result = generateTasks(linters, files)
const linter = result.find(item => item.pattern === '.hidden/*.js')
expect(linter).toEqual({
pattern: '.hidden/*.js',
commands: 'hidden-js',
fileList: [
'/root/.hidden/test.js'
]
})
})
it('should match pattern "*.{css,js}"', () => {
const result = generateTasks(linters, files)
const linter = result.find(item => item.pattern === '*.{css,js}')
expect(linter).toEqual({
pattern: '*.{css,js}',
commands: 'root-css-or-js',
fileList: [
'/root/test.js',
'/root/deeper/test.js',
'/root/deeper/test2.js',
'/root/even/deeper/test.js',
'/root/.hidden/test.js',
'/root/test.css',
'/root/deeper/test.css',
'/root/deeper/test2.css',
'/root/even/deeper/test.css',
'/root/.hidden/test.css'
]
})
})
it('should support globOptions specified in advanced configuration', () => {
const result = generateTasks(
{
globOptions: {
matchBase: false,
nocase: true
},
linters: {
'TeSt.*': 'lint'
}
},
files
)
const linter = result.find(item => item.pattern === 'TeSt.*')
expect(linter).toEqual({
pattern: 'TeSt.*',
commands: 'lint',
fileList: ['/root/test.js', '/root/test.css', '/root/test.txt']
})
})
})