forked from levibuzolic/eslint-plugin-no-only-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
164 lines (161 loc) · 6.39 KB
/
tests.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
const rules = require('./index').rules;
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester();
ruleTester.run('no-only-tests', rules['no-only-tests'], {
valid: [
'describe("Some describe block", function() {});',
'it("Some assertion", function() {});',
'xit.only("Some assertion", function() {});',
'xdescribe.only("Some describe block", function() {});',
'xcontext.only("A context block", function() {});',
'xtape.only("A tape block", function() {});',
'xtest.only("A test block", function() {});',
'other.only("An other block", function() {});',
'testResource.only("A test resource block", function() {});',
'var args = {only: "test"};',
'it("should pass meta only through", function() {});',
'obscureTestBlock.only("An obscure testing library test works unless options are supplied", function() {});',
{
options: [{block: ['it']}],
code: 'test.only("Options will exclude this from being caught", function() {});',
},
{
options: [{focus: ['focus']}],
code: 'test.only("Options will exclude this from being caught", function() {});',
},
],
invalid: [
{
code: 'describe.only("Some describe block", function() {});',
output: 'describe.only("Some describe block", function() {});',
errors: [{message: 'describe.only not permitted'}],
},
{
code: 'it.only("Some assertion", function() {});',
output: 'it.only("Some assertion", function() {});',
errors: [{message: 'it.only not permitted'}],
},
{
code: 'context.only("Some context", function() {});',
output: 'context.only("Some context", function() {});',
errors: [{message: 'context.only not permitted'}],
},
{
code: 'test.only("Some test", function() {});',
output: 'test.only("Some test", function() {});',
errors: [{message: 'test.only not permitted'}],
},
{
code: 'tape.only("A tape", function() {});',
output: 'tape.only("A tape", function() {});',
errors: [{message: 'tape.only not permitted'}],
},
{
code: 'fixture.only("A fixture", function() {});',
output: 'fixture.only("A fixture", function() {});',
errors: [{message: 'fixture.only not permitted'}],
},
{
code: 'serial.only("A serial test", function() {});',
output: 'serial.only("A serial test", function() {});',
errors: [{message: 'serial.only not permitted'}],
},
{
options: [{block: ['obscureTestBlock']}],
code: 'obscureTestBlock.only("An obscure testing library test", function() {});',
output: 'obscureTestBlock.only("An obscure testing library test", function() {});',
errors: [{message: 'obscureTestBlock.only not permitted'}],
},
{
options: [{block: ['ava.default']}],
code: 'ava.default.only("Block with dot", function() {});',
output: 'ava.default.only("Block with dot", function() {});',
errors: [{message: 'ava.default.only not permitted'}],
},
{
code: 'it.default.before(console.log).only("Some describe block", function() {});',
output: 'it.default.before(console.log).only("Some describe block", function() {});',
errors: [{message: 'it.default.before.only not permitted'}],
},
{
options: [{focus: ['focus']}],
code: 'test.focus("An alternative focus function", function() {});',
output: 'test.focus("An alternative focus function", function() {});',
errors: [{message: 'test.focus not permitted'}],
},
// As above, but with fix: true option to enable auto-fixing
{
options: [{fix: true}],
code: 'describe.only("Some describe block", function() {});',
output: 'describe("Some describe block", function() {});',
errors: [{message: 'describe.only not permitted'}],
},
{
options: [{fix: true}],
code: 'it.only("Some assertion", function() {});',
output: 'it("Some assertion", function() {});',
errors: [{message: 'it.only not permitted'}],
},
{
options: [{fix: true}],
code: 'context.only("Some context", function() {});',
output: 'context("Some context", function() {});',
errors: [{message: 'context.only not permitted'}],
},
{
options: [{fix: true}],
code: 'test.only("Some test", function() {});',
output: 'test("Some test", function() {});',
errors: [{message: 'test.only not permitted'}],
},
{
options: [{fix: true}],
code: 'tape.only("A tape", function() {});',
output: 'tape("A tape", function() {});',
errors: [{message: 'tape.only not permitted'}],
},
{
options: [{fix: true}],
code: 'fixture.only("A fixture", function() {});',
output: 'fixture("A fixture", function() {});',
errors: [{message: 'fixture.only not permitted'}],
},
{
options: [{fix: true}],
code: 'serial.only("A serial test", function() {});',
output: 'serial("A serial test", function() {});',
errors: [{message: 'serial.only not permitted'}],
},
{
options: [{block: ['obscureTestBlock'], fix: true}],
code: 'obscureTestBlock.only("An obscure testing library test", function() {});',
output: 'obscureTestBlock("An obscure testing library test", function() {});',
errors: [{message: 'obscureTestBlock.only not permitted'}],
},
{
options: [{block: ['ava.default'], fix: true}],
code: 'ava.default.only("Block with dot", function() {});',
output: 'ava.default("Block with dot", function() {});',
errors: [{message: 'ava.default.only not permitted'}],
},
{
options: [{fix: true}],
code: 'it.default.before(console.log).only("Some describe block", function() {});',
errors: [{message: 'it.default.before.only not permitted'}],
output: 'it.default.before(console.log)("Some describe block", function() {});',
},
{
options: [{focus: ['focus'], fix: true}],
code: 'test.focus("An alternative focus function", function() {});',
output: 'test("An alternative focus function", function() {});',
errors: [{message: 'test.focus not permitted'}],
},
{
options: [{block: ['test*']}],
code: 'testResource.only("A test resource block", function() {});',
output: 'testResource.only("A test resource block", function() {});',
errors: [{message: 'testResource.only not permitted'}],
},
],
});
console.log('Tests completed successfully');