Skip to content

Commit dcba5f1

Browse files
feat(rules): add .concurrent support (#498) (#502)
* feat(rules): add .concurrent support * refactor(no-focused): remove unnecessary type cast * chore(utils): inline `isConcurrentTestCase` * chore(no-focused-tests): use static checks instead of dynamic RegExp * chore(no-focused-tests): add test case for if `concurrent` is called * chore(utils): remove body from arrow functions Co-authored-by: Leonardo Villela <[email protected]>
1 parent 02e7cef commit dcba5f1

15 files changed

+354
-33
lines changed

src/rules/__tests__/consistent-test-it.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
2424
code: 'test.skip("foo")',
2525
options: [{ fn: TestCaseName.test }],
2626
},
27+
{
28+
code: 'test.concurrent("foo")',
29+
options: [{ fn: TestCaseName.test }],
30+
},
2731
{
2832
code: 'xtest("foo")',
2933
options: [{ fn: TestCaseName.test }],
@@ -90,6 +94,20 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
9094
],
9195
output: 'test.skip("foo")',
9296
},
97+
{
98+
code: 'it.concurrent("foo")',
99+
options: [{ fn: TestCaseName.test }],
100+
errors: [
101+
{
102+
messageId: 'consistentMethod',
103+
data: {
104+
testKeyword: TestCaseName.test,
105+
oppositeTestKeyword: TestCaseName.it,
106+
},
107+
},
108+
],
109+
output: 'test.concurrent("foo")',
110+
},
93111
{
94112
code: 'it.only("foo")',
95113
options: [{ fn: TestCaseName.test }],
@@ -143,6 +161,10 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
143161
code: 'it.skip("foo")',
144162
options: [{ fn: TestCaseName.it }],
145163
},
164+
{
165+
code: 'it.concurrent("foo")',
166+
options: [{ fn: TestCaseName.it }],
167+
},
146168
{
147169
code: 'describe("suite", () => { it("foo") })',
148170
options: [{ fn: TestCaseName.it }],
@@ -191,6 +213,20 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
191213
],
192214
output: 'it.skip("foo")',
193215
},
216+
{
217+
code: 'test.concurrent("foo")',
218+
options: [{ fn: TestCaseName.it }],
219+
errors: [
220+
{
221+
messageId: 'consistentMethod',
222+
data: {
223+
testKeyword: TestCaseName.it,
224+
oppositeTestKeyword: TestCaseName.test,
225+
},
226+
},
227+
],
228+
output: 'it.concurrent("foo")',
229+
},
194230
{
195231
code: 'test.only("foo")',
196232
options: [{ fn: TestCaseName.it }],
@@ -236,6 +272,10 @@ ruleTester.run('consistent-test-it with fn=test and withinDescribe=it ', rule, {
236272
code: 'test.skip("foo")',
237273
options: [{ fn: TestCaseName.test, withinDescribe: TestCaseName.it }],
238274
},
275+
{
276+
code: 'test.concurrent("foo")',
277+
options: [{ fn: TestCaseName.test, withinDescribe: TestCaseName.it }],
278+
},
239279
{
240280
code: 'xtest("foo")',
241281
options: [{ fn: TestCaseName.test, withinDescribe: TestCaseName.it }],
@@ -302,6 +342,20 @@ ruleTester.run('consistent-test-it with fn=test and withinDescribe=it ', rule, {
302342
],
303343
output: 'describe("suite", () => { it.skip("foo") })',
304344
},
345+
{
346+
code: 'describe("suite", () => { test.concurrent("foo") })',
347+
options: [{ fn: TestCaseName.test, withinDescribe: TestCaseName.it }],
348+
errors: [
349+
{
350+
messageId: 'consistentMethodWithinDescribe',
351+
data: {
352+
testKeywordWithinDescribe: TestCaseName.it,
353+
oppositeTestKeyword: TestCaseName.test,
354+
},
355+
},
356+
],
357+
output: 'describe("suite", () => { it.concurrent("foo") })',
358+
},
305359
],
306360
});
307361

@@ -319,6 +373,10 @@ ruleTester.run('consistent-test-it with fn=it and withinDescribe=test ', rule, {
319373
code: 'it.skip("foo")',
320374
options: [{ fn: TestCaseName.it, withinDescribe: TestCaseName.test }],
321375
},
376+
{
377+
code: 'it.concurrent("foo")',
378+
options: [{ fn: TestCaseName.it, withinDescribe: TestCaseName.test }],
379+
},
322380
{
323381
code: 'xit("foo")',
324382
options: [{ fn: TestCaseName.it, withinDescribe: TestCaseName.test }],
@@ -385,6 +443,20 @@ ruleTester.run('consistent-test-it with fn=it and withinDescribe=test ', rule, {
385443
],
386444
output: 'describe("suite", () => { test.skip("foo") })',
387445
},
446+
{
447+
code: 'describe("suite", () => { it.concurrent("foo") })',
448+
options: [{ fn: TestCaseName.it, withinDescribe: TestCaseName.test }],
449+
errors: [
450+
{
451+
messageId: 'consistentMethodWithinDescribe',
452+
data: {
453+
testKeywordWithinDescribe: TestCaseName.test,
454+
oppositeTestKeyword: TestCaseName.it,
455+
},
456+
},
457+
],
458+
output: 'describe("suite", () => { test.concurrent("foo") })',
459+
},
388460
],
389461
});
390462

src/rules/__tests__/no-commented-out-tests.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ ruleTester.run('no-commented-out-tests', rule, {
1717
'it("foo", function () {})',
1818
'describe.only("foo", function () {})',
1919
'it.only("foo", function () {})',
20+
'it.concurrent("foo", function () {})',
2021
'test("foo", function () {})',
2122
'test.only("foo", function () {})',
23+
'test.concurrent("foo", function () {})',
2224
'var appliedSkip = describe.skip; appliedSkip.apply(describe)',
2325
'var calledSkip = it.skip; calledSkip.call(it)',
2426
'({ f: function () {} }).f()',
@@ -80,6 +82,10 @@ ruleTester.run('no-commented-out-tests', rule, {
8082
code: '// it.only("foo", function () {})',
8183
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
8284
},
85+
{
86+
code: '// it.concurrent("foo", function () {})',
87+
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
88+
},
8389
{
8490
code: '// it["skip"]("foo", function () {})',
8591
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
@@ -88,6 +94,10 @@ ruleTester.run('no-commented-out-tests', rule, {
8894
code: '// test.skip("foo", function () {})',
8995
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
9096
},
97+
{
98+
code: '// test.concurrent("foo", function () {})',
99+
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],
100+
},
91101
{
92102
code: '// test["skip"]("foo", function () {})',
93103
errors: [{ messageId: 'commentedTests', column: 1, line: 1 }],

src/rules/__tests__/no-disabled-tests.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ ruleTester.run('no-disabled-tests', rule, {
1616
'it("foo", function () {})',
1717
'describe.only("foo", function () {})',
1818
'it.only("foo", function () {})',
19+
'it.concurrent("foo", function () {})',
1920
'test("foo", function () {})',
2021
'test.only("foo", function () {})',
22+
'test.concurrent("foo", function () {})',
2123
'describe[`${"skip"}`]("foo", function () {})',
2224
'var appliedSkip = describe.skip; appliedSkip.apply(describe)',
2325
'var calledSkip = it.skip; calledSkip.call(it)',
@@ -73,6 +75,10 @@ ruleTester.run('no-disabled-tests', rule, {
7375
code: 'it.skip("foo", function () {})',
7476
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
7577
},
78+
{
79+
code: 'it.concurrent.skip("foo", function () {})',
80+
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
81+
},
7682
{
7783
code: 'it["skip"]("foo", function () {})',
7884
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
@@ -81,6 +87,10 @@ ruleTester.run('no-disabled-tests', rule, {
8187
code: 'test.skip("foo", function () {})',
8288
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
8389
},
90+
{
91+
code: 'test.concurrent.skip("foo", function () {})',
92+
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
93+
},
8494
{
8595
code: 'test["skip"]("foo", function () {})',
8696
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],

src/rules/__tests__/no-focused-tests.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ ruleTester.run('no-focused-tests', rule, {
1515
'it()',
1616
'describe.skip()',
1717
'it.skip()',
18+
'it.concurrent.skip()',
1819
'test()',
1920
'test.skip()',
21+
'test.concurrent.skip()',
2022
'var appliedOnly = describe.only; appliedOnly.apply(describe)',
2123
'var calledOnly = it.only; calledOnly.call(it)',
2224
'it.each()()',
2325
'it.each`table`()',
2426
'test.each()()',
2527
'test.each`table`()',
28+
'test.concurrent()',
2629
],
2730

2831
invalid: [
@@ -46,6 +49,10 @@ ruleTester.run('no-focused-tests', rule, {
4649
code: 'it.only()',
4750
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
4851
},
52+
{
53+
code: 'it.concurrent.only()',
54+
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
55+
},
4956
{
5057
code: 'it.only.each()',
5158
errors: [{ messageId: 'focusedTest', column: 4, line: 1 }],
@@ -62,6 +69,10 @@ ruleTester.run('no-focused-tests', rule, {
6269
code: 'test.only()',
6370
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
6471
},
72+
{
73+
code: 'test.concurrent.only()',
74+
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],
75+
},
6576
{
6677
code: 'test.only.each()',
6778
errors: [{ messageId: 'focusedTest', column: 6, line: 1 }],

src/rules/__tests__/no-identical-title.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,22 @@ ruleTester.run('no-identical-title', rule, {
2525
'});',
2626
].join('\n'),
2727
['it("it1", function() {});', 'it("it2", function() {});'].join('\n'),
28+
[
29+
'it.concurrent("it1", function() {});',
30+
'it.concurrent("it2", function() {});',
31+
].join('\n'),
2832
['it.only("it1", function() {});', 'it("it2", function() {});'].join('\n'),
2933
['it.only("it1", function() {});', 'it.only("it2", function() {});'].join(
3034
'\n',
3135
),
36+
[
37+
'it.concurrent.only("it1", function() {});',
38+
'it.concurrent("it2", function() {});',
39+
].join('\n'),
40+
[
41+
'it.concurrent.only("it1", function() {});',
42+
'it.concurrent.only("it2", function() {});',
43+
].join('\n'),
3244
['describe("title", function() {});', 'it("title", function() {});'].join(
3345
'\n',
3446
),
@@ -118,13 +130,27 @@ ruleTester.run('no-identical-title', rule, {
118130
),
119131
errors: [{ messageId: 'multipleTestTitle', column: 4, line: 2 }],
120132
},
133+
{
134+
code: [
135+
'it.concurrent("it1", function() {});',
136+
'it.concurrent("it1", function() {});',
137+
].join('\n'),
138+
errors: [{ messageId: 'multipleTestTitle', column: 15, line: 2 }],
139+
},
121140
{
122141
code: [
123142
'it.only("it1", function() {});',
124143
'it("it1", function() {});',
125144
].join('\n'),
126145
errors: [{ messageId: 'multipleTestTitle', column: 4, line: 2 }],
127146
},
147+
{
148+
code: [
149+
'it.concurrent.only("it1", function() {});',
150+
'it.concurrent("it1", function() {});',
151+
].join('\n'),
152+
errors: [{ messageId: 'multipleTestTitle', column: 15, line: 2 }],
153+
},
128154
{
129155
code: ['fit("it1", function() {});', 'it("it1", function() {});'].join(
130156
'\n',
@@ -138,6 +164,13 @@ ruleTester.run('no-identical-title', rule, {
138164
].join('\n'),
139165
errors: [{ messageId: 'multipleTestTitle', column: 9, line: 2 }],
140166
},
167+
{
168+
code: [
169+
'it.concurrent.only("it1", function() {});',
170+
'it.concurrent.only("it1", function() {});',
171+
].join('\n'),
172+
errors: [{ messageId: 'multipleTestTitle', column: 20, line: 2 }],
173+
},
141174
{
142175
code: [
143176
'describe("describe1", function() {});',

src/rules/__tests__/no-if.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ ruleTester.run('no-if', rule, {
190190
},
191191
],
192192
},
193+
{
194+
code: `it.concurrent.skip('foo', () => {
195+
if('bar') {}
196+
})`,
197+
errors: [
198+
{
199+
messageId: 'noIf',
200+
},
201+
],
202+
},
193203
{
194204
code: `it.only('foo', () => {
195205
if('bar') {}
@@ -200,6 +210,16 @@ ruleTester.run('no-if', rule, {
200210
},
201211
],
202212
},
213+
{
214+
code: `it.concurrent.only('foo', () => {
215+
if('bar') {}
216+
})`,
217+
errors: [
218+
{
219+
messageId: 'noIf',
220+
},
221+
],
222+
},
203223
{
204224
code: `xit('foo', () => {
205225
if('bar') {}
@@ -220,6 +240,16 @@ ruleTester.run('no-if', rule, {
220240
},
221241
],
222242
},
243+
{
244+
code: `fit.concurrent('foo', () => {
245+
if('bar') {}
246+
})`,
247+
errors: [
248+
{
249+
messageId: 'noIf',
250+
},
251+
],
252+
},
223253
{
224254
code: `test('foo', () => {
225255
if('bar') {}
@@ -231,7 +261,7 @@ ruleTester.run('no-if', rule, {
231261
],
232262
},
233263
{
234-
code: `test.skip('foo', () => {
264+
code: `test.concurrent.skip('foo', () => {
235265
if('bar') {}
236266
})`,
237267
errors: [
@@ -241,7 +271,7 @@ ruleTester.run('no-if', rule, {
241271
],
242272
},
243273
{
244-
code: `test.only('foo', () => {
274+
code: `test.concurrent.only('foo', () => {
245275
if('bar') {}
246276
})`,
247277
errors: [

src/rules/__tests__/no-standalone-expect.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ruleTester.run('no-standalone-expect', rule, {
3232
});
3333
`,
3434
'it.only("an only", value => { expect(value).toBe(true); });',
35+
'it.concurrent("an concurrent", value => { expect(value).toBe(true); });',
3536
'describe.each([1, true])("trues", value => { it("an it", () => expect(value).toBe(true) ); });',
3637
],
3738
invalid: [

0 commit comments

Comments
 (0)