-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathuse-test.js
143 lines (136 loc) · 3.75 KB
/
use-test.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
'use strict';
const test = require('ava');
const avaRuleTester = require('eslint-ava-rule-tester');
const rule = require('../rules/use-test');
const ruleTester = avaRuleTester(test, {
env: {
es6: true,
},
parserOptions: {
sourceType: 'module',
},
});
const typescriptRuleTester = avaRuleTester(test, {
parser: require.resolve('@typescript-eslint/parser'),
});
const errors = [{}];
const commonTestCases = {
valid: [
{code: 'var test = require(\'ava\');', filename: 'file.js'},
{code: 'let test = require(\'ava\');', filename: 'file.js'},
{code: 'const test = require(\'ava\');', filename: 'file.js'},
{code: 'const a = 1, test = require(\'ava\'), b = 2;', filename: 'file.js'},
{code: 'const test = require(\'foo\');', filename: 'file.js'},
{code: 'import test from \'ava\';', filename: 'file.js'},
{code: 'import test, {} from \'ava\';', filename: 'file.js'},
{code: 'import test from \'foo\';', filename: 'file.js'},
{code: 'var anyTest = require(\'ava\');', filename: 'file.ts'},
{code: 'let anyTest = require(\'ava\');', filename: 'file.ts'},
{code: 'const anyTest = require(\'ava\');', filename: 'file.ts'},
{code: 'const a = 1, anyTest = require(\'ava\'), b = 2;', filename: 'file.ts'},
{code: 'const anyTest = require(\'foo\');', filename: 'file.ts'},
{code: 'import anyTest from \'ava\';', filename: 'file.ts'},
{code: 'import anyTest, {} from \'ava\';', filename: 'file.ts'},
{code: 'import anyTest from \'foo\';', filename: 'file.ts'},
{code: 'var anyTest = require(\'ava\');', filename: 'file.tsx'},
{code: 'let anyTest = require(\'ava\');', filename: 'file.tsx'},
{code: 'const anyTest = require(\'ava\');', filename: 'file.tsx'},
{code: 'const a = 1, anyTest = require(\'ava\'), b = 2;', filename: 'file.tsx'},
{code: 'const anyTest = require(\'foo\');', filename: 'file.tsx'},
{code: 'import anyTest from \'ava\';', filename: 'file.tsx'},
{code: 'import anyTest, {} from \'ava\';', filename: 'file.tsx'},
{code: 'import anyTest from \'foo\';', filename: 'file.tsx'},
],
invalid: [
{
code: 'var ava = require(\'ava\');',
errors,
filename: 'file.ts',
},
{
code: 'let ava = require(\'ava\');',
errors,
filename: 'file.ts',
},
{
code: 'const ava = require(\'ava\');',
errors,
filename: 'file.ts',
},
{
code: 'const a = 1, ava = require(\'ava\'), b = 2;',
errors,
filename: 'file.ts',
},
{
code: 'import ava from \'ava\';',
errors,
filename: 'file.ts',
},
{
code: 'var anyTest = require(\'ava\');',
errors,
filename: 'file.js',
},
{
code: 'var ava = require(\'ava\');',
errors,
filename: 'file.ts',
},
{
code: 'let ava = require(\'ava\');',
errors,
filename: 'file.ts',
},
{
code: 'const ava = require(\'ava\');',
errors,
filename: 'file.ts',
},
{
code: 'const a = 1, ava = require(\'ava\'), b = 2;',
errors,
filename: 'file.ts',
},
{
code: 'import ava from \'ava\';',
errors,
filename: 'file.ts',
},
{
code: 'var ava = require(\'ava\');',
errors,
filename: 'file.tsx',
},
{
code: 'let ava = require(\'ava\');',
errors,
filename: 'file.tsx',
},
{
code: 'const ava = require(\'ava\');',
errors,
filename: 'file.tsx',
},
{
code: 'const a = 1, ava = require(\'ava\'), b = 2;',
errors,
filename: 'file.tsx',
},
{
code: 'import ava from \'ava\';',
errors,
filename: 'file.tsx',
},
],
};
const typescriptTestCases = {
valid: [
{code: 'import type {Macro} from \'ava\';', filename: 'file.ts'},
{code: 'import type {Macro} from \'ava\';', filename: 'file.tsx'},
],
invalid: [],
};
ruleTester.run('use-test', rule, commonTestCases);
typescriptRuleTester.run('use-test', rule, commonTestCases);
typescriptRuleTester.run('use-test', rule, typescriptTestCases);