Skip to content

refactor: split transformer.ts into smaller modules #1

Description

@barispe

Problem

src/transformer.ts is currently 2,303 lines - the largest file in the codebase by far. It handles all Cypress-to-Playwright chain conversions in a single file, making it difficult to navigate, test, and maintain.

Proposed Solution

Split transformer.ts into focused, single-responsibility modules:

Suggested structure

src/ transformer/ index.ts # Public API (transformFile, parseCustomCommands) chain-converter.ts # convertCypressChain - the core dispatch logic chains/ get-chain.ts # convertGetChain (~300 lines) url-chain.ts # convertUrlChain (~50 lines) title-chain.ts # convertTitleChain (~40 lines) cy-on.ts # convertCyOn (~70 lines) cy-stub.ts # convertCyStub (~90 lines) cy-request.ts # convertCyRequest (~290 lines) assertions/ should-converter.ts # convertShouldAssertion (~100 lines) blocks/ block-accumulator.ts # accumulateBlock intercept-handler.ts # convertCyIntercept wait-handler.ts # convertCyWait each-handler.ts # convertCyEach window-handler.ts # convertCyWindow within-handler.ts # convertCyWithin custom-commands.ts # CustomCommandDef, parseCustomCommands types.ts # ChainCall, ChainConversionResult, etc. utils.ts # Shared helpers (quote stripping, indent, etc.)

Benefits

  • Readability: Each file is focused on one conversion type
  • Testability: Individual chain converters can be unit tested in isolation
  • Maintainability: Adding new chain converters doesn't bloat a single file
  • Discoverability: New contributors can find what they need quickly

Migration Plan

  1. Create the src/transformer/ directory structure
  2. Extract chain converters one at a time (start with the smallest)
  3. Keep the public API (transformFile, parseCustomCommands) stable via re-exports from index.ts
  4. Update imports across the codebase
  5. Run full test suite after each extraction to verify nothing breaks

Acceptance Criteria

  • No single file exceeds ~400 lines
  • All existing tests pass without modification
  • Public API remains unchanged (no breaking import changes for consumers)
  • Each extracted module has clear JSDoc comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions