Skip to content

Commit b03f082

Browse files
committed
test: add unit cases on Windows for folder-match-with-fex rule
1 parent 6ec6605 commit b03f082

File tree

1 file changed

+309
-0
lines changed

1 file changed

+309
-0
lines changed
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
/**
2+
* @file The folder should match the naming pattern specified by the file extension
3+
* @author Duke Luo
4+
*/
5+
'use strict';
6+
7+
const path = require('path');
8+
const proxyquire = require('proxyquire');
9+
const RuleTester = require('eslint').RuleTester;
10+
11+
const rule = proxyquire('../../../lib/rules/folder-match-with-fex', {
12+
path: { ...path.win32, '@global': true },
13+
});
14+
const ruleTester = new RuleTester();
15+
16+
ruleTester.run(
17+
"folder-match-with-fex with option on Windows: [{ '*.js': '**/__tests__/' }]",
18+
rule,
19+
{
20+
valid: [
21+
{
22+
code: "var foo = 'bar';",
23+
filename: 'C:\\__tests__\\foo.test.js',
24+
options: [{ '*.js': '**/__tests__/' }],
25+
},
26+
{
27+
code: "var foo = 'bar';",
28+
filename: '__tests__\\foo.test.js',
29+
options: [{ '*.js': '**/__tests__/' }],
30+
},
31+
{
32+
code: "var foo = 'bar';",
33+
filename: 'bar\\__tests__\\foo.test.js',
34+
options: [{ '*.js': '**/__tests__/' }],
35+
},
36+
{
37+
code: "var foo = 'bar';",
38+
filename: 'C:\\bar\\__tests__\\foo.test.js',
39+
options: [{ '*.js': '**/__tests__/' }],
40+
},
41+
],
42+
43+
invalid: [
44+
{
45+
code: "var foo = 'bar';",
46+
filename: 'C:\\bar\\__test__\\foo.test.js',
47+
options: [{ '*.js': '**/__tests__/' }],
48+
errors: [
49+
{
50+
message:
51+
'The folder of the file "bar/__test__/foo.test.js" does not match "**/__tests__/"',
52+
column: 1,
53+
line: 1,
54+
},
55+
],
56+
},
57+
],
58+
}
59+
);
60+
61+
ruleTester.run(
62+
"folder-match-with-fex with option on Windows: [{ '*.js': '*/__tests__/' }]",
63+
rule,
64+
{
65+
valid: [
66+
{
67+
code: "var foo = 'bar';",
68+
filename: 'bar\\__tests__\\foo.test.js',
69+
options: [{ '*.js': '*/__tests__/' }],
70+
},
71+
],
72+
73+
invalid: [
74+
{
75+
code: "var foo = 'bar';",
76+
filename: 'C:\\__tests__\\foo.test.js',
77+
options: [{ '*.js': '*/__tests__/' }],
78+
errors: [
79+
{
80+
message:
81+
'The folder of the file "__tests__/foo.test.js" does not match "*/__tests__/"',
82+
column: 1,
83+
line: 1,
84+
},
85+
],
86+
},
87+
{
88+
code: "var foo = 'bar';",
89+
filename: 'C:\\__test__\\foo.test.js',
90+
options: [{ '*.js': '*/__tests__/' }],
91+
errors: [
92+
{
93+
message:
94+
'The folder of the file "__test__/foo.test.js" does not match "*/__tests__/"',
95+
column: 1,
96+
line: 1,
97+
},
98+
],
99+
},
100+
{
101+
code: "var foo = 'bar';",
102+
filename: '__tests__\\foo.test.js',
103+
options: [{ '*.js': '*/__tests__/' }],
104+
errors: [
105+
{
106+
message:
107+
'The folder of the file "__tests__/foo.test.js" does not match "*/__tests__/"',
108+
column: 1,
109+
line: 1,
110+
},
111+
],
112+
},
113+
],
114+
}
115+
);
116+
117+
ruleTester.run(
118+
"folder-match-with-fex with option on Windows: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }]",
119+
rule,
120+
{
121+
valid: [
122+
{
123+
code: "var foo = 'bar';",
124+
filename: 'bar\\__tests__\\foo.test.js',
125+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
126+
},
127+
{
128+
code: "var foo = 'bar';",
129+
filename: 'bar\\__tests__\\foo.test.jsx',
130+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
131+
},
132+
{
133+
code: "var foo = 'bar';",
134+
filename: 'bar\\__tests__\\foo.test.ts',
135+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
136+
},
137+
{
138+
code: "var foo = 'bar';",
139+
filename: 'bar\\__tests__\\foo.test.tsx',
140+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
141+
},
142+
],
143+
144+
invalid: [
145+
{
146+
code: "var foo = 'bar';",
147+
filename: 'bar\\_tests_\\foo.test.js',
148+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
149+
errors: [
150+
{
151+
message:
152+
'The folder of the file "bar/_tests_/foo.test.js" does not match "*/__tests__/"',
153+
column: 1,
154+
line: 1,
155+
},
156+
],
157+
},
158+
{
159+
code: "var foo = 'bar';",
160+
filename: 'bar\\_tests_\\foo.test.jsx',
161+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
162+
errors: [
163+
{
164+
message:
165+
'The folder of the file "bar/_tests_/foo.test.jsx" does not match "*/__tests__/"',
166+
column: 1,
167+
line: 1,
168+
},
169+
],
170+
},
171+
{
172+
code: "var foo = 'bar';",
173+
filename: 'bar\\_tests_\\foo.test.ts',
174+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
175+
errors: [
176+
{
177+
message:
178+
'The folder of the file "bar/_tests_/foo.test.ts" does not match "*/__tests__/"',
179+
column: 1,
180+
line: 1,
181+
},
182+
],
183+
},
184+
{
185+
code: "var foo = 'bar';",
186+
filename: 'bar\\_tests_\\foo.test.tsx',
187+
options: [{ '*.test.{js,jsx,ts,tsx}': '*/__tests__/' }],
188+
errors: [
189+
{
190+
message:
191+
'The folder of the file "bar/_tests_/foo.test.tsx" does not match "*/__tests__/"',
192+
column: 1,
193+
line: 1,
194+
},
195+
],
196+
},
197+
],
198+
}
199+
);
200+
201+
ruleTester.run(
202+
"folder-match-with-fex with option on Windows: [{ '*.test.js': '*/__tests__/', '*.test.ts': '*/__tests__/' }]",
203+
rule,
204+
{
205+
valid: [
206+
{
207+
code: "var foo = 'bar';",
208+
filename: 'bar\\__tests__\\foo.test.js',
209+
options: [{ '*.test.js': '*/__tests__/', '*.test.ts': '*/__tests__/' }],
210+
},
211+
{
212+
code: "var foo = 'bar';",
213+
filename: 'bar\\__tests__\\foo.test.ts',
214+
options: [{ '*.test.js': '*/__tests__/', '*.test.ts': '*/__tests__/' }],
215+
},
216+
],
217+
218+
invalid: [
219+
{
220+
code: "var foo = 'bar';",
221+
filename: 'bar\\_tests_\\foo.test.js',
222+
options: [{ '*.test.js': '*/__tests__/', '*.test.ts': '*/__tests__/' }],
223+
errors: [
224+
{
225+
message:
226+
'The folder of the file "bar/_tests_/foo.test.js" does not match "*/__tests__/"',
227+
column: 1,
228+
line: 1,
229+
},
230+
],
231+
},
232+
{
233+
code: "var foo = 'bar';",
234+
filename: 'bar\\_tests_\\foo.test.ts',
235+
options: [{ '*.test.js': '*/__tests__/', '*.test.ts': '*/__tests__/' }],
236+
errors: [
237+
{
238+
message:
239+
'The folder of the file "bar/_tests_/foo.test.ts" does not match "*/__tests__/"',
240+
column: 1,
241+
line: 1,
242+
},
243+
],
244+
},
245+
],
246+
}
247+
);
248+
249+
ruleTester.run(
250+
'folder-match-with-fex with fex that has not been set on Windows',
251+
rule,
252+
{
253+
valid: [
254+
{
255+
code: "var foo = 'bar';",
256+
filename: 'C:\\bar\\__test__\\foo.test.ts',
257+
options: [{ '*.js': '**/__tests__/', '*.jsx': '**/__tests__/' }],
258+
},
259+
],
260+
261+
invalid: [],
262+
}
263+
);
264+
265+
ruleTester.run(
266+
"folder-match-with-fex with option on Windows: [{ '*.test.js': 'FOO', '*.test.ts': '*/__tests__/' }]",
267+
rule,
268+
{
269+
valid: [],
270+
271+
invalid: [
272+
{
273+
code: "var foo = 'bar';",
274+
filename: 'bar\\__tests__\\foo.test.js',
275+
options: [{ '*.test.js': 'FOO', '*.test.ts': '*/__tests__/' }],
276+
errors: [
277+
{
278+
message: 'There is an invalid pattern "FOO", please check it',
279+
column: 1,
280+
line: 1,
281+
},
282+
],
283+
},
284+
],
285+
}
286+
);
287+
288+
ruleTester.run(
289+
"folder-match-with-fex with option on Windows: [{ '*.test.js': '*/__tests__/', '.test.ts': '*/__tests__/' }]",
290+
rule,
291+
{
292+
valid: [],
293+
294+
invalid: [
295+
{
296+
code: "var foo = 'bar';",
297+
filename: 'bar\\__tests__\\foo.test.js',
298+
options: [{ '*.test.js': '*/__tests__/', '.test.ts': '*/__tests__/' }],
299+
errors: [
300+
{
301+
message: 'There is an invalid pattern ".test.ts", please check it',
302+
column: 1,
303+
line: 1,
304+
},
305+
],
306+
},
307+
],
308+
}
309+
);

0 commit comments

Comments
 (0)