Synpress Documentation

repository·dev·Indexed 21 days ago

https://github.com/synpress-io/synpress

A developer-friendly E2E testing library for Web3 dApps that extends Cypress and Playwright. It features a 'New Dawn' caching mechanism to store browser state and wallet setups (such as MetaMask and Phantom), enabling faster and parallel test execution. The library includes support for Anvil, full TypeScript integration, and a dedicated CLI for managing browser cache operations.

Tokens
23.7K
Snippets
89
Records
116
Agent score
75%

What's inside Synpress

  1. Overview of Synpress features

    dev

    Synpress is an E2E testing library for Web3 dApps built on top of Cypress and Playwright. It is designed to simplify testing blockchain-specific operations and wallet interactions (like MetaMask).

    Key features include:

    • Framework Support: Works with both Playwright and Cypress.
    • Browser State Caching: Define wallet setup once and cache the browser state to enable fast, parallel testing.
    • Wallet & Blockchain Agnostic: The core system is designed to support various wallets and blockchains.
    • MetaMask Integration: Deep integration for seamless dApp interaction testing.
    • Anvil Support: Ability to spin up a local Anvil node with a single line of code for isolated testing.
    • TypeScript Support: Full TypeScript support for type safety.
  2. Understand the Synpress 'New Dawn' caching model

    dev

    The 'New Dawn' version of Synpress introduces a caching mechanism for browser sessions. Instead of setting up the browser for every test, the browser is set up once and cached. This allows for faster test execution and enables the use of all Playwright features, including parallel testing.

    To use this model, you must define setup files using the naming convention *.setup.{js,ts}. These files define how the browser and wallet should be initialized. Once defined, you use the Synpress CLI to build the cache.

  3. How the Synpress New Dawn caching mechanism works

    dev

    Unlike previous versions, Synpress New Dawn sets up the browser only once and caches it. This approach enables faster test execution and allows for the use of all Playwright features, including parallel testing.

    To use this mechanism, you must define a setup file using the naming convention *.setup.{js,ts} (for example, in a test/wallet-setup directory). Once defined, you use the Synpress CLI to build the cache based on these setup files.

  4. Set up the MetaMask Example Project

    dev

    To run the MetaMask example project, follow these steps in order:

    1. Install dependencies: Use pnpm install.
    2. Start the MetaMask Test Dapp: Run pnpm run serve:test-dapp.
    3. Install Playwright: Run pnpm exec playwright install.
      • Note: If you don't have Anvil installed, you must install Foundry first.
    4. Build the cache: Use the provided scripts to build the browser cache:
      • Headed: pnpm run build:cache
      • Headless: pnpm run build:cache:headless.
    5. Run tests: Execute Playwright tests using the project scripts or the Playwright CLI.
    # 1. Install dependencies
    pnpm install 
    
    # 2. Start MetaMask Test Dapp
    pnpm run serve:test-dapp
    
    # 3. Install Playwright
    pnpm exec playwright install  
    
    # 4. Build cache
    pnpm run build:cache
    
    # 5. Run tests
    pnpm run test:playwright:headful
  5. Run Playwright tests in the example project

    dev

    You can run tests using the project's pre-defined scripts or by calling the playwright CLI directly.

    Note: Currently, tests are triggered in headed mode by default. To run them in headless mode, you must explicitly set the HEADLESS=true environment variable.

    # Using project scripts:
    pnpm run test:playwright:headful
    pnpm run test:playwright:headless
    pnpm run test:playwright:headless:ui
    
    # Using Playwright directly:
    playwright test
    HEADLESS=true playwright test
    HEADLESS=true playwright test --ui
  6. Use the Synpress Support Bot in Discord

    dev

    Once the bot is running, follow these steps to interact with it:

    1. Create a Channel: Create a channel named support-bot in your Discord server. The bot is configured to only respond within this specific channel.
    2. Ask a Question: Mention the bot (e.g., @BotName) in the support-bot channel followed by your Synpress-related question.

    Operational Constraints

    • Response Limits: Responses are limited to 1900 characters. If a response exceeds this, the bot will automatically split it into multiple messages.
    • Concurrency: The bot uses a processing lock to handle only one request at a time to maintain response quality.
    # To run the bot in development mode
    pnpm dev
    
    # To run the bot in production mode
    pnpm start
  7. Set up the Synpress Support Bot

    dev

    The Synpress Support Bot is a Discord bot powered by Google's Gemini AI that answers questions about the Synpress codebase.

    Prerequisites

    • Node.js 18 or higher
    • pnpm package manager
    • A Discord Bot Token (from the Discord Developer Portal)
    • A Google Cloud API Key with Gemini AI access
    • A file named synpress-source.txt in the root directory containing the Synpress codebase (required for the bot to answer questions).

    Installation and Build

    1. Copy the environment template:
      cp .env.example .env
    2. Configure your .env file with the following keys:
      • DISCORD_BOT_TOKEN: Your Discord bot token.
      • CLOUD_API_KEY: Your Google Cloud API key.
    3. Install dependencies:
      pnpm install
    4. Build the project:
      pnpm build
    cp .env.example .env
    pnpm install
    pnpm build
  8. Run Playwright tests in the MetaMask example

    dev

    Once the cache is built, you can run tests using either the predefined npm scripts or the Playwright CLI directly.

    Note on Headless Mode: Currently, tests are triggered in headed mode by default. To run in headless mode, you must explicitly set the HEADLESS=true environment variable.

    # Using project scripts:
    pnpm run test:playwright:headful
    pnpm run test:playwright:headless
    pnpm run test:playwright:headless:ui
    
    # Using Playwright directly:
    playwright test
    HEADLESS=true playwright test
    HEADLESS=true playwright test --ui
  9. Deploy packages using Changesets

    dev

    To release new versions of packages in the repository, follow this sequence of commands from the root directory. This process uses changesets to manage versioning and publishing.

    1. Select packages: Run pnpm changeset to choose which packages to release.
    2. Version packages: Run pnpm changeset version to consume the changesets and update package.json and CHANGELOG.md files.
    3. Verify: Manually inspect all modified package.json and CHANGELOG.md files.
    4. Build root: Run pnpm build from the root directory.
    5. Build release assets: Run pnpm build inside the ./release/ directory.
    6. Commit: Commit the versioning changes.
    7. Publish: Run pnpm changeset publish to publish the packages. Note: If the @synthetixio/synpress package fails to publish on the first attempt, you may need to run this command a second time.
    8. Update dependencies: Run pnpm i to update the lockfile.
    9. Final commit: Commit the updated lockfile.
    pnpm changeset
    pnpm changeset version
    pnpm build
    pnpm changeset publish
  10. Set up the Ethereum Wallet Mock example project

    dev

    Follow these steps to get the example project running locally:

    1. Install dependencies: Use pnpm install.
    2. Start the MetaMask Test Dapp: Run pnpm run serve:test-dapp.
    3. Install Playwright: Run pnpm exec playwright install.
    4. Ensure Anvil is installed: If you don't have Anvil, follow the Foundry installation guide.
    5. Build the cache: Use the provided scripts to build the cache in either headed or headless mode.
    6. Run tests: Execute Playwright tests using the provided scripts or the Playwright CLI directly.
    # 1. Install dependencies
    pnpm install 
    
    # 2. Start MetaMask Test Dapp
    pnpm run serve:test-dapp
    
    # 3. Install Playwright
    pnpm exec playwright install  
    
    # 4. Build cache
    pnpm run build:cache
    
    # 5. Run tests
    pnpm run test:playwright:headful
  11. Use @synthetixio/synpress-tsconfig for base TypeScript configurations

    dev
    The @synthetixio/synpress-tsconfig package provides standardized base tsconfig.json files used across the Synpress monorepo. These configurations are designed to be inherited by other packages to ensure consistent TypeScript compiler settings. The base configurations are derived from the 'Total TypeScript' cheat sheet and the strictest configurations from tsconfig/bases.