Skip to content

Commit

Permalink
allow custom path on e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
aledesma-godaddy committed Oct 20, 2023
1 parent aaa064e commit 8e87eab
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 73 deletions.
144 changes: 71 additions & 73 deletions .github/workflows/test-e2e-cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,78 +103,76 @@ jobs:
node-version-file: '.nvmrc'
cache: 'yarn'

- name: Install dependencies
run: |
composer install --prefer-dist --optimize-autoloader &
yarn install --immutable
- name: Build plugin
run: |
npx grunt build
# moving the built directory to this location means no dev files in tests-container.
mv ./build/coblocks $(wp-env install-path)/${{ inputs.installPath }}/wp-content/plugins/
- name: Prepare Theme
run: |
if [ "${{ inputs.theme }}" = "https://downloads.wordpress.org/theme/go.zip" ]; then
cd $(wp-env install-path)/go
else
cd $(wp-env install-path)/${{ inputs.installPath }}/wp-content/themes/twentytwentythree
fi
mkdir -p coblocks/icons
echo '<svg height="20" viewBox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><circle class="inner-circle" cx="20" cy="20" r="8" stroke-width="8" stroke-dasharray="50.2655 50.2655" stroke-dashoffset="0"></circle></svg>' >> coblocks/icons/custom.svg
- name: Prepare tests
run: ls $(wp-env install-path)
# - name: Install dependencies
# run: |
# composer install --prefer-dist --optimize-autoloader &
# yarn install --immutable

# - name: Build plugin
# run: |
# npx grunt build
# # moving the built directory to this location means no dev files in tests-container.
# mv ./build/coblocks $(wp-env install-path)/tests-WordPress/wp-content/plugins/

# - name: Prepare Theme
# run: |
# if [ "${{ inputs.theme }}" = "https://downloads.wordpress.org/theme/go.zip" ]; then
# cd $(wp-env install-path)/go
# else
# cd $(wp-env install-path)/tests-WordPress/wp-content/themes/twentytwentythree
# fi
# mkdir -p coblocks/icons
# echo '<svg height="20" viewBox="0 0 20 20" width="20" xmlns="http://www.w3.org/2000/svg"><circle class="inner-circle" cx="20" cy="20" r="8" stroke-width="8" stroke-dasharray="50.2655 50.2655" stroke-dashoffset="0"></circle></svg>' >> coblocks/icons/custom.svg

# - name: Prepare tests
# run: |
# WP_CORE_VERSION=$(wp-env run cli wp core version)
# echo "WP_CORE_VERSION=${WP_CORE_VERSION}" >> $GITHUB_ENV
# wp-env run tests-cli wp post generate --count=5
# wp-env run cli wp post generate --count=5
# wp-env run cli wp option update permalink_structure '/%postname%'
# if [ "${{ inputs.theme }}" = "https://downloads.wordpress.org/theme/go.zip" ]; then
# wp-env run tests-cli wp theme activate go
# fi

# # Only create a new post if running the migrated specs
# - name: Create post and get ID
# if: matrix.spec == 'alert.cypress.js' || matrix.spec == 'author.cypress.js'
# run: |
# # Generate application-password to use with WP REST API.
# app_password=$(wp-env run tests-cli wp user application-password create admin gha-password --porcelain)

# # Retrieve post content from fixture.
# post_content=$(cat .dev/tests/cypress/fixtures/${{matrix.spec}}.html)
# echo $post_content

# # Create a post using the REST API and parse the postId from the response.
# postId=$(curl -s -X POST 'http://localhost:8889/?rest_route=/wp/v2/posts' --data-urlencode "title=${{matrix.spec}}" --data-raw "content=$post_content" --data-urlencode "status=publish" --user "admin:$app_password"| jq '.id')

# # Save the postId to the output.
# echo "postId=$postId" >> $GITHUB_OUTPUT
# id: create-post

# # Only retrieve the post ID if running the first spec
# - name: Save post ID to file
# if: matrix.spec == 'alert.cypress.js' || matrix.spec == 'author.cypress.js'
# run: |
# path="$GITHUB_WORKSPACE/.dev/tests/cypress/fixtures/${{matrix.spec}}.json"
# touch "$path"
# echo "{\"${{matrix.spec}}\": \"$(echo "${{ steps.create-post.outputs.postId }}")\"}" > "$path"

# - name: Run tests
# run: |
# CYPRESS_SPEC=$(find ./src/* -name ${{ matrix.spec }} -type f)
# echo '{"wpUsername":"admin","wpPassword":"password","testURL":"http://localhost:8889"}' | jq . > cypress.env.json
# ./node_modules/.bin/cypress verify
# ./node_modules/.bin/cypress run --browser ${{ inputs.browser }} --spec $CYPRESS_SPEC

# - name: Upload failure video
# if: ${{ failure() }}
# uses: actions/upload-artifact@v3
# with:
# name: ${{ matrix.spec }}-fail.mp4
# path: ./.dev/tests/cypress/videos/${{ matrix.spec }}.mp4
# retention-days: 1
run: |
WP_CORE_VERSION=$(wp-env run cli wp core version)
echo "WP_CORE_VERSION=${WP_CORE_VERSION}" >> $GITHUB_ENV
wp-env run tests-cli wp post generate --count=5
wp-env run cli wp post generate --count=5
wp-env run cli wp option update permalink_structure '/%postname%'
if [ "${{ inputs.theme }}" = "https://downloads.wordpress.org/theme/go.zip" ]; then
wp-env run tests-cli wp theme activate go
fi
# Only create a new post if running the migrated specs
- name: Create post and get ID
if: matrix.spec == 'alert.cypress.js' || matrix.spec == 'author.cypress.js'
run: |
# Generate application-password to use with WP REST API.
app_password=$(wp-env run tests-cli wp user application-password create admin gha-password --porcelain)
# Retrieve post content from fixture.
post_content=$(cat .dev/tests/cypress/fixtures/${{matrix.spec}}.html)
echo $post_content
# Create a post using the REST API and parse the postId from the response.
postId=$(curl -s -X POST 'http://localhost:8889/?rest_route=/wp/v2/posts' --data-urlencode "title=${{matrix.spec}}" --data-raw "content=$post_content" --data-urlencode "status=publish" --user "admin:$app_password"| jq '.id')
# Save the postId to the output.
echo "postId=$postId" >> $GITHUB_OUTPUT
id: create-post

# Only retrieve the post ID if running the first spec
- name: Save post ID to file
if: matrix.spec == 'alert.cypress.js' || matrix.spec == 'author.cypress.js'
run: |
path="$GITHUB_WORKSPACE/.dev/tests/cypress/fixtures/${{matrix.spec}}.json"
touch "$path"
echo "{\"${{matrix.spec}}\": \"$(echo "${{ steps.create-post.outputs.postId }}")\"}" > "$path"
- name: Run tests
run: |
CYPRESS_SPEC=$(find ./src/* -name ${{ matrix.spec }} -type f)
echo '{"wpUsername":"admin","wpPassword":"password","testURL":"http://localhost:8889"}' | jq . > cypress.env.json
./node_modules/.bin/cypress verify
./node_modules/.bin/cypress run --browser ${{ inputs.browser }} --spec $CYPRESS_SPEC
- name: Upload failure video
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.spec }}-fail.mp4
path: ./.dev/tests/cypress/videos/${{ matrix.spec }}.mp4
retention-days: 1

1 change: 1 addition & 0 deletions .github/workflows/test-wp-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
uses: ./.github/workflows/test-e2e-cypress.yml
with:
wpVersion: ${{needs.set_constant.outputs.wp_next}}
installPath: "tests-wordpress-6.4-RC1"
concurrency:
group: chrome-defaults
cancel-in-progress: true
Expand Down

0 comments on commit 8e87eab

Please sign in to comment.