-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Better scope for no-skipped-tests * Add examples folder for testing * Better scope for no-useless-not * max-nested-describe * missing-playwright-await * no-focused-test * no-force-option * no-page-pause * no-restricted-matchers * Update ecma version * no-wait-for-timeout * prefer-lowercase-title * prefer-strict-equal * prefer-to-be * prefer-to-have-length * require-top-level-describe * valid-expect * no-conditional-in-test * Update example eslintrc * no-eval * Cleanup * no-element-handle * Order * Use dedent * Update examples * Docs * Finish rule * Update docs
- Loading branch information
Showing
6 changed files
with
115 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Require soft assertions (`require-soft-assertions`) | ||
|
||
Some find it easier to write longer test that perform more assertions per test. | ||
In cases like these, it can be helpful to require | ||
[soft assertions](https://playwright.dev/docs/test-assertions#soft-assertions) | ||
in your tests. | ||
|
||
This rule is not enabled by default and is only intended to be used it if fits | ||
your workflow. If you aren't sure if you should use this rule, you probably | ||
shouldn't 🙂. | ||
|
||
## Rule Details | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```javascript | ||
await expect(page.locator('foo')).toHaveText('bar'); | ||
await expect(page).toHaveTitle('baz'); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```javascript | ||
await expect.soft(page.locator('foo')).toHaveText('bar'); | ||
await expect.soft(page).toHaveTitle('baz'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Rule } from 'eslint'; | ||
import { getExpectType } from '../utils/ast'; | ||
|
||
export default { | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if (getExpectType(node) === 'standalone') { | ||
context.report({ | ||
node: node.callee, | ||
messageId: 'requireSoft', | ||
fix: (fixer) => fixer.insertTextAfter(node.callee, '.soft'), | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
meta: { | ||
docs: { | ||
description: 'Require all assertions to use `expect.soft`', | ||
recommended: false, | ||
url: 'https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/require-soft-assertions.md', | ||
}, | ||
messages: { | ||
requireSoft: 'Unexpected non-soft assertion', | ||
}, | ||
fixable: 'code', | ||
type: 'suggestion', | ||
schema: [], | ||
}, | ||
} as Rule.RuleModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import rule from '../../src/rules/require-soft-assertions'; | ||
import { runRuleTester } from '../utils/rule-tester'; | ||
|
||
const messageId = 'requireSoft'; | ||
|
||
runRuleTester('require-soft-assertions', rule, { | ||
valid: [ | ||
'expect.soft(page).toHaveTitle("baz")', | ||
'expect.soft(page.locator("foo")).toHaveText("bar")', | ||
'expect["soft"](foo).toBe("bar")', | ||
'expect[`soft`](bar).toHaveText("bar")', | ||
'expect.poll(() => foo).toBe("bar")', | ||
'expect["poll"](() => foo).toBe("bar")', | ||
'expect[`poll`](() => foo).toBe("bar")', | ||
], | ||
invalid: [ | ||
{ | ||
code: 'expect(page).toHaveTitle("baz")', | ||
output: 'expect.soft(page).toHaveTitle("baz")', | ||
errors: [{ messageId, line: 1, column: 1, endColumn: 7 }], | ||
}, | ||
{ | ||
code: 'expect(page.locator("foo")).toHaveText("bar")', | ||
output: 'expect.soft(page.locator("foo")).toHaveText("bar")', | ||
errors: [{ messageId, line: 1, column: 1, endColumn: 7 }], | ||
}, | ||
{ | ||
code: 'await expect(page.locator("foo")).toHaveText("bar")', | ||
output: 'await expect.soft(page.locator("foo")).toHaveText("bar")', | ||
errors: [{ messageId, line: 1, column: 7, endColumn: 13 }], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters