Skip to content

Commit

Permalink
chore: add logic to install woocommerce subscription for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinderk committed Sep 17, 2023
1 parent f55a237 commit b58759e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- smoke-testing
pull_request:
types: [opened, synchronize, reopened, labeled]
types: [ opened, synchronize, reopened, labeled ]
branches:
- trunk

Expand All @@ -32,14 +32,22 @@ jobs:
key: node-${{ hashFiles('package-lock.json') }}

- name: Node install
run: |
npm install
run: npm install

- name: Build
run: |
npm run build
run: npm run build

- name: Install Playwright Browsers
run: npx playwright install chromium

- name: Install required WP plugins
run: |
URL_CONFIG="url.https://${{ secrets.BOT_GH_TOKEN }}:[email protected]/.insteadOf [email protected]:"
git config --global $URL_CONFIG
npm run env:install-plugins
git config --global --unset $URL_CONFIG
- name: Setup WP environment
run: npm run env:start

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ build

woocommerce-gateway-payfast.zip
tests/e2e/test-results
./tests/e2e/test-plugins/woocommerce-subscriptions
5 changes: 3 additions & 2 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"plugins": [
".",
"https://downloads.wordpress.org/plugin/woocommerce.zip",
"./tests/e2e/wordpress-plugins/payfast-webhook-faker"
".",
"./tests/e2e/wordpress-plugins/payfast-webhook-faker",
"./tests/e2e/test-plugins/woocommerce-subscriptions"
],
"themes": ["https://downloads.wordpress.org/theme/storefront.zip"],
"env": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"env:clean": "wp-env clean",
"env:stop": "wp-env stop",
"env:destroy": "wp-env destroy",
"env:install-plugins": "bash ./tests/e2e/bin/install-plugins.sh",
"postenv:start": "bash ./tests/e2e/bin/initialize.sh",
"test:e2e": "npx playwright test --config tests/e2e/playwright.config.js",
"test:e2e-debug": "npx playwright test --config tests/e2e/playwright.config.js --debug",
Expand Down
31 changes: 31 additions & 0 deletions tests/e2e/bin/install-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Clone latest version of a plugin (fallback to default branch if latest version is not found)
install_plugin_from_repo() {
local PLUGIN_SLUG=$1
local DIR=$2

rm -rf "${DIR}"
git clone --quiet --depth=1 "[email protected]:woocommerce/${PLUGIN_SLUG}.git" "${DIR}"

# Parse latest version from main plugin file
local LATEST_VERSION=$(grep -o '\* Version:.*' ${DIR}/${PLUGIN_SLUG}.php | sed 's/* Version://' | tr -d ' ')
echo Latest version ${LATEST_VERSION} for ${PLUGIN_SLUG}

# Fetch a specific tag
cd "${DIR}"
git fetch --depth 1 "[email protected]:woocommerce/${PLUGIN_SLUG}.git" tag "${LATEST_VERSION}"

# If the latest version tag is available then switch
if [ $(git tag -l "${LATEST_VERSION}") ]; then
git checkout "${LATEST_VERSION}" --quiet
fi

cd -
}

# Install Subscriptions.
install_plugin_from_repo "woocommerce-subscriptions" "./tests/e2e/test-plugins/woocommerce-subscriptions"
cd ./tests/e2e/test-plugins/woocommerce-subscriptions
npm install && npm run build
cd -

0 comments on commit b58759e

Please sign in to comment.