Skip to content

Apply title rules to test.step #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/rules/valid-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ test.describe('foo', () => {
```ts
interface Options {
ignoreSpaces?: boolean
ignoreTypeOfStepName?: boolean
ignoreTypeOfTestName?: boolean
ignoreTypeOfDescribeName?: boolean
disallowedWords?: string[]
Expand All @@ -157,6 +158,13 @@ Default: `false`

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

#### `ignoreTypeOfStepName`

Default: `true`

When enabled, the type of the first argument to `test.step` blocks won't be
checked.

#### `ignoreTypeOfDescribeName`

Default: `false`
Expand Down
164 changes: 158 additions & 6 deletions src/rules/valid-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ runRuleTester('valid-title', rule, {
],
options: [{ disallowedWords: ['properly'] }],
},
{
code: 'test.step(`that the value is set properly`, function () {})',
errors: [
{
column: 11,
data: { word: 'properly' },
line: 1,
messageId: 'disallowedWord',
},
],
options: [{ disallowedWords: ['properly'] }],
},
// Global aliases
{
code: 'it("the correct way to properly handle all things", () => {});',
Expand Down Expand Up @@ -142,7 +154,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
});

test.describe('e2e tests #e4e', () => {
test('is another test #e2e #playwright4life', () => {});
test('is another test #e2e #playwright4life', () => {
test.step('#wow', () => {});
});
});
});
`,
Expand All @@ -165,6 +179,15 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
line: 9,
messageId: 'mustNotMatch',
},
{
column: 17,
data: {
functionName: 'step',
pattern: /(?:#(?!unit|e2e))\w+/u,
},
line: 10,
messageId: 'mustNotMatch',
},
],
options: [
{
Expand All @@ -183,7 +206,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
});

test.describe('e2e tests #e4e', () => {
test('is another test #e2e #playwright4life', () => {});
test('is another test #e2e #playwright4life', () => {
test.step('#wow', () => {});
});
});
});
`,
Expand All @@ -208,6 +233,15 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
line: 9,
messageId: 'mustNotMatchCustom',
},
{
column: 17,
data: {
message: 'Please include "#unit" or "#e2e" in titles',
pattern: /(?:#(?!unit|e2e))\w+/u,
},
line: 10,
messageId: 'mustNotMatchCustom',
},
],
options: [
{
Expand All @@ -232,7 +266,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
});

test.describe('e2e tests #e4e', () => {
test('is another test #e2e #playwright4life', () => {});
test('is another test #e2e #playwright4life', () => {
test.step('#wow', () => {});
});
});
});
`,
Expand Down Expand Up @@ -264,7 +300,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
});

test.describe('e2e tests #e4e', () => {
test('is another test #e2e #playwright4life', () => {});
test('is another test #e2e #playwright4life', () => {
test.step('#wow', () => {});
});
});
});
`,
Expand Down Expand Up @@ -302,7 +340,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
});

test.describe('e2e tests #e4e', () => {
test('is another test #e2e #playwright4life', () => {});
test('is another test #e2e #playwright4life', () => {
test.step('#wow', () => {});
});
});
});
`,
Expand Down Expand Up @@ -334,7 +374,9 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
});

test.describe('e2e tests #e4e', () => {
test('is another test #e2e #playwright4life', () => {});
test('is another test #e2e #playwright4life', () => {
test.step('#wow', () => {});
});
});
});
`,
Expand Down Expand Up @@ -409,6 +451,21 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
{ mustMatch: { describe: /#(?:unit|integration|e2e)/u.source } },
],
},
{
code: 'test.step("the test", () => {});',
errors: [
{
column: 11,
data: {
functionName: 'step',
pattern: /#(?:unit|integration|e2e)/u,
},
line: 1,
messageId: 'mustMatch',
},
],
options: [{ mustMatch: { step: /#(?:unit|integration|e2e)/u.source } }],
},
{
code: 'test.describe.skip("the test", () => {});',
errors: [
Expand Down Expand Up @@ -503,6 +560,12 @@ runRuleTester('mustMatch & mustNotMatch options', rule, {
{ mustMatch: { describe: /#(?:unit|integration|e2e)/u.source } },
],
},
{
code: 'test.step("correctly sets the value", () => {});',
options: [
{ mustMatch: { describe: /#(?:unit|integration|e2e)/u.source } },
],
},
{
code: javascript`
test.describe('things to test', () => {
Expand Down Expand Up @@ -657,6 +720,17 @@ runRuleTester('title-must-be-string', rule, {
},
],
},
{
code: 'test.step(123, () => {});',
errors: [
{
column: 11,
line: 1,
messageId: 'titleMustBeString',
},
],
options: [{ ignoreTypeOfStepName: false }],
},
// Global aliases
{
code: 'it(String(/.+/), () => {});',
Expand Down Expand Up @@ -685,6 +759,7 @@ runRuleTester('title-must-be-string', rule, {
'test.describe.skip("is a string", () => {});',
'test.describe.skip(`${myFunc} is a string`, () => {});',
'test.describe("is a string", () => {});',
'test.step(123, () => {});',
{
code: 'test.describe(String(/.+/), () => {});',
options: [{ ignoreTypeOfDescribeName: true }],
Expand Down Expand Up @@ -811,6 +886,17 @@ runRuleTester('no-empty-title', rule, {
},
],
},
{
code: 'test.step(``, function () {})',
errors: [
{
column: 1,
data: { functionName: 'step' },
line: 1,
messageId: 'emptyTitle',
},
],
},
// Global aliases
{
code: 'it.describe("", function () {})',
Expand Down Expand Up @@ -840,6 +926,7 @@ runRuleTester('no-empty-title', rule, {
'test.skip(`foo`, function () {})',
'test(`${foo}`, function () {})',
'test.fixme(`${foo}`, function () {})',
'test.step(`${foo}`, function () {})',
// Global aliases
{
code: 'test.describe()',
Expand Down Expand Up @@ -969,6 +1056,21 @@ runRuleTester('no-accidental-space', rule, {
errors: [{ column: 6, line: 1, messageId: 'accidentalSpace' }],
output: 'test("foo", function () {})',
},
{
code: 'test.step(` foo bar bang `, function () {})',
errors: [{ column: 11, line: 1, messageId: 'accidentalSpace' }],
output: 'test.step(`foo bar bang`, function () {})',
},
{
code: 'test.step(" foo", function () {})',
errors: [{ column: 11, line: 1, messageId: 'accidentalSpace' }],
output: 'test.step("foo", function () {})',
},
{
code: 'test.step(" foo ", function () {})',
errors: [{ column: 11, line: 1, messageId: 'accidentalSpace' }],
output: 'test.step("foo", function () {})',
},
{
code: javascript`
test.describe(' foo', () => {
Expand Down Expand Up @@ -1013,6 +1115,8 @@ runRuleTester('no-accidental-space', rule, {
'test("foo", function () {})',
'test.describe()',
'test.describe("foo", function () {})',
'test.step()',
'test.step("foo", function () {})',
'test.only()',
'test.only("foo", function () {})',
javascript`
Expand Down Expand Up @@ -1135,6 +1239,37 @@ runRuleTester('no-duplicate-prefix test', rule, {
],
})

runRuleTester('no-duplicate-prefix step', rule, {
invalid: [
{
code: 'test.step("step foo", function () {})',
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
output: 'test.step("foo", function () {})',
},
{
code: 'test.step("step foo", function () {})',
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
output: 'test.step("foo", function () {})',
},
{
code: 'test.step("step foo", function () {})',
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
output: 'test.step("foo", function () {})',
},
{
code: "test.step('step foo', function () {})",
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
output: "test.step('foo', function () {})",
},
{
code: 'test.step(`step foo`, function () {})',
errors: [{ column: 11, line: 1, messageId: 'duplicatePrefix' }],
output: 'test.step(`foo`, function () {})',
},
],
valid: ['test.step("foo", function () {})'],
})

runRuleTester('no-duplicate-prefix nested', rule, {
invalid: [
{
Expand Down Expand Up @@ -1176,6 +1311,23 @@ runRuleTester('no-duplicate-prefix nested', rule, {
})
`,
},
{
code: javascript`
test.describe('foo', () => {
test('bar', () => {
test.step('step foobar', () => {})
})
})
`,
errors: [{ column: 15, line: 3, messageId: 'duplicatePrefix' }],
output: javascript`
test.describe('foo', () => {
test('bar', () => {
test.step('foobar', () => {})
})
})
`,
},
// Global aliases
{
code: javascript`
Expand Down
Loading