1.0.5 • Published 12 months ago

playwright-cleanup-queue v1.0.5

Weekly downloads
-
License
MIT License
Repository
github
Last release
12 months ago

npm version

playwright-cleanup-queue simplifies resource cleanup in Playwright tests by allowing you to register cleanup tasks for individual tests. This is beneficial for complex test setups, enabling you to teardown only the resources that were created in case a test fails. Cleanup tasks are executed in reverse order of their registration, ensuring that interdependent resources can be cleaned up correctly.

Features

  • register cleanup tasks for individual tests
  • cleanup tasks are executed in reverse order of registration
  • failure to cleanup will fail the test case

Installation

You can install playwright-cleanup-queue using npm:

npm install playwright-cleanup-queue --save-dev

Or with yarn:

yarn add playwright-cleanup-queue --dev

Usage

Import the cleanup fixture and the CleanupQueue type from the playwright-cleanup-queue package.

import { cleanup, CleanupQueue } from 'playwright-cleanup-queue'

Extend Playwright's base test to include the cleanup fixture and add the CleanupQueue type as a type parameter.

import { test as base } from '@playwright/test'

export const test = base.extend<CleanupQueue>({
  cleanup
})

Write your tests and use the cleanup fixture to register cleanup tasks. Each task will be executed after the test completes, in reverse order of their registration.

import { test } from './fixtures'

test('should create todo and comment', async ({ page, cleanup }) => {
  const todo = await createTodo()
  cleanup(() => todo.delete())

  comment = todo.addComment()
  cleanup(() => comment.delete())

  /* ... */
})

Typescript support

Typescript is supported for this project.

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago