From f3d6bd2434412e62be162714db1c4bfc9a5e7f97 Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Tue, 22 Apr 2025 22:10:55 +0100 Subject: [PATCH] Fix code quality issues: update Cypress tests to use custom commands, fix workflow files, update documentation --- .github/workflows/playground-tests.yml | 23 +++++++--------------- .github/workflows/wordpress-tests.yml | 5 +---- .wiki/Multisite-Development.md | 2 +- cypress.config.js | 5 +++-- cypress/e2e/playground-multisite.cy.js | 25 ++++++++++++------------ cypress/e2e/playground-single-site.cy.js | 24 +++++++++++------------ 6 files changed, 36 insertions(+), 48 deletions(-) diff --git a/.github/workflows/playground-tests.yml b/.github/workflows/playground-tests.yml index 7fc64b3..d9cd7d9 100644 --- a/.github/workflows/playground-tests.yml +++ b/.github/workflows/playground-tests.yml @@ -2,12 +2,12 @@ name: WordPress Playground Tests on: push: - branches: [ main, feature/*, bugfix/* ] + branches: [ main ] pull_request: branches: [ main ] concurrency: - group: playground-tests-${{ github.ref }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: @@ -36,10 +36,7 @@ jobs: npm ci --dry-run - name: Lint JavaScript files - run: | - echo "Linting JavaScript files" - # Add your linting command here when you have one - # For example: npm run lint + run: npm run lint:js playground-single-test: name: WordPress Playground Single Site Tests @@ -62,10 +59,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: | @@ -112,10 +106,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: | @@ -123,7 +114,7 @@ jobs: export CYPRESS_BASE_URL=http://localhost:80 # Start WordPress Playground with our blueprint - # Use port 80 for multisite as WordPress multisites don't support custom ports + # 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 & # Wait for WordPress Playground to be ready @@ -159,4 +150,4 @@ jobs: / /wp-admin/ php-version: '8.0' - wp-version: 'latest' + wp-version: '6.4' diff --git a/.github/workflows/wordpress-tests.yml b/.github/workflows/wordpress-tests.yml index 5ba6ef4..28328c5 100644 --- a/.github/workflows/wordpress-tests.yml +++ b/.github/workflows/wordpress-tests.yml @@ -32,10 +32,7 @@ jobs: npm ci --dry-run - name: Lint JavaScript files - run: | - echo "Linting JavaScript files" - # Add your linting command here when you have one - # For example: npm run lint + run: npm run lint:js # Note about e2e tests - name: Note about e2e tests diff --git a/.wiki/Multisite-Development.md b/.wiki/Multisite-Development.md index 9c21d62..a1f0f01 100644 --- a/.wiki/Multisite-Development.md +++ b/.wiki/Multisite-Development.md @@ -10,7 +10,7 @@ WordPress Multisite allows you to run multiple WordPress sites from a single Wor The plugin includes a dedicated directory for multisite-specific functionality: -```text +```bash includes/ └── Multisite/ ├── class-multisite.php # Base class for multisite functionality diff --git a/cypress.config.js b/cypress.config.js index 2d97bc4..bbb9436 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,13 +1,14 @@ -/* eslint-env node */ +/* eslint-env node, mocha */ const { defineConfig } = require('cypress'); module.exports = defineConfig({ e2e: { baseUrl: 'http://localhost:8888', - setupNodeEvents() { + setupNodeEvents(on, config) { // This function can be used to register custom Cypress plugins or event listeners. // Currently not in use, but left for future extensibility. + return config; }, // Add configuration for WordPress Playground experimentalWebKitSupport: true, diff --git a/cypress/e2e/playground-multisite.cy.js b/cypress/e2e/playground-multisite.cy.js index 44faa04..58f8633 100644 --- a/cypress/e2e/playground-multisite.cy.js +++ b/cypress/e2e/playground-multisite.cy.js @@ -11,36 +11,37 @@ describe('WordPress Playground Multisite Tests', () => { }); it('Can access the network admin area', () => { + // Use the custom login command + cy.loginAsAdmin(); + // Visit the network admin dashboard cy.visit('/wp-admin/network/'); - // Fill in the login form if needed - cy.get('body').then(($body) => { - if ($body.hasClass('login')) { - cy.get('#user_login').type('admin'); - cy.get('#user_pass').type('password'); - cy.get('#wp-submit').click(); - } - }); - // Check if we're logged in to the network admin cy.get('#wpadminbar').should('exist'); }); it('Plugin is network activated', () => { + // Use the custom login command + cy.loginAsAdmin(); + // Navigate to network plugins page cy.visit('/wp-admin/network/plugins.php'); - // Check if the plugins are active - cy.contains('Plugin Toggle').should('exist'); - cy.contains('Kadence Blocks').should('exist'); + // Check if the plugins are network active + cy.contains('tr', 'Plugin Toggle').find('.network_active').should('exist'); + cy.contains('tr', 'Kadence Blocks').find('.network_active').should('exist'); }); it('Network settings page loads correctly', () => { + // Use the custom login command + cy.loginAsAdmin(); + // Navigate to the network settings page cy.visit('/wp-admin/network/settings.php'); // Check if the network settings page loaded correctly cy.get('#wpbody-content').should('exist'); + cy.get('h1').should('contain', 'Network Settings'); }); }); diff --git a/cypress/e2e/playground-single-site.cy.js b/cypress/e2e/playground-single-site.cy.js index 9453676..a865ca3 100644 --- a/cypress/e2e/playground-single-site.cy.js +++ b/cypress/e2e/playground-single-site.cy.js @@ -11,36 +11,34 @@ describe('WordPress Playground Single Site Tests', () => { }); it('Can access the admin area', () => { - // Visit the admin dashboard - cy.visit('/wp-admin/'); - - // Fill in the login form if needed - cy.get('body').then(($body) => { - if ($body.hasClass('login')) { - cy.get('#user_login').type('admin'); - cy.get('#user_pass').type('password'); - cy.get('#wp-submit').click(); - } - }); + // Use the custom login command + cy.loginAsAdmin(); // Check if we're logged in cy.get('#wpadminbar').should('exist'); }); it('Plugin is activated', () => { + // Use the custom login command + cy.loginAsAdmin(); + // Navigate to plugins page cy.visit('/wp-admin/plugins.php'); // Check if the plugin is active - cy.contains('Plugin Toggle').should('exist'); - cy.contains('Kadence Blocks').should('exist'); + cy.contains('tr', 'Plugin Toggle').find('.deactivate').should('exist'); + cy.contains('tr', 'Kadence Blocks').find('.deactivate').should('exist'); }); it('Plugin settings page loads correctly', () => { + // Use the custom login command + cy.loginAsAdmin(); + // Navigate to the plugin settings page cy.visit('/wp-admin/options-general.php'); // Check if the settings page exists cy.get('#wpbody-content').should('exist'); + cy.get('h1').should('be.visible'); }); });