Skip to content

Commit c689b08

Browse files
authored
Apply title rules to test.step (#309)
* Apply title rules to test.step * Prettier * ESLint * Revert changes to the existing test * docs update
1 parent 1034dc0 commit c689b08

File tree

3 files changed

+183
-10
lines changed

3 files changed

+183
-10
lines changed

docs/rules/valid-title.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ test.describe('foo', () => {
143143
```ts
144144
interface Options {
145145
ignoreSpaces?: boolean
146+
ignoreTypeOfStepName?: boolean
146147
ignoreTypeOfTestName?: boolean
147148
ignoreTypeOfDescribeName?: boolean
148149
disallowedWords?: string[]
@@ -157,6 +158,13 @@ Default: `false`
157158

158159
When enabled, the leading and trailing spaces won't be checked.
159160

161+
#### `ignoreTypeOfStepName`
162+
163+
Default: `true`
164+
165+
When enabled, the type of the first argument to `test.step` blocks won't be
166+
checked.
167+
160168
#### `ignoreTypeOfDescribeName`
161169

162170
Default: `false`

src/rules/valid-title.test.ts

Lines changed: 158 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ runRuleTester('valid-title', rule, {
6363
],
6464
options: [{ disallowedWords: ['properly'] }],
6565
},
66+
{
67+
code: 'test.step(`that the value is set properly`, function () {})',
68+
errors: [
69+
{
70+
column: 11,
71+
data: { word: 'properly' },
72+
line: 1,
73+
messageId: 'disallowedWord',
74+
},
75+
],
76+
options: [{ disallowedWords: ['properly'] }],
77+
},
6678
// Global aliases
6779
{
6880
code: 'it("the correct way to properly handle all things", () => {});',
@@ -142,7 +154,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
142154
});
143155
144156
test.describe('e2e tests #e4e', () => {
145-
test('is another test #e2e #playwright4life', () => {});
157+
test('is another test #e2e #playwright4life', () => {
158+
test.step('#wow', () => {});
159+
});
146160
});
147161
});
148162
`,
@@ -165,6 +179,15 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
165179
line: 9,
166180
messageId: 'mustNotMatch',
167181
},
182+
{
183+
column: 17,
184+
data: {
185+
functionName: 'step',
186+
pattern: /(?:#(?!unit|e2e))\w+/u,
187+
},
188+
line: 10,
189+
messageId: 'mustNotMatch',
190+
},
168191
],
169192
options: [
170193
{
@@ -183,7 +206,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
183206
});
184207
185208
test.describe('e2e tests #e4e', () => {
186-
test('is another test #e2e #playwright4life', () => {});
209+
test('is another test #e2e #playwright4life', () => {
210+
test.step('#wow', () => {});
211+
});
187212
});
188213
});
189214
`,
@@ -208,6 +233,15 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
208233
line: 9,
209234
messageId: 'mustNotMatchCustom',
210235
},
236+
{
237+
column: 17,
238+
data: {
239+
message: 'Please include "#unit" or "#e2e" in titles',
240+
pattern: /(?:#(?!unit|e2e))\w+/u,
241+
},
242+
line: 10,
243+
messageId: 'mustNotMatchCustom',
244+
},
211245
],
212246
options: [
213247
{
@@ -232,7 +266,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
232266
});
233267
234268
test.describe('e2e tests #e4e', () => {
235-
test('is another test #e2e #playwright4life', () => {});
269+
test('is another test #e2e #playwright4life', () => {
270+
test.step('#wow', () => {});
271+
});
236272
});
237273
});
238274
`,
@@ -264,7 +300,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
264300
});
265301
266302
test.describe('e2e tests #e4e', () => {
267-
test('is another test #e2e #playwright4life', () => {});
303+
test('is another test #e2e #playwright4life', () => {
304+
test.step('#wow', () => {});
305+
});
268306
});
269307
});
270308
`,
@@ -302,7 +340,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
302340
});
303341
304342
test.describe('e2e tests #e4e', () => {
305-
test('is another test #e2e #playwright4life', () => {});
343+
test('is another test #e2e #playwright4life', () => {
344+
test.step('#wow', () => {});
345+
});
306346
});
307347
});
308348
`,
@@ -334,7 +374,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
334374
});
335375
336376
test.describe('e2e tests #e4e', () => {
337-
test('is another test #e2e #playwright4life', () => {});
377+
test('is another test #e2e #playwright4life', () => {
378+
test.step('#wow', () => {});
379+
});
338380
});
339381
});
340382
`,
@@ -409,6 +451,21 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
409451
{ mustMatch: { describe: /#(?:unit|integration|e2e)/u.source } },
410452
],
411453
},
454+
{
455+
code: 'test.step("the test", () => {});',
456+
errors: [
457+
{
458+
column: 11,
459+
data: {
460+
functionName: 'step',
461+
pattern: /#(?:unit|integration|e2e)/u,
462+
},
463+
line: 1,
464+
messageId: 'mustMatch',
465+
},
466+
],
467+
options: [{ mustMatch: { step: /#(?:unit|integration|e2e)/u.source } }],
468+
},
412469
{
413470
code: 'test.describe.skip("the test", () => {});',
414471
errors: [
@@ -503,6 +560,12 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
503560
{ mustMatch: { describe: /#(?:unit|integration|e2e)/u.source } },
504561
],
505562
},
563+
{
564+
code: 'test.step("correctly sets the value", () => {});',
565+
options: [
566+
{ mustMatch: { describe: /#(?:unit|integration|e2e)/u.source } },
567+
],
568+
},
506569
{
507570
code: javascript`
508571
test.describe('things to test', () => {
@@ -657,6 +720,17 @@ runRuleTester('title-must-be-string', rule, {
657720
},
658721
],
659722
},
723+
{
724+
code: 'test.step(123, () => {});',
725+
errors: [
726+
{
727+
column: 11,
728+
line: 1,
729+
messageId: 'titleMustBeString',
730+
},
731+
],
732+
options: [{ ignoreTypeOfStepName: false }],
733+
},
660734
// Global aliases
661735
{
662736
code: 'it(String(/.+/), () => {});',
@@ -685,6 +759,7 @@ runRuleTester('title-must-be-string', rule, {
685759
'test.describe.skip("is a string", () => {});',
686760
'test.describe.skip(`${myFunc} is a string`, () => {});',
687761
'test.describe("is a string", () => {});',
762+
'test.step(123, () => {});',
688763
{
689764
code: 'test.describe(String(/.+/), () => {});',
690765
options: [{ ignoreTypeOfDescribeName: true }],
@@ -811,6 +886,17 @@ runRuleTester('no-empty-title', rule, {
811886
},
812887
],
813888
},
889+
{
890+
code: 'test.step(``, function () {})',
891+
errors: [
892+
{
893+
column: 1,
894+
data: { functionName: 'step' },
895+
line: 1,
896+
messageId: 'emptyTitle',
897+
},
898+
],
899+
},
814900
// Global aliases
815901
{
816902
code: 'it.describe("", function () {})',
@@ -840,6 +926,7 @@ runRuleTester('no-empty-title', rule, {
840926
'test.skip(`foo`, function () {})',
841927
'test(`${foo}`, function () {})',
842928
'test.fixme(`${foo}`, function () {})',
929+
'test.step(`${foo}`, function () {})',
843930
// Global aliases
844931
{
845932
code: 'test.describe()',
@@ -969,6 +1056,21 @@ runRuleTester('no-accidental-space', rule, {
9691056
errors: [{ column: 6, line: 1, messageId: 'accidentalSpace' }],
9701057
output: 'test("foo", function () {})',
9711058
},
1059+
{
1060+
code: 'test.step(` foo bar bang `, function () {})',
1061+
errors: [{ column: 11, line: 1, messageId: 'accidentalSpace' }],
1062+
output: 'test.step(`foo bar bang`, function () {})',
1063+
},
1064+
{
1065+
code: 'test.step(" foo", function () {})',
1066+
errors: [{ column: 11, line: 1, messageId: 'accidentalSpace' }],
1067+
output: 'test.step("foo", function () {})',
1068+
},
1069+
{
1070+
code: 'test.step(" foo ", function () {})',
1071+
errors: [{ column: 11, line: 1, messageId: 'accidentalSpace' }],
1072+
output: 'test.step("foo", function () {})',
1073+
},
9721074
{
9731075
code: javascript`
9741076
test.describe(' foo', () => {
@@ -1013,6 +1115,8 @@ runRuleTester('no-accidental-space', rule, {
10131115
'test("foo", function () {})',
10141116
'test.describe()',
10151117
'test.describe("foo", function () {})',
1118+
'test.step()',
1119+
'test.step("foo", function () {})',
10161120
'test.only()',
10171121
'test.only("foo", function () {})',
10181122
javascript`
@@ -1135,6 +1239,37 @@ runRuleTester('no-duplicate-prefix test', rule, {
11351239
],
11361240
})
11371241

1242+
runRuleTester('no-duplicate-prefix step', rule, {
1243+
invalid: [
1244+
{
1245+
code: 'test.step("step foo", function () {})',
1246+
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
1247+
output: 'test.step("foo", function () {})',
1248+
},
1249+
{
1250+
code: 'test.step("step foo", function () {})',
1251+
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
1252+
output: 'test.step("foo", function () {})',
1253+
},
1254+
{
1255+
code: 'test.step("step foo", function () {})',
1256+
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
1257+
output: 'test.step("foo", function () {})',
1258+
},
1259+
{
1260+
code: "test.step('step foo', function () {})",
1261+
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
1262+
output: "test.step('foo', function () {})",
1263+
},
1264+
{
1265+
code: 'test.step(`step foo`, function () {})',
1266+
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
1267+
output: 'test.step(`foo`, function () {})',
1268+
},
1269+
],
1270+
valid: ['test.step("foo", function () {})'],
1271+
})
1272+
11381273
runRuleTester('no-duplicate-prefix nested', rule, {
11391274
invalid: [
11401275
{
@@ -1176,6 +1311,23 @@ runRuleTester('no-duplicate-prefix nested', rule, {
11761311
})
11771312
`,
11781313
},
1314+
{
1315+
code: javascript`
1316+
test.describe('foo', () => {
1317+
test('bar', () => {
1318+
test.step('step foobar', () => {})
1319+
})
1320+
})
1321+
`,
1322+
errors: [{ column: 15, line: 3, messageId: 'duplicatePrefix' }],
1323+
output: javascript`
1324+
test.describe('foo', () => {
1325+
test('bar', () => {
1326+
test.step('foobar', () => {})
1327+
})
1328+
})
1329+
`,
1330+
},
11791331
// Global aliases
11801332
{
11811333
code: javascript`

0 commit comments

Comments
 (0)