1.0.13 • Published 5 months ago

cy2pwconvert v1.0.13

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

cy2pwconvert

A command-line tool to migrate Cypress tests to Playwright, preserving directory structure and converting .js & .ts test files automatically.

šŸš€ Features

āœ… Converts Cypress .js and .ts test files to Playwright
āœ… Preserves the original folder structure
āœ… Supports custom source and target directories
āœ… CLI-based, install once and use anywhere
āœ… Error handling for missing directories


šŸ“„ Installation

1ļøāƒ£ Global Installation (Recommended)

npm install -g cy2pwconvert

2ļøāƒ£ Local Installation (Project-based)

npm install --save-dev cy2pwconvert

šŸ“Œ Usage

šŸ”„ Convert Cypress Tests (Default Paths)

cy2pwconvert

(Default: ./cypress/integration → ./playwright/tests)

šŸ“‚ Convert with Custom Source & Target Directories

cy2pwconvert ./my-cypress-tests ./my-playwright-tests

šŸ†˜ Help

cy2pwconvert --help

Options

Usage: npx cy2pwconvert .cypress/ tests/

Arguments:
  src                                            Source file or folder
  dst                                            Target file or folder

Options:
  -V, --version                                  output the version number
  -ft, --filetype <filetype>                     File types to convert default: .js, example: .js,.ts, current support: .js,.ts,.jsx (default: ".js,.ts")
  -idp, --installDependency <installDependency>  Installs Dependency after project clone (default: false)
  -sC, --skipConfig <skipConfig>                 Skips the config conversion from cypress to playwright (default: true)
  -ep, --enablePlugins <enablePlugins>           If enabled, this packages takes plugins from babel config file or package file, which comes under plugins key. (default:
                                                 false)
  -ep, --preserveBDD <preserveBDD>               This option will help you to preserve bdd being converted to tdd (default: true)
  -h, --help                                     display help for command

šŸ”§ How It Works

  • Replaces Cypress commands (cy.visit(), cy.get(), etc.) with Playwright equivalents.
  • Ensures async/await syntax for Playwright compatibility.
  • Converts all .js and .ts test files while maintaining directory structure.
  • Converts you Cypress config to Playwright config

šŸ“– Example

Before (Cypress Test)

describe('Login', () => {
  it('should log in successfully', () => {
    cy.visit('/login');
    cy.get('#username').type('admin');
    cy.get('#password').type('password');
    cy.contains('Submit').click();
    cy.get('.dashboard').should('be.visible');
  });
});

After (Playwright Test)

test.describe('Login', async ({ page }) => {
  test('should log in successfully', async ({ page }) => {
    await page.goto('/login');
    await page.locator('#username').fill('admin');
    await page.locator('#password').fill('password');
    await page.getByText('Submit').click();
    await expect(page.locator('.dashboard')).toBeVisible();
  });
});

šŸ›  Supported Cypress → Playwright Config Mappings

āœ… Supports all Cypress config formats:

  • cypress.config.js
  • cypress.config.json
  • cypress.config.ts (via ts-node)

āœ… Merges into existing playwright.config.ts

  • If the Playwright config already has settings, it preserves them while adding the new ones.

āœ… Creates a new Playwright config if missing

āœ… Supports both Playwright JS & TS configs:

  • Detects if playwright.config.ts or playwright.config.js exists.
  • Merges Cypress settings into the correct file.

āœ… Handles missing Playwright config:

  • If no playwright.config.ts/js exists, it creates a new one based on the detected Cypress format.

āœ… Automatically formats with Prettier


šŸ›  Development & Contributions

šŸ”§ Local Development

Clone the repo:

git clone git@github.com:arunchaitanyajami/cy2pwconvert.git
cd cy2pwconvert
npm install

šŸ”— Link for Local Testing

npm link
cy2pwconvert ./cypress/integration ./playwright/tests

Foundation

I took the inspiration from cy2pw package. Copied the code and added additional features on top of this code.

Open Source Packages : https://www.npmjs.com/package/cy2pw

šŸ“ License

MIT License. Feel free to contribute! šŸš€

Version Update

v1.0.13

  • Support Cypress custom commands.
  • Cucumber: Move away from Regx to Babel plugin.
1.0.13

5 months ago

1.0.12

5 months ago

1.0.11

5 months ago

1.0.10

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago