Skip to content

Commit

Permalink
Get subdomain multisite tests working properly (#148)
Browse files Browse the repository at this point in the history
* add copying the changes in the PR to the subdomain tests

* switch to git mode before we try pushing things

* remove color tags

* exclude node_modules from rsync
playwright runs on the ci, not on the fixture

* add multisite config to the fixture site
this shouldn't need to be done every time, so we check if multisite is true and add the config if it's not true

* fix quoting

* remove lingering ${type} vars and stray quote

* don't run playwright tests if files we don't care about were affected

* remove color tags

* don't save in a variable

Co-authored-by: Phil Tyler <[email protected]>

* exclude node_modules from rsync
playwright runs on the ci, not on the fixture

* fix quoting

* remove lingering ${type} vars and stray quote

* don't run playwright tests if files we don't care about were affected

* move the wait to earlier
we can't check the config if it hasn't finished being updated

* give up on the multisite checking
we should know it already is multisite so we'll just check that the domains exist

* install graphql as part of the workflow

* clear ache after installing graphql

* break the subdomain sites up
so we can pass different values in

* allow the graphql endpoint to be passed
we can use this to fix the subdirectory test, too, but later

* copy the application.php for subdom
this is getting reset, too, for some reason

* add more debugging info to failure output

Co-authored-by: Phil Tyler <[email protected]>

---------

Co-authored-by: Phil Tyler <[email protected]>
  • Loading branch information
jazzsequence and pwtyler authored Aug 2, 2024
1 parent 0688710 commit 669117e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/tests/wpcm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test, expect } from "@playwright/test";
const exampleArticle = "Hello world!";
const siteTitle = process.env.SITE_NAME || "WPCM Playwright Tests";
const siteUrl = process.env.SITE_URL || "https://dev-wpcm-playwright-tests.pantheonsite.io";
let graphqlEndpoint = process.env.GRAPHQL_ENDPOINT || `${siteUrl}/wp/graphql`;

test("homepage loads and contains example content", async ({ page }) => {
await page.goto(siteUrl);
Expand Down Expand Up @@ -41,8 +42,7 @@ test("validate core resource URLs", async ({ request }) => {
});

test("graphql is able to access hello world post", async ({ request }) => {
let graphqlEndpoint = `${siteUrl}/wp/graphql`;
let apiRoot = await request.get(`${siteUrl}/wp/graphql`);
let apiRoot = await request.get(graphqlEndpoint);
// If the above request doesn't resolve, it's because we're on a subsite where the path is ${siteUrl}/graphql -- similar to the rest api.
if (!apiRoot.ok()) {
graphqlEndpoint = `${siteUrl}/graphql`;
Expand Down
82 changes: 75 additions & 7 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
name: WordPress Composer Playwright Tests
on:
pull_request:
paths-ignore:
- '.github/workflows/ci.yml'
- '.github/workflows/composer-diff.yml'
- '.github/workflows/phpcbf.yml'
- '.github/workflows/sage-test.yml'
- '.github/workflows/sync-default.yml'
- '.github/tests/*.bats'
- 'private/scripts/**'
- 'docs/**'
- '*.md'
- 'phpcs.yml'
- 'wp-cli.yml'
- '.lando.upstream.yml'
- 'CODEOWNERS'
- '.editorconfig'
types:
- opened
- reopened
Expand Down Expand Up @@ -358,6 +373,7 @@ jobs:
echo "SITE_NAME=$SITE_NAME" >> $GITHUB_ENV
echo "SITE_URL=$SITE_URL" >> $GITHUB_ENV
echo "SUBDOMAIN_URL=$SUBDOMAIN_URL" >> $GITHUB_ENV
echo "SITE_ID=wpcm-subdom-playwright-tests" >> $GITHUB_ENV
- name: Install SSH keys
uses: webfactory/[email protected]
Expand Down Expand Up @@ -385,13 +401,65 @@ jobs:
echo "Install Playwright Browsers"
npx playwright install --with-deps
- name: Run Playwright tests
- name: Copy changes from PR
run: |
echo "Commit Message: ${{ env.COMMIT_MSG }}"
echo "Setting up some git config..."
git config --global user.email "[email protected]"
git config --global user.name "Pantheon WPCM Bot"
echo "Switching to git mode..."
terminus connection:set "${{ env.SITE_ID }}".dev git
echo "Clone the site locally and copy PR updates"
terminus local:clone ${{ env.SITE_ID }}
cd ~/pantheon-local-copies/"${{ env.SITE_ID }}"
echo "Copying latest changes and committing to the site."
rsync -a --exclude='.git' --exclude='status-*.txt' --exclude="node_modules" "${{ github.workspace }}/" .
git add -A
git commit -m "Update to latest commit: ${{ env.COMMIT_MSG }}" || true
echo "Installing wp-graphql..."
composer require wp-graphql/wp-graphql
git add composer.json composer.lock
git commit -m "Add WP-GraphQL plugin" || true
echo "Copying the subdomain multisite config/application.php file..."
cp -f "${{ github.workspace }}/.github/fixtures/config/application.subdom.php" config/application.php
git add config/application.php
git commit -m "Add subdomain multisite config" || true
# Push and wait for the git push to finish.
git push origin master || true
terminus workflow:wait "${{ env.SITE_ID }}".dev
echo "Checking WordPress install status"
terminus wp "${{ env.SITE_ID }}".dev -- cli info
# Activte WP-GraphQL plugin
terminus wp "${{ env.SITE_ID }}".dev -- plugin activate wp-graphql
terminus env:clear-cache "${{ env.SITE_ID }}".dev
# Run curl checks against the site URLs to ensure the main site and the subdomain site exist.
echo "Checking site URLs"
SITE_URL_TEST=$(curl -s -o /dev/null -w "%{http_code}" ${{ env.SITE_URL }})
SUBDOMAIN_URL_TEST=$(curl -s -o /dev/null -w "%{http_code}" ${{ env.SUBDOMAIN_URL }})
if [ $SITE_URL_TEST -ne 200 ] || [ $SUBDOMAIN_URL_TEST -ne 200 ]; then
echo "One or more site URLs are not returning a 200 status code. Exiting."
echo "${{ env.SITE_URL }} - ${SITE_URL_TEST}"
echo "${{ env.SUBDOMAIN_URL }} - ${SUBDOMAIN_URL_TEST}"
exit 1
fi
- name: Run Playwright tests on main site
env:
SITE_NAME: ${{ env.SITE_NAME }}
SITE_URL: ${{ env.SITE_URL }}
run: |
npm run test .github/tests/wpcm.spec.ts
SITE_NAME=Foo
SITE_URL=${{ env.SUBDOMAIN_URL }}
echo "Running Playwright tests on WordPress Subdomain subsite"
npm run test .github/tests/wpcm.spec.ts
GRAPHQL_ENDPOINT: ${{ env.SITE_URL }}/wp/graphql
run: npm run test .github/tests/wpcm.spec.ts
- name: Run Playwright tests on subdomain site
env:
SITE_NAME: Foo
SITE_URL: ${{ env.SUBDOMAIN_URL }}
GRAPHQL_ENDPOINT: ${{ env.SUBDOMAIN_URL }}/wp/graphql
run: npm run test .github/tests/wpcm.spec.ts
2 changes: 1 addition & 1 deletion devops/scripts/setup-playwright-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ copy_pr_updates() {
echo "Commit Message: ${commit_msg}"
cd ~/pantheon-local-copies/"${site_id}"
echo -e "${YELLOW}Copying latest changes and committing to the site.${RESET}"
rsync -a --exclude='.git' --exclude='status-*.txt' "${workspace}/" .
rsync -a --exclude='.git' --exclude='status-*.txt' --exclude="node_modules" "${workspace}/" .
git add -A
git commit -m "Update to latest commit: ${commit_msg}" || true
git push origin master || true
Expand Down

0 comments on commit 669117e

Please sign in to comment.