• Stars
    star
    225
  • Rank 171,421 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ESLint plugin for Playwright

ESLint Plugin Playwright

Test npm semantic-release

ESLint plugin for Playwright.

Installation

npm

npm install -D eslint-plugin-playwright

Yarn

yarn add -D eslint-plugin-playwright

pnpm

pnpm add -D eslint-plugin-playwright

Usage

This plugin bundles two configurations to work with both @playwright/test or jest-playwright.

With Playwright test runner

{
  "extends": ["plugin:playwright/recommended"]
}

With Jest Playwright

{
  "extends": ["plugin:playwright/jest-playwright"]
}

Global Settings

The plugin reads global settings from your ESLint configuration's shared data under the playwright key. It supports the following settings:

  • additionalAssertFunctionNames: an array of function names to treat as assertion functions for the case of rules like expect-expect, which enforces the presence of at least one assertion per test case. This allows such rules to recognise custom assertion functions as valid assertions. The global setting applies to all modules. The expect-expect rule accepts an option by the same name to enable per-module configuration (.e.g, for module-specific custom assert functions).

You can configure these settings like so:

{
  "settings": {
    "playwright": {
      "additionalAssertFunctionNames": ["assertCustomCondition"]
    }
  }
}

List of Supported Rules

βœ”: Enabled in the recommended configuration.
πŸ”§: Some problems reported by this rule are automatically fixable by the --fix command line option.
πŸ’‘: Some problems reported by this rule are manually fixable by editor suggestions.

βœ” πŸ”§ πŸ’‘ Rule Description
βœ” expect-expect Enforce assertion to be made in a test body
βœ” max-nested-describe Enforces a maximum depth to nested describe calls
βœ” πŸ”§ missing-playwright-await Enforce Playwright APIs to be awaited
βœ” no-conditional-in-test Disallow conditional logic in tests
βœ” πŸ’‘ no-element-handle Disallow usage of element handles
βœ” no-eval Disallow usage of page.$eval and page.$$eval
βœ” πŸ’‘ no-focused-test Disallow usage of .only annotation
βœ” no-force-option Disallow usage of the { force: true } option
βœ” no-nested-step Disallow nested test.step() methods
βœ” no-networkidle Disallow usage of the networkidle option
no-nth-methods Disallow usage of first(), last(), and nth() methods
βœ” no-page-pause Disallow using page.pause
βœ” πŸ”§ no-useless-await Disallow unnecessary awaits for Playwright methods
no-restricted-matchers Disallow specific matchers & modifiers
βœ” πŸ’‘ no-skipped-test Disallow usage of the .skip annotation
βœ” πŸ”§ no-useless-not Disallow usage of not matchers when a specific matcher exists
βœ” πŸ’‘ no-wait-for-timeout Disallow usage of page.waitForTimeout
πŸ’‘ prefer-strict-equal Suggest using toStrictEqual()
πŸ”§ prefer-lowercase-title Enforce lowercase test names
πŸ”§ prefer-to-be Suggest using toBe()
πŸ”§ prefer-to-contain Suggest using toContain()
πŸ”§ prefer-to-have-length Suggest using toHaveLength()
βœ” πŸ”§ prefer-web-first-assertions Suggest using web first assertions
require-top-level-describe Require test cases and hooks to be inside a test.describe block
πŸ”§ require-soft-assertions Require assertions to use expect.soft()
βœ” valid-expect Enforce valid expect() usage