Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Mark several recommended Playwright rules as errors instead of warnings",
"packageName": "@ni/eslint-config-playwright",
"email": "jattasNI@users.noreply.github.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions packages/eslint-config-playwright/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ export const playwrightConfig = defineConfig([
*/
'no-await-in-loop': 'off',

/*
Playwright marks this as recommended but configures it as 'warn'.
A test without an assertion can't fail on incorrect behavior, so it gives a false sense of coverage.
*/
'playwright/expect-expect': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Deeply nested describe blocks are likely an indication that test files are too complicated.
*/
'playwright/max-nested-describe': 'error',

/*
Commented out tests are easy to forget about and lose coverage silently.
Use a skipped test accompanied by a comment linking to a work item instead.
*/
'playwright/no-commented-out-tests': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
An assertion that is conditionally skipped can cause a test to pass without verifying anything.
*/
'playwright/no-conditional-expect': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Conditional logic in tests is usually an indication that a test is attempting to cover too much, and not testing the logic it intends to.
Expand All @@ -47,6 +65,12 @@ export const playwrightConfig = defineConfig([
*/
'playwright/no-force-option': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Identical titles make it hard to tell which test failed and can cause tests to be filtered or reported incorrectly.
*/
'playwright/no-identical-title': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Using page.pause should be reserved for debugging, not production code.
Expand All @@ -60,23 +84,53 @@ export const playwrightConfig = defineConfig([
*/
'playwright/no-skipped-test': 'off',

/*
Playwright marks this as recommended but configures it as 'warn'.
Awaiting a value that is not a promise is unnecessary and misleading about what is asynchronous.
*/
'playwright/no-useless-await': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Assertions are easier to read when using a dedicated matcher rather than negating the opposite matcher.
*/
'playwright/no-useless-not': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
page.waitForSelector is discouraged. Instead use locators with web-first assertions, which wait automatically.
*/
'playwright/no-wait-for-selector': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Waiting for arbitrary amounts of time can cause test intermittency. Instead wait for a specific condition.
*/
'playwright/no-wait-for-timeout': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
Locators are auto-waiting and retryable. Instead of page methods like page.click use page.locator().click().
*/
'playwright/prefer-locator': 'error',

/*
Playwright marks this as recommended but configures it as 'warn'.
toHaveCount() retries until the count matches, which avoids intermittency compared to asserting on locator.count().
*/
'playwright/prefer-to-have-count': 'error',

/*
In order to have a better failure message, toHaveLength() should be used when asserting expectations on objects length property.
*/
'playwright/prefer-to-have-length': 'error',

/*
Skipped tests are allowed (see no-skipped-test) but must explain why they are skipped.
The reason should link to a work item that tracks re-enabling the test.
*/
'playwright/require-annotation-reason': 'error',

/*
Having a top-level describe block in each test file is common practice which aligns with patterns we use in Jasmine
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"peerDependencies": {
"@ni/eslint-config-typescript": "^5.0.7",
"@ni/eslint-config-javascript": "^5.2.0",
"eslint-plugin-playwright": "^2.10.2"
"eslint-plugin-playwright": "^2.12.0"
}
}
Loading