-
Notifications
You must be signed in to change notification settings - Fork 18
/
tests.js
205 lines (202 loc) · 6.98 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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() {});',
},
{
options: [{ functions: ["fit", "xit"] }],
code: 'it("Options will exclude this from being caught", function() {});',
},
],
invalid: [
{
code: 'describe.only("Some describe block", function() {});',
errors: [{ message: "describe.only not permitted" }],
},
{
code: 'it.only("Some assertion", function() {});',
errors: [{ message: "it.only not permitted" }],
},
{
code: 'context.only("Some context", function() {});',
errors: [{ message: "context.only not permitted" }],
},
{
code: 'test.only("Some test", function() {});',
errors: [{ message: "test.only not permitted" }],
},
{
code: 'tape.only("A tape", function() {});',
errors: [{ message: "tape.only not permitted" }],
},
{
code: 'fixture.only("A fixture", function() {});',
errors: [{ message: "fixture.only not permitted" }],
},
{
code: 'serial.only("A serial test", function() {});',
errors: [{ message: "serial.only not permitted" }],
},
{
options: [{ block: ["obscureTestBlock"] }],
code: '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() {});',
errors: [{ message: "ava.default.only not permitted" }],
},
{
code: '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() {});',
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() {});',
errors: [{ message: "testResource.only not permitted" }],
},
{
options: [{ fix: true }],
code: 'Feature.only("Some Feature", function() {});',
output: 'Feature("Some Feature", function() {});',
errors: [{ message: "Feature.only not permitted" }],
},
{
options: [{ fix: true }],
code: 'Scenario.only("Some Scenario", function() {});',
output: 'Scenario("Some Scenario", function() {});',
errors: [{ message: "Scenario.only not permitted" }],
},
{
options: [{ fix: true }],
code: 'Given.only("Some assertion", function() {});',
output: 'Given("Some assertion", function() {});',
errors: [{ message: "Given.only not permitted" }],
},
{
options: [{ fix: true }],
code: 'And.only("Some assertion", function() {});',
output: 'And("Some assertion", function() {});',
errors: [{ message: "And.only not permitted" }],
},
{
options: [{ fix: true }],
code: 'When.only("Some assertion", function() {});',
output: 'When("Some assertion", function() {});',
errors: [{ message: "When.only not permitted" }],
},
{
options: [{ fix: true }],
code: 'Then.only("Some assertion", function() {});',
output: 'Then("Some assertion", function() {});',
errors: [{ message: "Then.only not permitted" }],
},
{
options: [{ functions: ["fit", "xit"] }],
code: 'xit("No skipped tests", function() {});',
errors: [{ message: "xit not permitted" }],
},
{
options: [{ functions: ["fit", "xit"], fix: true }],
code: 'xit("No skipped tests", function() {});',
errors: [{ message: "xit not permitted" }],
},
],
});
/* global process */
process.stderr.write("\n✅ Tests completed successfully\n");