Skip to content

Commit

Permalink
Merge pull request #285 from SlateFoundation/features/e2e-tests
Browse files Browse the repository at this point in the history
feat: automated e2e tests
  • Loading branch information
themightychris authored Aug 3, 2021
2 parents 395db86 + 02f005a commit 908972f
Show file tree
Hide file tree
Showing 20 changed files with 387 additions and 27 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/release-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ on:
branches: ['releases/v*']
types: [closed]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
release-deploy:

if: github.event.pull_request.merged == true # only run on PR merge
runs-on: ubuntu-latest
steps:

- name: Grab PR Title
- name: Configure release
run: |
set -e
PR_TITLE=$(jq -r ".pull_request.title" $GITHUB_EVENT_PATH)
PR_BODY=$(jq -r ".pull_request.body" $GITHUB_EVENT_PATH)
RELEASE_TAG=$(echo "${PR_TITLE}" | grep -oP "(?<=^Release: )v\d+\.\d+\.\d+(-rc\.\d+)?$")
Expand All @@ -37,14 +32,12 @@ jobs:
echo "${PR_BODY}" >> $GITHUB_ENV
echo 'END_OF_PR_BODY' >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
- name: Create release
uses: ncipollo/release-action@v1
with:
tag_name: '${{ env.RELEASE_TAG }}'
release_name: '${{ env.RELEASE_TAG }}'
token: ${{ secrets.BOT_GITHUB_TOKEN }}
commit: '${{ github.sha }}'
tag: '${{ env.RELEASE_TAG }}'
body: '${{ env.PR_BODY }}'
draft: false
prerelease: ${{ env.RELEASE_PRERELEASE }}
2 changes: 1 addition & 1 deletion .github/workflows/release-prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [develop]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
RELEASE_BRANCH: releases/v2

jobs:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Grab PR Title
- name: Validate PR title
run: |
set -e
PR_TITLE=$(jq -r ".pull_request.title" $GITHUB_EVENT_PATH)
# check title format and extract tag
Expand All @@ -30,7 +28,7 @@ jobs:
fi
# check that tag doesn't exist
if git ls-remote --exit-code origin "refs/tags/${RELEASE_TAG}"; then
if git ls-remote --exit-code "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}" "refs/tags/${RELEASE_TAG}"; then
echo "The PR title's version exists already"
exit 1
fi
111 changes: 111 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: 'Test: End-to-end'

on: pull_request

env:
HAB_LICENSE: accept-no-persist
HOLO_CACHE_TO: origin
HOLO_CACHE_FROM: origin

jobs:
test-e2e:

runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2

# TODO: wrap the next three steps an an emergence-studio action
- name: 'Stop default mysql service'
run: sudo service mysql stop

- name: 'Initialize Chef Habitat environment'
uses: JarvusInnovations/habitat-action@action/v1
env:
HAB_NGINX: |
[http.listen]
port = 5580
HAB_MYSQL: |
app_username = 'appadmin'
app_password = 'appadmin'
bind = '0.0.0.0'
HAB_PHP_RUNTIME: |
[sites.default.holo]
gitDir = '${{ github.workspace }}/.git'
with:
deps: |
jarvus/hologit
supervisor: |
core/mysql
emergence/php-runtime --bind="database:mysql.default"
emergence/nginx --bind="backend:php-runtime.default"
- name: Waiting for MySQL
run: |
until nc -z localhost 3306; do
sleep 0.5
echo -n "."
done
- name: Waiting for Emergence runtime
run: |
until nc -z localhost 9123; do
sleep 0.5
echo -n "."
done
- name: Configure command-line client access
run: |
sudo chmod ugo+xr \
/hab/svc/mysql/config \
/hab/svc/mysql/config/client.cnf \
/hab/svc/php-runtime/config \
/hab/svc/php-runtime/config/fpm-exec
ln -sf /hab/svc/mysql/config/client.cnf ~/.my.cnf
- name: Load site projection into emergence runtime
env:
HOLO_CACHE_FROM: origin
HOLO_CACHE_TO: origin
run: |
SITE_TREE="$(hab pkg exec jarvus/hologit git-holo project emergence-site)"
[ -n "${SITE_TREE}" ] || exit 1
hab pkg exec emergence/php-runtime emergence-php-load "${SITE_TREE}"
- name: Set up Cypress workspace
run: |
CYPRESS_TREE="$(hab pkg exec jarvus/hologit git-holo project cypress-workspace)"
[ -n "${CYPRESS_TREE}" ] || exit 1
mkdir "${GITHUB_WORKSPACE}.cypress-workspace"
git archive --format=tar "${CYPRESS_TREE}" | (cd "${GITHUB_WORKSPACE}.cypress-workspace" && tar xf -)
- name: Run Cypress tests
uses: cypress-io/github-action@v2
env:
GIT_DIR: ${{ github.workspace }}/.git
GIT_WORK_TREE: ${{ github.workspace }}
with:
env: STUDIO_CONTAINER=,STUDIO_SSH=
working-directory: ${{ github.workspace }}.cypress-workspace

- name: Upload supervisor log
uses: actions/upload-artifact@v1
if: always()
with:
name: supervisor-log
path: /hab/sup/default/sup.log

- name: Upload Cypress screenshots
uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: ${{ github.workspace }}.cypress-workspace/cypress/screenshots

- name: Upload Cypress videos
uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: ${{ github.workspace }}.cypress-workspace/cypress/videos
4 changes: 4 additions & 0 deletions .holo/branches/cypress-workspace/_skeleton-v2.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[holomapping]
holosource="=>cypress-workspace"
files = "**"
before = "*"
7 changes: 7 additions & 0 deletions .holo/branches/cypress-workspace/_slate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[holomapping]
files = [
"cypress/**",
"cypress.json",
"package.json",
"package-lock.json",
]
2 changes: 1 addition & 1 deletion .holo/sources/skeleton-v2.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[holosource]
url = "https://github.com/JarvusInnovations/emergence-skeleton-v2"
ref = "refs/tags/v2.6.2"
ref = "refs/tags/v2.6.6"
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"bmewburn.vscode-intelephense-client",
"imperez.smarty"
"imperez.smarty",
"felixfbecker.php-debug"
]
}
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/hab/svc/php-runtime/var/site/php-classes/Slate": "${workspaceFolder:slate}/php-classes/Slate",
"/hab/svc/php-runtime/var/site/php-classes/Emergence/CMS": "${workspaceFolder:slate}/php-classes/Emergence/CMS",
"/hab/svc/php-runtime/var/site/php-classes/Emergence/Locations": "${workspaceFolder:slate}/php-classes/Emergence/Locations",
"/hab/svc/php-runtime/var/site/php-classes/Emergence/People": "${workspaceFolder:slate}/php-classes/Emergence/People",
"/hab/svc/php-runtime/var/site/php-classes": "${workspaceFolder:emergence-skeleton}/php-classes",
"/hab/svc/php-runtime/var/site": "${workspaceFolder:slate}",
// "/src/emergence-php-core": "${workspaceFolder:php-core}"
},
"ignore": [
"**/vendor/**/*"
]
},
{
"name": "Launch SlateAdmin",
"type": "chrome",
Expand Down
7 changes: 7 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"baseUrl": "http://localhost:5580",
"env": {
"STUDIO_CONTAINER": "slate-studio",
"TEST_USER": "teacher"
}
}
26 changes: 26 additions & 0 deletions cypress/integration/profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"selectors": {
"gallery-photo": ".available-photos .photo-item",
"gallery-photo-first": ".available-photos .photo-item:first-of-type",
"gallery-default-link": "a[title=\"Make Default\"][href^=\"/profile/primaryPhoto?\"]",
"gallery-default-link": "a[title=\"Make Default\"][href^=\"/profile/primaryPhoto?\"]",
"about-content": "main.content .about-bio"
},
"values": {
"gallery-photo-selected-class": "current",
"profile-markdown-link-text": "Markdown",
"profile-markdown-link-href": "https://www.markdownguide.org/cheat-sheet",
"profile-save-button-text": "Save Profile",
"profile-data": {
"Class": "Emergence\\People\\User",
"FirstName": "Teacher",
"LastName": "Slate",
"Username": "teacher",
"AccountLevel": "Staff"
}
},
"features": {
"location": false,
"gallery": false
}
}
10 changes: 10 additions & 0 deletions cypress/integration/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe.skip('Registration', () => {
/**
* The registration test is temporarily disabled for Slate because
* registration is disabled by default in Slate installations.
*
* In the future, we could create a pathway for the cypress test to
* execute writing a file into the php-config tree through some
* reliable API into the studio
**/
});
2 changes: 1 addition & 1 deletion html-templates/profile/profileEdit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<h2 class="legend title-3">Profile Details</h2>

{field inputName="Location" label="Location" default=$User->Location}
{textarea inputName="About" label="About Me" default=$User->About hint="Use <a href='http://daringfireball.net/projects/markdown'>Markdown</a> to give your text some style"}
{textarea inputName="About" label="About Me" default=$User->About hint="Use <a href='https://www.markdownguide.org/cheat-sheet'>Markdown</a> to give your text some style"}

<div class="submit-area">
<input type="submit" class="submit" value="Save Profile">
Expand Down
10 changes: 10 additions & 0 deletions mkdocs.site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ theme:
palette:
primary: "cyan"
accent: "orange"

extra:
repository:
name: slate
url: [email protected]:SlateFoundation/slate.git
studio:
web_port: 5580
static_port: 5581
docs_port: 5588
mysql_port: 5536
31 changes: 31 additions & 0 deletions mkdocs.users.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extra:
fixtures:
users:
- username: system
password: system
level: Developer
about: 'Full system access'
- username: admin
password: admin
level: Administrator
about: 'Manage site and staff'
- username: teacher
password: teacher
level: Staff
about: 'Staff access with teaching role in multiple courses sections'
- username: teacher2
password: teacher2
level: Staff
about: 'Staff access with teaching role in multiple course sections'
- username: student
password: student
level: User
about: 'Student user with student role in multiple course sections'
- username: student2
password: student2
level: User
about: 'Student user with student role in multiple course sections'
- username: student3
password: student3
level: User
about: 'Student user with no roles in any course sections'
2 changes: 2 additions & 0 deletions php-classes/Emergence/People/ContactPoint/AbstractPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ public static function fromSerialized($string, Person $Person = null, $autoSave

public static function getByString($string, $conditions = [], $options = [])
{
$conditions['Class'] = static::class;
$conditions['Data'] = static::fromString($string)->serialize();

return static::getByWhere($conditions, $options);
}

public static function getAllByString($string, $conditions = [], $options = [])
{
$conditions['Class'] = static::class;
$conditions['Data'] = static::fromString($string)->serialize();

return static::getAllByWhere($conditions, $options);
Expand Down
Loading

0 comments on commit 908972f

Please sign in to comment.