generated from compucorp/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPS-562: E2E test Basic Structure #1
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
10c0dc4
CPS-562: Basic Structure
deb1990 8a9ed4e
CPS-562: Add JSDoc
deb1990 52738f8
CPS-562: Add husky precommit hooks
deb1990 dda2cbe
CPS-562: Support CiviProspect and Awards
deb1990 711b2e4
CPS-562: Add linter
deb1990 ea1a85b
CPS-562: Remove site config
deb1990 7192630
CPS-562: Support testing for different roles
deb1990 fc450d0
CPS-562: Add tests for different roles
deb1990 3345ae2
CPS-562: Update folder structure
deb1990 d67d3b7
CPS-562: Update folder structure
deb1990 0b3e2ad
CPS-562: Implement Db trascation start/rollback logic
deb1990 7950a8e
CPS-562: Create data
deb1990 b664fd5
CPS-562: Change Page structure
deb1990 6c78415
CPS-562: Run tests in sequence
deb1990 3115552
CPS-562: Create Drupal users and assign roles
deb1990 deedf83
CPS-562: Add reporting
deb1990 cda7776
CPS-562: Github action
deb1990 8e678fa
CPS-562: Use cache and proper types
deb1990 27ca50c
CPS-562: Create permissions for roles
deb1990 f94cc8e
CPS-562: Take screenshot when test fails
deb1990 dd3f74a
CPS-562: Github Action
deb1990 1820fa3
CPS-562: Fix session limit issue
deb1990 28fc6a2
CPS-562: Folder structure changes
deb1990 b4b83f2
CPS-562: Move github action to workflow_dispatch
deb1990 b0a56e1
CPS-562: Misc changes
deb1990 3d50827
CPS-562: Remove Param type
deb1990 1d5f5e1
CPS-562: Removed unnecessary functions
deb1990 5032361
CPS-562: Change branch name
deb1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.eslintrc.js | ||
gulp-tasks/jest-helper/environments/e2e-test-environment.js | ||
gulp-tasks/jest-helper/global/teardown.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
extends: ['standard-with-typescript', 'plugin:jsdoc/recommended'], | ||
parserOptions: { | ||
project: './tsconfig.json' | ||
}, | ||
settings: { | ||
jsdoc: { | ||
mode: 'typescript' | ||
} | ||
}, | ||
rules: { | ||
'@typescript-eslint/semi': ['error', 'always'], | ||
'jsdoc/require-param-type': 0, | ||
'jsdoc/require-returns-type': 0, | ||
'jsdoc/require-jsdoc': [1, { | ||
contexts: [ | ||
'ClassDeclaration', 'FunctionExpression', 'FunctionDeclaration', | ||
'ArrowFunctionExpression', 'MethodDefinition', 'ClassExpression', | ||
'FunctionExpression', 'TSInterfaceDeclaration', 'TSMethodSignature' | ||
] | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
name: End to End Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
civicase_branch: | ||
description: CiviCase Branch/Tag Name | ||
default: master | ||
required: true | ||
civiawards_branch: | ||
description: CiviAwards Branch/Tag Name | ||
default: master | ||
required: true | ||
civiprospect_branch: | ||
description: CiviProspect Branch/Tag Name | ||
default: master | ||
required: true | ||
shoreditch_branch: | ||
description: Shoreditch Branch/Tag Name | ||
default: master | ||
required: true | ||
civicrm_version: | ||
description: CiviCRM Version | ||
default: 5.35 # change this to the current civicrm version in use | ||
required: true | ||
|
||
jobs: | ||
run-backstop-tests: | ||
runs-on: ubuntu-latest | ||
container: compucorp/civicrm-buildkit:1.1.0-php7.2-chrome | ||
|
||
env: | ||
SITE_FOLDER: site | ||
SITE_URL: http://localhost:7979 | ||
CIVICRM_EXTENSIONS_DIR: web/sites/all/modules/civicrm/tools/extensions | ||
DRUPAL_MODULES_DIR: web/sites/all/modules | ||
E2E_DIR: cases-product-suite-e2e-tests | ||
DRUPAL_THEME_DIR: web/sites/all/themes | ||
SITE_NAME: drupal-clean | ||
|
||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
ports: | ||
- 3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
|
||
steps: | ||
|
||
- name: Config mysql database as per CiviCRM requirement | ||
run: echo "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));" | mysql -u root --password=root --host=mysql | ||
|
||
- name: Config amp | ||
run : | | ||
amp config:set --db_type=mysql_dsn --mysql_dsn='mysql://root:root@mysql:3306' --httpd_type=apache24 --httpd_restart_command='sudo /usr/sbin/apache2ctl graceful' --perm_type=worldWritable --hosts_type=file | ||
echo "IncludeOptional $HOME/.amp/apache.d/*.conf" >> /etc/apache2/apache2.conf | ||
/usr/sbin/apache2ctl restart | ||
|
||
- name: Install Missing Dependencies | ||
run : | | ||
sudo apt-get update | ||
sudo apt-get install -y libxshmfence-dev | ||
|
||
- name: Build Reference Drupal site -> CiviCRM - ${{ github.event.inputs.civicrm_version }} | ||
run: | | ||
civibuild create drupal-clean --civi-ver ${{ github.event.inputs.civicrm_version }} --cms-ver 7.74 --web-root $GITHUB_WORKSPACE/${{ env.SITE_FOLDER }} --url ${{ env.SITE_URL }} | ||
chmod -R 777 $GITHUB_WORKSPACE/${{ env.SITE_FOLDER }} | ||
|
||
- name: Installing CiviCase - ${{ github.event.inputs.civicase_branch }}, CiviAwards - ${{ github.event.inputs.civiawards_branch }}, CiviProspects - ${{ github.event.inputs.civiprospect_branch }}, Shoreditch - ${{ github.event.inputs.shoreditch_branch }} | ||
working-directory: ${{ env.SITE_FOLDER }}/${{ env.CIVICRM_EXTENSIONS_DIR }} | ||
run: | | ||
git clone https://github.com/compucorp/uk.co.compucorp.civicase.git --branch ${{ github.event.inputs.civicase_branch }} | ||
git clone https://github.com/compucorp/uk.co.compucorp.civiawards.git --branch ${{ github.event.inputs.civiawards_branch }} | ||
git clone https://github.com/compucorp/uk.co.compucorp.civicrm.prospect.git --branch ${{ github.event.inputs.civiprospect_branch }} | ||
git clone https://github.com/civicrm/org.civicrm.shoreditch.git --branch ${{ github.event.inputs.shoreditch_branch }} | ||
cv en shoreditch civicase civiawards prospect | ||
drush en civicrmtheme -y | ||
drush en bootstrap -y | ||
drush vset theme_default bootstrap | ||
|
||
- name: Generate CSS files for Shoreditch | ||
working-directory: ${{ env.SITE_FOLDER }}/${{ env.CIVICRM_EXTENSIONS_DIR }}/org.civicrm.shoreditch | ||
run: | | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
nvm install | ||
nvm use | ||
npm install | ||
npx gulp sass | ||
drush cc all && drush cc civicrm | ||
|
||
- name: Installing Shoreditch Companion Theme | ||
working-directory: ${{ env.SITE_FOLDER }}/${{ env.DRUPAL_THEME_DIR }} | ||
run: | | ||
git clone https://github.com/compucorp/shoreditch-companion-d7-theme.git depth=1 | ||
drush en -y shoreditch_companion_d7_theme | ||
drush vset civicrmtheme_theme_admin shoreditch_companion_d7_theme | ||
|
||
drush sql-query "UPDATE block SET status = 0 WHERE theme='shoreditch_companion_d7_theme' AND module='civicrm' AND delta IN ('1', '2', '3', '4', '5');" -y | ||
drush sql-query "UPDATE block SET status = 0 WHERE theme='shoreditch_companion_d7_theme' AND module='search' AND delta='form';" -y | ||
drush sql-query "UPDATE block SET status = 0 WHERE theme='shoreditch_companion_d7_theme' AND module='system' AND delta IN ('navigation', 'powered-by');" -y | ||
|
||
drush cc all && drush cc civicrm | ||
|
||
- name: Install E2E Test Suite | ||
run: | | ||
git clone https://github.com/compucorp/cases-product-suite-e2e-tests.git --branch master | ||
cd ${{ env.E2E_DIR }} | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
nvm install | ||
nvm use | ||
npm install | ||
|
||
- name: Setup data and site-config.json and run E2E tests | ||
working-directory: ${{ env.E2E_DIR }} | ||
run: | | ||
cp site-config.json.sample site-config.json | ||
sed -i 's+<url>+${{ env.SITE_URL }}+' site-config.json | ||
sed -i 's+<path-to-site-root>+'"$GITHUB_WORKSPACE"'/${{ env.SITE_FOLDER }}/web+' site-config.json | ||
sed -i 's+<site_name>+${{ env.SITE_NAME }}+' site-config.json | ||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||
nvm use | ||
npx gulp test | ||
|
||
- uses: actions/upload-artifact@v2 | ||
if: ${{ always() }} | ||
with: | ||
name: e2e-report | ||
path: ${{ env.E2E_DIR }}/test-report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Linters | ||
|
||
on: pull_request | ||
|
||
env: | ||
GITHUB_BASE_REF: ${{ github.base_ref }} | ||
|
||
jobs: | ||
run-linters: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set Correct NodeJS version | ||
shell: bash -l {0} | ||
run: | | ||
nvm install | ||
nvm use | ||
|
||
- name: Run npm install | ||
run: npm i | ||
|
||
- name: Fetch target branch | ||
run: git fetch -n origin ${GITHUB_BASE_REF} | ||
|
||
- name: Run eslint linter | ||
if: ${{ always() }} | ||
run: git diff --diff-filter=d origin/${GITHUB_BASE_REF} --name-only -- '*.ts' | xargs -r npx eslint --max-warnings=0 . -c .eslintrc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
cookies | ||
site-config.json | ||
test-report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"*.ts": [ | ||
"npx eslint --max-warnings=0 . -c .eslintrc.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
14.16.0 |
33 changes: 33 additions & 0 deletions
33
gulp-tasks/jest-helper/environments/e2e-test-environment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest has issues with Environment Files written in TS | ||
// https://github.com/facebook/jest/issues/5164 | ||
const NodeEnvironment = require('jest-environment-node'); | ||
|
||
class E2ETestEnvironment extends NodeEnvironment { | ||
constructor (config, context) { | ||
super(config, context); | ||
|
||
this.global.hasTestFailures = false; | ||
} | ||
|
||
async handleTestEvent (event, state) { | ||
if (event.name === 'test_fn_failure') { | ||
var testName = this.getTestName(event.test, []).reverse(); | ||
testName.shift(); | ||
|
||
this.global.failureScreenshotFileName = testName.join('_').replace(/ /g,'_'); | ||
this.global.hasTestFailures = true; | ||
} | ||
} | ||
|
||
getTestName (test, name) { | ||
name.push([test.name]); | ||
|
||
if (test.parent) { | ||
this.getTestName(test.parent, name); | ||
} | ||
|
||
return name; | ||
} | ||
} | ||
|
||
module.exports = E2ETestEnvironment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest has issues with Global Setup/TearDown Files written in TS | ||
// https://github.com/facebook/jest/issues/5164 | ||
|
||
const execSync = require('child_process').execSync; | ||
const fs = require('fs'); | ||
|
||
module.exports = async function () { | ||
var config = JSON.parse(fs.readFileSync('site-config.json')); | ||
|
||
execSync('drush en session_limit -y', { encoding: 'utf8', cwd: config.root }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as jest from 'jest-cli'; | ||
import ConfigService from '../src/services/utils/configs.service'; | ||
import BrowserService from '../src/services/utils/browser.service'; | ||
import UserRole from '../src/services/utils/user-role.service'; | ||
import changeDrupalModuleState from '../src/services/utils/change-drupal-module-state.service'; | ||
import cleanUpReports from '../src/services/utils/clean-up-reports.service'; | ||
|
||
export default jestTask; | ||
|
||
/** | ||
* @returns promise | ||
*/ | ||
async function jestTask (): Promise<void> { | ||
ConfigService.touchSiteConfigFile(); | ||
|
||
cleanUpReports(); | ||
changeDrupalModuleState('session_limit', false); | ||
|
||
UserRole.createUsersWithRoles(); | ||
|
||
const browser = new BrowserService(); | ||
|
||
await browser.writeCookies(); | ||
|
||
await jest.run(['--runInBand']); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as gulp from 'gulp'; | ||
import jestTask from './gulp-tasks/jest'; | ||
|
||
gulp.task('test', async function () { | ||
await jestTask(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
const config: Config.InitialOptions = { | ||
preset: 'jest-playwright-preset', | ||
testMatch: ['**/tests/**/(*.)spec.ts'], | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest' | ||
}, | ||
globalTeardown: '<rootDir>/gulp-tasks/jest-helper/global/teardown.js', | ||
testRunner: 'jest-circus/runner', | ||
testEnvironment: './gulp-tasks/jest-helper/environments/e2e-test-environment', | ||
reporters: [ | ||
'default', | ||
['./node_modules/jest-html-reporter', { | ||
pageTitle: 'Cases Product Suite E2E Test Report', | ||
includeFailureMsg: true, | ||
outputPath: './test-report/test-report.html' | ||
}] | ||
] | ||
}; | ||
|
||
export default config; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think the return value is inferred by TypeScript because there is no
return
and because ofasync
. TypeScript would usually infer the return value and there is no need to define it in most cases. Unless we want to make it a rule to always define it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah Standard JS is enforcing this, which is fine because now we are documenting the return type anymore using JSDoc.