Skip to content

Commit e09eaad

Browse files
committed
test: add unit cases on Windows for rule no-index
1 parent 314c24d commit e09eaad

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"eslint-plugin-prettier": "4.0.0",
4747
"husky": "^8.0.1",
4848
"mocha": "^10.1.0",
49-
"prettier": "2.5.1"
49+
"prettier": "2.5.1",
50+
"proxyquire": "^2.1.3"
5051
},
5152
"engines": {
5253
"node": "12.x || 14.x || >= 16"

tests/lib/rules/no-index.windows.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @file A file cannot be named "index"
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/no-index', {
12+
path: { ...path.win32, '@global': true },
13+
});
14+
const ruleTester = new RuleTester();
15+
16+
ruleTester.run('no-index on Windows', rule, {
17+
valid: [
18+
{
19+
code: "var foo = 'bar';",
20+
filename: 'C:\\Users\\Administrator\\Downloads\\wai\\src\\main.js',
21+
},
22+
{
23+
code: "var foo = 'bar';",
24+
filename: 'src\\main.ts',
25+
},
26+
],
27+
28+
invalid: [
29+
{
30+
code: "var foo = 'bar';",
31+
filename: 'C:\\Users\\Administrator\\Downloads\\wai\\src\\index.js',
32+
errors: [
33+
{
34+
message:
35+
'The filename "index" is not allowed, please use another one',
36+
column: 1,
37+
line: 1,
38+
},
39+
],
40+
},
41+
{
42+
code: "var foo = 'bar';",
43+
filename: 'src\\index.ts',
44+
errors: [
45+
{
46+
message:
47+
'The filename "index" is not allowed, please use another one',
48+
column: 1,
49+
line: 1,
50+
},
51+
],
52+
},
53+
],
54+
});

0 commit comments

Comments
 (0)