Skip to content

Commit

Permalink
dev: added simple smoke test for preview environment (CMC-NA) (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
swalker125 authored Jun 30, 2020
1 parent cd5cba3 commit 4a53d0e
Show file tree
Hide file tree
Showing 14 changed files with 3,096 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
"plugins": [
"codeceptjs"
],
"env": {
"browser": true,
"commonjs": true,
"es2020": true,
"codeceptjs/codeceptjs": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 11
},
"rules": {
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
}
};
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ bin/main/application.yaml
*.ipr

.DS_Store


# node_modules
package-lock.json
node_modules/

# test_output
output/
test-results/
2 changes: 2 additions & 0 deletions Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ withPipeline(type, product, component) {
./bin/add-roles-preview.sh
./bin/import-ccd-definition.sh
"""

env.URL="https://xui-ucmc-service-pr-${CHANGE_ID}.service.core-compute-preview.internal"
}

after('functionalTest:preview') {
Expand Down
33 changes: 33 additions & 0 deletions bin/wait-for.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -eu

service_base_urls=${@}

max_health_check_attempts=30

function checkHealth {
for service_base_url in ${service_base_urls}; do
curl -k --fail --silent --output /dev/null --head ${service_base_url}/health
if [ $? -ne 0 ]; then
exit 1
fi
done
}

until $(checkHealth); do
current_health_check_attempt=$((${current_health_check_attempt:-1} + 1))

if [ ${current_health_check_attempt} -gt ${max_health_check_attempts} ]; then
echo -e "\nMax number of attempts reached"
exit 1
fi

if [ ${current_health_check_attempt} -eq 2 ]; then
printf 'Awaiting healthy services'
else
printf '.'
fi

sleep 10
done
33 changes: 29 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,35 @@ task integration(type: Test) {
failFast = true
}

task smoke(type: Test) {
description = "Runs Smoke Tests"
testClassesDirs = sourceSets.smokeTest.output.classesDirs
classpath = sourceSets.smokeTest.runtimeClasspath
task installDependencies(type: Exec, description: 'Installs Yarn dependencies.') {
commandLine '/usr/bin/yarn', '--mutex', 'network', '--frozen-lockfile', '--silent', 'install'
}

task checkDependenciesIntegrity(type: Exec, description: 'Checks integrity of Yarn dependencies.') {
commandLine '/usr/bin/yarn', '--mutex', 'network', '--frozen-lockfile', '--silent', 'check', '--integrity'
}

task lintUserInterfaceTests(type: Exec, description: 'Runs linting of E2E tests.') {
commandLine '/usr/bin/yarn', '--silent', 'lint'
}

task awaitApplicationReadiness(type: Exec, description: 'Awaits until application is ready.') {
commandLine './bin/wait-for.sh', System.env.URL
}

task runSmokeTests(type: Exec, description: 'Runs smoke tests.') {
commandLine '/usr/bin/yarn', '--silent', 'test:smoke'
}

def inStrictOrder(Task... tasks) {
for (int i = 0; i < tasks.size() - 1; i++) {
tasks[i + 1].mustRunAfter(tasks[i])
}
return tasks
}

task smoke(description: 'Runs the smoke tests.') {
dependsOn(inStrictOrder(awaitApplicationReadiness, installDependencies, checkDependenciesIntegrity, lintUserInterfaceTests, runSmokeTests))
}

checkstyle {
Expand Down
45 changes: 45 additions & 0 deletions codecept.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* global process */

exports.config = {
tests: './e2e/tests/*_test.js',
output: './output',
helpers: {
Puppeteer: {
show: process.env.SHOW_BROWSER_WINDOW || false,
windowSize: '1200x900',
waitForTimeout: 20000,
chrome: {
ignoreHTTPSErrors: true,
args: process.env.PROXY_SERVER ? [`--proxy-server=${process.env.PROXY_SERVER}`,] : [],
},
},
},
include: {
I: './e2e/steps_file.js',
loginPage: './e2e/pages/login.page.js'
},
mocha: {
reporterOptions: {
'codeceptjs-cli-reporter': {
stdout: '-',
options: {
steps: false,
},
},
'mocha-junit-reporter': {
stdout: '-',
options: {
mochaFile: 'test-results/result.xml',
},
},
'mochawesome': {
stdout: '-',
options: {
reportDir: './output',
inlineAssets: true,
json: false,
},
},
}
}
}
8 changes: 8 additions & 0 deletions e2e/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const defaultPassword = 'Password12';

module.exports = {
solicitorUser: {
password: defaultPassword,
email: '[email protected]'
}
};
17 changes: 17 additions & 0 deletions e2e/pages/login.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { I } = inject();

module.exports = {

fields: {
username: '#username',
password: '#password',
},
submitButton: 'input[value="Sign in"]',

signIn(user) {
I.waitForElement(this.submitButton);
I.fillField(this.fields.username, user.email);
I.fillField(this.fields.password, user.password);
I.click(this.submitButton);
},
};
12 changes: 12 additions & 0 deletions e2e/steps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types='codeceptjs' />
type steps_file = typeof import('./steps_file.js');

declare namespace CodeceptJS {
interface SupportObject { I: CodeceptJS.I }
interface CallbackOrder { [0]: CodeceptJS.I }
interface Methods extends CodeceptJS.Puppeteer {}
interface I extends ReturnType<steps_file> {}
namespace Translation {
interface Actions {}
}
}
10 changes: 10 additions & 0 deletions e2e/steps_file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// in this file you can append custom step methods to 'I' object

module.exports = function() {
return actor({

// Define custom steps here, use 'this' to access default methods of I.
// It is recommended to place a general 'login' function here.

});
};
11 changes: 11 additions & 0 deletions e2e/tests/smoke_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* global process */
const config = require('../config.js');
const baseUrl = process.env.URL || 'http://localhost:3333';

Feature('Smoke tests @smoke-tests');

Scenario('Sign in as solicitor user', (I, loginPage) => {
I.amOnPage(baseUrl);
loginPage.signIn(config.solicitorUser);
I.see('Case List');
});
5 changes: 5 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowJs": true
}
}
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ucmc-service",
"version": "1.0.0",
"description": "Civil Unspecified e2e tests",
"scripts": {
"lint": "eslint e2e",
"test": "npx codeceptjs run --steps",
"test:smoke": "MOCHAWESOME_REPORTFILENAME=smoke npx codeceptjs run --grep @smoke-tests --reporter mocha-multi"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint"
}
},
"license": "MIT",
"devDependencies": {
"codeceptjs": "^2.6.6",
"eslint": "^7.3.1",
"eslint-plugin-codeceptjs": "^1.3.0",
"husky": "^4.2.5",
"mocha-multi": "^1.1.3",
"mochawesome": "^6.1.1",
"puppeteer": "^4.0.1"
}
}
Loading

0 comments on commit 4a53d0e

Please sign in to comment.