Files
wp-plugin-starter-template-…/.wiki/Testing-Framework.md
marcusquinn f6d30e92d0 Fix additional Markdown line lengths for Codacy compliance
- Break long prose lines to under 120 characters
- Improve readability of documentation
- URLs and ASCII art diagrams left unchanged (cannot be shortened)
2025-11-24 22:12:43 +00:00

3.0 KiB

WordPress Plugin Testing Framework

This document outlines how to set up and run tests for our plugin.

It covers both single site and multisite WordPress environments.

Overview

Our plugin is designed to work with both standard WordPress installations and WordPress Multisite.

This testing framework allows you to verify functionality in both environments.

Setting Up the Test Environment

We use @wordpress/env and Cypress for testing our plugin.

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • Docker and Docker Compose

Installation

  1. Clone the repository:

    git clone https://github.com/wpallstars/wp-plugin-starter-template-for-ai-coding.git
    cd wp-plugin-starter-template-for-ai-coding
    
  2. Install dependencies:

    npm install
    

Testing in Single Site WordPress

  1. Set up the single site environment:

    npm run setup:single
    

    This will:

    • Start a WordPress environment using wp-env
    • Activate our plugin
  2. Run Cypress tests for single site:

    npm run test:single
    

    For headless testing:

    npm run test:single:headless
    
  3. Access the site manually:

Testing in WordPress Multisite

  1. Set up the multisite environment:

    npm run setup:multisite
    

    This will:

    • Start a WordPress environment using wp-env
    • Configure it as a multisite installation
    • Create a test subsite
    • Network activate our plugin
  2. Run Cypress tests for multisite:

    npm run test:multisite
    

    For headless testing:

    npm run test:multisite:headless
    
  3. Access the sites manually:

Continuous Integration

We use GitHub Actions to automatically run tests on pull requests.

The workflow is defined in .github/workflows/wordpress-tests.yml and runs tests in both environments.

Writing Tests

Single Site Tests

Add new single site tests to cypress/e2e/single-site.cy.js.

Multisite Tests

Add new multisite tests to cypress/e2e/multisite.cy.js.

Troubleshooting

Common Issues

  1. Database connection errors: Make sure Docker is running and ports 8888 and 8889 are available.

  2. Multisite conversion fails: Check the wp-env logs for details:

    wp-env logs
    
  3. Plugin not activated: Run the following command:

    # For single site
    wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding
    
    # For multisite
    wp-env run cli wp plugin activate wp-plugin-starter-template-for-ai-coding --network
    

Getting Help

If you encounter any issues, please open an issue on our GitHub repository with:

  • A description of the problem
  • Steps to reproduce
  • Any error messages
  • Your environment details (OS, Node.js version, etc.)