From 0c4e91fcec7141823257e1b135c755c51b4c8487 Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Tue, 22 Apr 2025 22:30:31 +0100 Subject: [PATCH] Fix code quality issues and GitHub Actions workflows --- .eslintrc.json | 1 + .github/workflows/playground-tests-fix.yml | 12 +++++----- .github/workflows/playground-tests.yml | 11 +++++---- .github/workflows/wordpress-tests.yml | 28 ++++++++++++++++------ .wiki/Testing.md | 17 +++++++++++-- cypress/e2e/playground-multisite.cy.js | 4 ++++ cypress/e2e/playground-single-site.cy.js | 1 + includes/Multisite/README.md | 2 +- package.json | 5 ++-- playground/test.html | 2 ++ 10 files changed, 61 insertions(+), 22 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 4a42e06..81c5c6d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,6 +14,7 @@ "describe": "readonly", "it": "readonly", "before": "readonly", + "beforeEach": "readonly", "module": "readonly" }, "parserOptions": { diff --git a/.github/workflows/playground-tests-fix.yml b/.github/workflows/playground-tests-fix.yml index e83beda..a0a1578 100644 --- a/.github/workflows/playground-tests-fix.yml +++ b/.github/workflows/playground-tests-fix.yml @@ -2,12 +2,15 @@ name: WordPress Playground Tests Fix on: push: - branches: [ main, feature/*, bugfix/* ] + branches: [ main ] pull_request: branches: [ main ] +permissions: + contents: read + concurrency: - group: playground-tests-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: @@ -31,10 +34,7 @@ jobs: run: npm install --save-dev @wp-playground/cli - name: Create plugin zip - run: | - mkdir -p dist - zip -r dist/plugin.zip . \ - -x "node_modules/**" "dist/**" ".git/**" ".github/**" ".wiki/**" + uses: ./.github/actions/create-plugin-zip - name: Run tests with WordPress Playground run: | diff --git a/.github/workflows/playground-tests.yml b/.github/workflows/playground-tests.yml index d9cd7d9..fa56f19 100644 --- a/.github/workflows/playground-tests.yml +++ b/.github/workflows/playground-tests.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ main ] +permissions: + contents: read + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -111,15 +114,15 @@ jobs: - name: Run tests with WordPress Playground run: | # Set base URL for Cypress - export CYPRESS_BASE_URL=http://localhost:80 + export CYPRESS_BASE_URL=http://localhost:8889 # Start WordPress Playground with our blueprint - # Use port 80 for multisite to avoid port configuration issues with WP Playground CLI - npx @wp-playground/cli server --blueprint playground/multisite-blueprint.json --port 80 --login & + # Use a different port for multisite to avoid conflicts with single site tests + npx @wp-playground/cli server --blueprint playground/multisite-blueprint.json --port 8889 --login & # Wait for WordPress Playground to be ready echo "Waiting for WordPress Playground to be ready..." - timeout 60 bash -c 'until curl -s http://localhost:80; do sleep 2; done' + timeout 60 bash -c 'until curl -s http://localhost:8889; do sleep 2; done' # Run Cypress tests against WordPress Playground npx cypress run --spec "cypress/e2e/playground-multisite.cy.js" diff --git a/.github/workflows/wordpress-tests.yml b/.github/workflows/wordpress-tests.yml index 28328c5..361b5c3 100644 --- a/.github/workflows/wordpress-tests.yml +++ b/.github/workflows/wordpress-tests.yml @@ -2,10 +2,17 @@ name: WordPress Tests on: push: - branches: [ main, feature/*, bugfix/* ] + branches: [ main ] pull_request: branches: [ main ] +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: code-quality: name: Code Quality Check @@ -61,21 +68,28 @@ jobs: run: npm ci - name: Install WordPress Playground CLI - run: npm install -g @wordpress/playground-tools + run: npm install --save-dev @wp-playground/cli - name: Create plugin zip - run: | - mkdir -p dist - zip -r dist/plugin.zip . -x "node_modules/*" "dist/*" ".git/*" + uses: ./.github/actions/create-plugin-zip - name: Run tests with WordPress Playground run: | # Start WordPress Playground with our blueprint - wp-playground start --blueprint playground/blueprint.json --port 8888 & + npx @wp-playground/cli server --blueprint playground/blueprint.json --port 8888 --login & # Wait for WordPress Playground to be ready echo "Waiting for WordPress Playground to be ready..." timeout 60 bash -c 'until curl -s http://localhost:8888; do sleep 2; done' # Run tests against WordPress Playground - npm run test:playground:single + npx cypress run --spec "cypress/e2e/playground-single-site.cy.js" + + - name: Upload Cypress artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: cypress-results + path: | + cypress/videos + cypress/screenshots diff --git a/.wiki/Testing.md b/.wiki/Testing.md index 994ab90..e2ec10e 100644 --- a/.wiki/Testing.md +++ b/.wiki/Testing.md @@ -2,14 +2,26 @@ This document explains how to use the testing framework for our plugin. +## Table of Contents + +* [Overview](#overview) +* [Prerequisites](#prerequisites) +* [Testing Approaches](#testing-approaches) + * [wp-env Approach](#1-wp-env-approach) + * [WordPress Playground Approach](#2-wordpress-playground-approach) +* [Writing Tests](#writing-tests) +* [CI/CD Integration](#cicd-integration) +* [Troubleshooting](#troubleshooting) +* [Future Improvements](#future-improvements) + ## Overview Our testing framework uses: See also: -* [.wiki/Architecture-Overview.md](Architecture-Overview.md) – high-level design -* [.wiki/Multisite-Development.md](Multisite-Development.md) – deeper multisite guidance +* [Architecture Overview](Architecture-Overview.md) – high-level design +* [Multisite Development](Multisite-Development.md) – deeper multisite guidance Components: @@ -199,3 +211,4 @@ We have GitHub Actions workflows for running tests in CI/CD: 1. **PHPUnit tests**: Add unit tests for PHP code 2. **Performance tests**: Add performance testing 3. **Accessibility tests**: Add accessibility testing + diff --git a/cypress/e2e/playground-multisite.cy.js b/cypress/e2e/playground-multisite.cy.js index 58f8633..0c3ba5d 100644 --- a/cypress/e2e/playground-multisite.cy.js +++ b/cypress/e2e/playground-multisite.cy.js @@ -8,6 +8,8 @@ describe('WordPress Playground Multisite Tests', () => { it('Can access the site', () => { // Check if the page loaded cy.get('body').should('exist'); + cy.get('h1').should('exist'); + cy.title().should('include', 'WordPress'); }); it('Can access the network admin area', () => { @@ -19,6 +21,8 @@ describe('WordPress Playground Multisite Tests', () => { // Check if we're logged in to the network admin cy.get('#wpadminbar').should('exist'); + cy.get('#wpbody-content').should('exist'); + cy.title().should('include', 'Network Admin'); }); it('Plugin is network activated', () => { diff --git a/cypress/e2e/playground-single-site.cy.js b/cypress/e2e/playground-single-site.cy.js index a865ca3..d50e3df 100644 --- a/cypress/e2e/playground-single-site.cy.js +++ b/cypress/e2e/playground-single-site.cy.js @@ -40,5 +40,6 @@ describe('WordPress Playground Single Site Tests', () => { // Check if the settings page exists cy.get('#wpbody-content').should('exist'); cy.get('h1').should('be.visible'); + cy.title().should('include', 'Settings'); }); }); diff --git a/includes/Multisite/README.md b/includes/Multisite/README.md index e4f8a66..0095474 100644 --- a/includes/Multisite/README.md +++ b/includes/Multisite/README.md @@ -21,4 +21,4 @@ if ( is_multisite() ) { ## Testing -For information on testing your plugin in a multisite environment, see the [Testing Framework](../../.wiki/Testing-Framework.md) documentation. +For information on testing your plugin in a multisite environment, see the [Testing Framework](../../.wiki/Testing.md) documentation. diff --git a/package.json b/package.json index 81c2f38..ea98d29 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "test:multisite:headless": "cypress run --config specPattern=cypress/e2e/multisite.cy.js", "test:e2e:single": "npm run setup:single && sleep 5 && npm run test:single:headless", "test:e2e:multisite": "npm run setup:multisite && sleep 5 && npm run test:multisite:headless", - "test:playground:single": "cypress run --config specPattern=cypress/e2e/single-site.cy.js", - "test:playground:multisite": "cypress run --config specPattern=cypress/e2e/multisite.cy.js", + "test:playground:single": "cypress run --spec cypress/e2e/playground-single-site.cy.js", + "test:playground:multisite": "cypress run --spec cypress/e2e/playground-multisite.cy.js", "build": "./build.sh", "lint:php": "composer run-script phpcs", "lint:php:simple": "composer run-script phpcs:simple", @@ -50,6 +50,7 @@ "@wordpress/env": "^8.12.0", "@wp-playground/blueprints": "^1.0.28", "@wp-playground/client": "^1.0.28", + "@wp-playground/cli": "^1.0.28", "cypress": "^13.17.0" } } diff --git a/playground/test.html b/playground/test.html index addcac4..3ab0d38 100644 --- a/playground/test.html +++ b/playground/test.html @@ -17,6 +17,7 @@ height: 100%; border: none; } + .buttons { position: fixed; top: 10px; @@ -32,6 +33,7 @@ border-radius: 4px; cursor: pointer; } + button:hover { background-color: #005177; }