Skip to content

jabranr/eslint-plugin-catchpoint-playwright

Repository files navigation

ESLint Plugin for Catchpoint Playwright

An ESLint plugin that enforces restrictions on Playwright APIs to ensure compatibility with Catchpoint's testing environment.

Features

This plugin provides two custom ESLint rules:

  1. no-restricted-catchpoint-playwright-imports - Prevents importing specific Playwright types that are not supported in Catchpoint tests
  2. no-restricted-catchpoint-playwright-properties - Prevents using specific page and browser properties that are not supported in Catchpoint tests

Installation

npm install eslint-plugin-catchpoint-playwright --save-dev

Compatibility

This plugin supports:

  • ESLint v7.x, v8.x, v9.x
  • Node.js 14+

Usage

ESLint v9+ (Flat Config)

For the new flat config format in ESLint 9+:

// eslint.config.js
import catchpointPlaywright from 'eslint-plugin-catchpoint-playwright';

export default [
  {
    plugins: {
      'catchpoint-playwright': catchpointPlaywright
    },
    rules: {
      ...catchpointPlaywright.configs['flat/recommended'].rules
    }
  }
];

ESLint v7 & v8 (Legacy Config)

For traditional .eslintrc.* configuration files:

{
  "plugins": ["catchpoint-playwright"],
  "extends": ["plugin:catchpoint-playwright/recommended"]
}

Or in .eslintrc.js:

module.exports = {
  plugins: ['catchpoint-playwright'],
  extends: ['plugin:catchpoint-playwright/recommended']
};

Manual Configuration

You can also configure individual rules:

{
  "plugins": ["catchpoint-playwright"],
  "rules": {
    "catchpoint-playwright/no-restricted-catchpoint-playwright-imports": "error",
    "catchpoint-playwright/no-restricted-catchpoint-playwright-properties": "error"
  }
}

Rules

no-restricted-catchpoint-playwright-imports

Prevents importing the following types from @playwright/test as they are not supported in Catchpoint tests:

  • Browser
  • BrowserContext
  • BrowserServer
  • BrowserType

❌ Invalid:

import { Browser, BrowserContext } from '@playwright/test';

✅ Valid:

import { test, expect, Page } from '@playwright/test';

no-restricted-catchpoint-playwright-properties

Prevents using the following page and browser properties that are not supported in Catchpoint tests:

Page properties:

  • addInitScript()
  • close()
  • pdf()
  • routeFromHAR()
  • screenshot()
  • setDefaultNavigationTimeout()
  • setDefaultTimeout()
  • video
  • workers
  • context

Browser properties:

  • newContext()

❌ Invalid:

await page.screenshot();
await page.close();
const context = browser.newContext();

✅ Valid:

await page.goto('https://example.com');
await page.click('button');
await page.fill('input', 'value');

Example

Here's a complete example of a Catchpoint-compatible Playwright test:

import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
  // ✅ Supported operations
  await page.goto('https://example.com');
  await page.click('button#submit');
  await page.fill('input[name="username"]', 'testuser');

  const title = await page.title();
  expect(title).toBe('Example Page');

  // ❌ These would trigger ESLint errors:
  // await page.screenshot(); // Not supported in Catchpoint
  // await page.close(); // Not supported in Catchpoint
});

Development

This project uses:

  • TypeScript for type safety
  • Vitest for testing
  • ESLint for code quality

Running Tests

npm test

Building

npm run build

License

MIT

© 2025 - Jabran Rafique