Skip to content

Commit c1bc713

Browse files
authored
GitHub Actions Migration - Add Initial Tests (#2457)
1 parent 293b6e3 commit c1bc713

File tree

15 files changed

+396
-24
lines changed

15 files changed

+396
-24
lines changed

.dev/tests/cypress/helpers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ export function savePage() {
175175
*/
176176

177177
export function checkForBlockErrors( blockName ) {
178-
disableGutenbergFeatures();
179-
180178
cy.get( '.block-editor-warning' ).should( 'not.exist' );
181179

182180
cy.get( 'body.php-error' ).should( 'not.exist' );
@@ -230,6 +228,10 @@ export function clearBlocks() {
230228
safeWin.wp.data.dispatch( 'core/block-editor' ).removeBlocks(
231229
safeWin.wp.data.select( 'core/block-editor' ).getBlocks().map( ( block ) => block.clientId )
232230
);
231+
232+
if ( safeWin.wp.data.select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ) ) {
233+
safeWin.wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'welcomeGuide' );
234+
}
233235
} );
234236
}
235237

.dev/tests/cypress/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Welcome to our end-to-end testing suite for CoBlocks blocks! There are a number
99
### Add your local test credentials
1010
```bash
1111
$ echo '{
12-
"testURL": "https://coblocks.test",
12+
"testURL": "https://localhost:8889",
1313
"wpUsername": "admin",
1414
"wpPassword": "password",
1515
}' > cypress.env.json

.dev/tests/cypress/support/commands.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
import { disableGutenbergFeatures, isNotWPLocalEnv, loginToSite } from '../helpers';
2-
3-
before( function() {
4-
loginToSite().then( () => {
5-
if ( isNotWPLocalEnv() ) {
6-
// Waiting to see if the Welcome Guide will show up. Could probably be improved, but
7-
// for the moment, it seems hard to tie the wait to something else
8-
cy.wait( 10000 );
9-
}
10-
11-
disableGutenbergFeatures();
12-
} );
13-
} );
14-
151
// Maintain WordPress logged in state
162
Cypress.Cookies.defaults( {
173
preserve: /wordpress_.*/,
Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: 'Deploy / Create Release'
22

33
on:
4-
pull_request:
5-
branches:
6-
- master
74
milestone:
85
types: [ closed ]
96

@@ -12,6 +9,106 @@ env:
129
ARTIFACT_ZIP: 'coblocks.zip'
1310

1411
jobs:
12+
update:
13+
name: Update version
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Setup Node
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version-file: '.nvmrc'
23+
cache: 'yarn'
24+
25+
- name: Setup git user
26+
uses: godaddy-wordpress/setup-godaddy-git-user@v1
27+
28+
# Yarn is still required on this project, so we need to make sure it is
29+
# installed globally.
30+
- name: Install yarn
31+
run: npm i -g yarn
32+
33+
- name: Set version
34+
run: |
35+
echo "NEW_TAG_VERSION=${{ github.event.milestone.title }}" >> $GITHUB_ENV
36+
37+
- name: Validate tag version
38+
run: |
39+
MATCH='^([0-9]+\.){2}(\*|[0-9]+)(-.*)?$'
40+
if ! [[ $NEW_TAG_VERSION =~ $MATCH ]]; then
41+
echo "::error::Milestone title does not match semver format: '$NEW_TAG_VERSION'"
42+
exit 1
43+
fi
44+
45+
- name: Install dependencies
46+
run: |
47+
yarn install --immutable
48+
49+
- name: Run version update
50+
run: yarn version --new-version $NEW_TAG_VERSION
51+
52+
- name: Push changes
53+
run: |
54+
git add .
55+
git commit -m "Updating to version $NEW_TAG_VERSION" --no-verify
56+
git push
57+
1558
build:
1659
name: Build
1760
uses: ./.github/workflows/deploy-create-artifact.yml
61+
needs: update
62+
63+
tag:
64+
runs-on: ubuntu-latest
65+
name: Tag new version
66+
needs: update
67+
steps:
68+
- name: Checkout
69+
uses: actions/checkout@v3
70+
with:
71+
ref: ${{ github.event.repository.default_branch }}
72+
73+
- name: Setup git user
74+
uses: godaddy-wordpress/setup-godaddy-git-user@v1
75+
76+
- name: Set version
77+
run: |
78+
echo "NEW_TAG_VERSION=${{ github.event.milestone.title }}" >> $GITHUB_ENV
79+
80+
- name: Publish new tag
81+
run: |
82+
git tag $NEW_TAG_VERSION
83+
git push origin $NEW_TAG_VERSION
84+
85+
release:
86+
runs-on: ubuntu-latest
87+
name: Create new release
88+
needs: [ build, tag ]
89+
steps:
90+
- name: Checkout
91+
uses: actions/checkout@v3
92+
with:
93+
ref: ${{ github.event.repository.default_branch }}
94+
95+
- name: Set release version
96+
run: |
97+
echo "RELEASE_VERSION=${{ github.event.milestone.title }}" >> $GITHUB_ENV
98+
99+
- name: Create release
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
run: |
103+
gh release create $RELEASE_VERSION -n "${{ github.event.milestone.description }}" -t "$RELEASE_VERSION"
104+
105+
- name: Download theme
106+
uses: actions/download-artifact@v3
107+
with:
108+
name: ${{ env.ARTIFACT_NAME }}
109+
110+
- name: Upload asset to release
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
run: |
114+
gh release upload $RELEASE_VERSION ${{ env.ARTIFACT_ZIP }}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: WIP Test / Accessibility
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
pa11y:
10+
name: Pa11y
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
16+
- name: Setup wp-env
17+
uses: godaddy-wordpress/setup-wp-env@v1
18+
with:
19+
core: 'WordPress/WordPress#6.1'
20+
phpVersion: '7.4'
21+
plugins: '[".","https://downloads.wordpress.org/plugin/woocommerce.zip"]'
22+
themes: '["https://downloads.wordpress.org/theme/go.zip"]'
23+
24+
- name: Setup Node
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version-file: '.nvmrc'
28+
cache: 'yarn'
29+
30+
- name: Setup WP-CLI
31+
uses: godaddy-wordpress/setup-wp-cli@1
32+
33+
- name: Install dependencies
34+
run: |
35+
npm i -g yarn
36+
composer install
37+
yarn install --immutable
38+
39+
- name: Build plugin
40+
run: |
41+
yarn build
42+
43+
- name: Prepare tests
44+
run: |
45+
wp-env run cli "wp db import wp-content/plugins/coblocks/.dev/tests/a11y/coblocks_pa11y.sql"
46+
47+
- name: Run tests
48+
run: |
49+
A11Y=$(yarn test:a11y)
50+
echo "$A11Y"
51+
if [[ $A11Y != *"All accessibility tests have passed"* ]]; then
52+
exit 1
53+
fi
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: WIP Test / E2E
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
browser:
7+
required: false
8+
type: string
9+
default: chrome
10+
theme:
11+
required: false
12+
type: string
13+
default: go
14+
wpVersion:
15+
required: false
16+
type: string
17+
default: ""
18+
phpVersion:
19+
required: false
20+
type: string
21+
default: "8.1"
22+
secrets:
23+
record-key:
24+
description: 'Record key for Cypress Dashboard'
25+
required: true
26+
27+
jobs:
28+
test_cypress_e2e:
29+
name: E2E Test
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
spec:
35+
- alert.cypress.js
36+
- author.cypress.js
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v3
41+
42+
- name: Setup wp-env
43+
uses: godaddy-wordpress/setup-wp-env@v1
44+
with:
45+
core: ${{ inputs.wpVersion }}
46+
phpVersion: ${{ inputs.phpVersion }}
47+
plugins: '["."]'
48+
themes: '["https://downloads.wordpress.org/theme/go.zip"]'
49+
50+
- name: Setup Node
51+
uses: actions/setup-node@v3
52+
with:
53+
node-version-file: '.nvmrc'
54+
cache: 'yarn'
55+
56+
- name: Setup WP-CLI
57+
uses: godaddy-wordpress/setup-wp-cli@1
58+
59+
- name: Install dependencies
60+
run: |
61+
composer install --prefer-dist --optimize-autoloader &
62+
yarn install --immutable
63+
64+
- name: Build plugin
65+
run: |
66+
yarn build
67+
68+
- name: Prepare Go
69+
if: ${{ inputs.theme == 'go' }}
70+
run: |
71+
cd $(wp-env install-path)/go
72+
mkdir -p coblocks/icons
73+
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
74+
75+
- name: Prepare tests
76+
run: |
77+
WP_CORE_VERSION=$(wp-env run cli "wp core version")
78+
echo "WP_CORE_VERSION=${WP_CORE_VERSION}" >> $GITHUB_ENV
79+
wp-env run cli "wp post generate --count=5"
80+
wp-env run cli "wp theme activate ${{ inputs.theme }}"
81+
wp-env run cli "wp option update permalink_structure '/%postname%'"
82+
83+
- name: Run tests
84+
run: |
85+
CYPRESS_SPEC=$(find ./src/* -name ${{ matrix.spec }} -type f)
86+
echo '{"wpUsername":"admin","wpPassword":"password","testURL":"http://localhost:8889"}' | jq . > cypress.env.json
87+
./node_modules/.bin/cypress verify
88+
./node_modules/.bin/cypress run --browser ${{ inputs.browser }} --spec $CYPRESS_SPEC
89+
90+
- name: Upload failure video
91+
if: ${{ failure() }}
92+
uses: actions/upload-artifact@v3
93+
with:
94+
name: ${{ matrix.spec }}-fail.mp4
95+
path: ./.dev/tests/cypress/videos/${{ matrix.spec }}.mp4
96+
retention-days: 1
97+

.github/workflows/test-e2e.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: WIP Test / E2E
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
chrome_e2e:
10+
name: Chrome
11+
uses: ./.github/workflows/test-e2e-cypress.yml
12+
secrets:
13+
record-key: ${{ secrets.CYPRESS_RECORD_KEY }}
14+
15+
# firefox_e2e:
16+
# name: Firefox
17+
# uses: ./.github/workflows/test-e2e-cypress.yml
18+
# with:
19+
# browser: firefox
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: WIP Test / JS
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
10+
js_unit:
11+
name: Unit
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: Setup Node
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version-file: '.nvmrc'
21+
cache: 'yarn'
22+
23+
- name: Install dependencies
24+
run: yarn install --immutable
25+
26+
- name: Run tests
27+
run: yarn run test:js

0 commit comments

Comments
 (0)