Skip to content

Commit

Permalink
Merge pull request #160 from newfold-labs/fix-tests-workflow
Browse files Browse the repository at this point in the history
PRESS4-393 | Cypress Test Workflow fix
  • Loading branch information
ramyakrishnai authored Nov 17, 2023
2 parents dc87a1f + ef72575 commit 9680f2d
Show file tree
Hide file tree
Showing 12 changed files with 4,568 additions and 168 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/bluehost-plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build Bluehost Plugin For Testing
on:
workflow_dispatch:
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
Expand Down Expand Up @@ -70,14 +71,14 @@ jobs:
run: composer install --no-progress --no-dev --optimize-autoloader --prefer-dist

- name: Setup Registry on Plugin
run: printf "\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
run: printf "\n//npm.pkg.github.com/:_authToken=${{ secrets.NEWFOLD_ACCESS_TOKEN }}" >> .npmrc

- name: NPM Install
run: npm ci --legacy-peer-deps

- name: Setup Registry on Module
working-directory: ./modules/${{ github.repository }}
run: printf "\n//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
run: printf "\n//npm.pkg.github.com/:_authToken=${{ secrets.NEWFOLD_ACCESS_TOKEN }}" >> .npmrc

- name: Setup module
working-directory: ./modules/${{ github.repository }}
Expand All @@ -89,7 +90,11 @@ jobs:
- name: View modified files
run: cat package.json composer.json

- name: Build JavaScript
- name: Build JavaScript in module
working-directory: ./modules/${{ github.repository }}
run: npm run build

- name: Build JavaScript in plugin
run: npm run build

- name: Setup workflow context
Expand Down
134 changes: 74 additions & 60 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Tests
name: Cypress Tests
on:
workflow_dispatch:
push:
branches:
- trunk
Expand All @@ -12,29 +13,46 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
tests:

Tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository

- name: Checkout plugin
uses: actions/checkout@v4
with:
repository: bluehost/bluehost-wordpress-plugin
ref: 'develop'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
coverage: none
tools: composer, cs2pr

- name: Setup workflow context
id: workflow
working-directory: ${{ runner.temp }}
env:
REPO: ${{ github.repository }}
REPO: "bluehost-wordpress-plugin"
run: |
mkdir dist
echo "DIST=${PWD}/dist" >> $GITHUB_OUTPUT
echo "PACKAGE=${REPO##*/}" >> $GITHUB_OUTPUT
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Setup Node
uses: actions/setup-node@v4
with:
php-version: '7.4'
coverage: none
tools: composer
node-version: 18
cache: "npm"

- name: Checkout module
uses: actions/checkout@v4
with:
path: ./vendor/${{ github.repository }}

- name: Get Composer cache directory
id: composer-cache
Expand All @@ -46,91 +64,87 @@ jobs:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-composer-
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Log debug information
- name: Show versions
run: |
php --version
composer --version
node --version
npm --version
- name: Validate composer.json and composer.lock files
- name: Modify composer.json
run: |
node ./vendor/newfold-labs/wp-module-ecommerce/scripts/update-plugin-composer.mjs ${PWD}/composer.json ${PWD}/vendor
- name: Update lockfile
run: composer update

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install PHP Dependencies
run: composer install --no-progress --no-dev --optimize-autoloader
run: composer install --no-progress --no-dev --optimize-autoloader --prefer-dist

- name: Setup Registry
- name: Setup Registry on Plugin
run: printf "\n//npm.pkg.github.com/:_authToken=${{ secrets.NEWFOLD_ACCESS_TOKEN }}" >> .npmrc

- name: Run NPM Install
run: npm install
- name: NPM Install
run: npm ci --legacy-peer-deps

- name: Setup Registry on Module
working-directory: ./vendor/${{ github.repository }}
run: printf "\n//npm.pkg.github.com/:_authToken=${{ secrets.NEWFOLD_ACCESS_TOKEN }}" >> .npmrc

- name: Setup module
working-directory: ./vendor/${{ github.repository }}
run: npm ci --legacy-peer-deps

- name: NPM Install module
run: npm install ./vendor/newfold-labs/wp-module-ecommerce --legacy-peer-deps --force

- name: View modified files
run: cat package.json composer.json

- name: Build JavaScript in module
working-directory: ./vendor/${{ github.repository }}
run: npm run build

- name: Build JavaScript
- name: Build JavaScript in plugin
run: npm run build

- name: Create Distribution Copy
run: rsync -r --exclude-from=.distignore --include-from=.distinclude . ${{ steps.workflow.outputs.DIST }}/${{ steps.workflow.outputs.PACKAGE }}
- name: Prepare files
run: rsync -r --include-from=.distinclude --exclude-from=.distignore . ${{ steps.workflow.outputs.DIST }}/${{ steps.workflow.outputs.PACKAGE }}

- name: List Distribution Files
working-directory: ${{ steps.workflow.outputs.DIST }}
run: find .
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.workflow.outputs.PACKAGE }}
path: ${{ steps.workflow.outputs.DIST }}

- name: Configure WordPress
run: echo '{"config":{"WP_DEBUG_DISPLAY":false},"plugins":["${{ steps.workflow.outputs.DIST }}/${{ steps.workflow.outputs.PACKAGE }}"]}' > .wp-env.override.json

- name: Install WordPress
run: npx @wordpress/env@latest start

- name: Run PHPUnit Tests
run: npm run test:unit
run: npx wp-env start --debug

- name: Run Cypress Tests
run: npm run test:e2e
run: npx cypress run --spec ./vendor/${{ github.repository }}/tests/cypress/integration

- name: Store screenshots of test failures
if: ${{ failure() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: screenshots
path: ./tests/cypress/screenshots

- name: Check if a debug.log file exists
id: hasErrors
run: npx wp-env run wordpress test ! -f /var/www/html/wp-content/debug.log

- name: Copy debug.log file
if: ${{ steps.hasErrors.outputs.failure }}
run: cat /var/www/html/wp-content/debug.log 1>./debug.log 2>/dev/null
- name: Output debug.log file contents
if: ${{ always() }}
continue-on-error: true
run: npx wp-env run wordpress "cat /var/www/html/wp-content/debug.log"

- name: Store debug.log file
if: ${{ steps.hasErrors.outputs.failure }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: logs
path: ./debug.log

- name: Store a copy of the plugin on success
if: ${{ success() }}
uses: actions/upload-artifact@v1
with:
name: ${{ steps.workflow.outputs.PACKAGE }}
path: ${{ steps.workflow.outputs.DIST }}
17 changes: 12 additions & 5 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
{
"core": "WordPress/WordPress#tags/6.3.2",
"config": {
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": true
"WP_DEBUG_DISPLAY": false,
"FS_METHOD": "direct",
"NFD_ONBOARDING_VERSION": "0.0.10"
},
"phpVersion": "8.1",
"plugins": [
"."
],
"port": 8880,
"testsPort": 8881,
"themes": [
"https://downloads.wordpress.org/theme/yith-wonder.latest-stable.zip"
],
"port": 8882,
"testsPort": 8883,
"env": {
"tests": {
"config": {
"WP_SITEURL": "localhost:8881",
"WP_TESTS_DOMAIN": "localhost:8881",
"WP_TESTS_EMAIL": "team-spartans@newfold.com",
"WP_TESTS_TITLE": "WordPress Tests",
"WP_TESTS_TITLE": "Wordpress Tests",
"WP_TESTS_BINARY": "php"
}
}
Expand Down
45 changes: 45 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { defineConfig } = require('cypress')
const cypressReplay = require("@replayio/cypress")
const { phpVersion, core } = require('./.wp-env.json')
const wpVersion = /[^/]*$/.exec(core)[0]

module.exports = defineConfig({
env: {
wpUsername: 'admin',
wpPassword: 'password',
wpVersion,
phpVersion,
},
downloadsFolder: 'tests/cypress/downloads',
fixturesFolder: 'tests/cypress/fixtures',
screenshotsFolder: 'tests/cypress/screenshots',
video: true,
videosFolder: 'tests/cypress/videos',
videoUploadOnPasses: false,
chromeWebSecurity: false,
viewportWidth: 1024,
viewportHeight: 768,
blockHosts: [
'*doubleclick.net',
'*jnn-pa.googleapis.com',
'*youtube.com',
],
e2e: {
setupNodeEvents(on, config) {
const semver = require('semver');

// Setup Replay
cypressReplay.default(on, config);

// Ensure that the base URL is always properly set.
if (config.env && config.env.baseUrl) {
config.baseUrl = config.env.baseUrl;
}
return config;
},
baseUrl: 'http://localhost:8882',
specPattern: 'tests/cypress/integration/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'tests/cypress/support/index.js',
testIsolation: false,
},
})
Loading

0 comments on commit 9680f2d

Please sign in to comment.