Skip to content

Commit

Permalink
feat(#425): Create e2e test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
sugat009 committed Feb 1, 2024
1 parent f7abaa0 commit 61f4032
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"docker-start-couchdb": "npm run docker-stop-couchdb && docker run -d -p 6984:5984 --rm --name cht-conf-couchdb couchdb:2.3.1 && sh test/scripts/wait_for_response_code.sh 6984 200 CouchDB",
"docker-stop-couchdb": "docker stop cht-conf-couchdb || true",
"test": "npm run eslint && npm run docker-start-couchdb && npm run clean && mkdir -p build/test && cp -r test/data build/test/data && cd build/test && nyc --reporter=html mocha --forbid-only \"../../test/**/*.spec.js\" && cd ../.. && npm run docker-stop-couchdb",
"test-e2e": "npm run eslint && ./test/e2e/test_runner.sh",
"semantic-release": "semantic-release"
},
"bin": {
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/test_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

set -eu

chtCoreDockerComposeFile='cht-docker-compose.sh'
chtCoreDockerComposeUrl='https://raw.githubusercontent.com/medic/cht-core/master/scripts/docker-helper-4.x/cht-docker-compose.sh'
chtCoreProjectName='cht_conf_e2e_tests'
chtConfe2eFolderName='e2e_tests'
currentDir=$(pwd)

log_info() {
echo "[INFO] $1"
}

log_error() {
echo "[ERROR] $1"
}

setup() {
log_info "Starting cht-conf e2e tests"

mkdir -p "$chtConfe2eFolderName"
cd "$chtConfe2eFolderName"

log_info "Setting up cht-core"

curl -s -o "$chtCoreDockerComposeFile" "$chtCoreDockerComposeUrl"
chmod +x "$chtCoreDockerComposeFile"

if {
echo "y"
echo "y"
echo "$chtCoreProjectName"
} | ./"$chtCoreDockerComposeFile"; then
log_info "cht-core setup complete."
else
log_error "Failed to set up cht-core. Manual cleanup may be required. Exiting."
exit 1
fi

# since the setup is completed if the execution flow
# reaches here, this makes sure that the destruction of
# the setup always occurs
trap destroy EXIT
trap destroy ERR
}

run_tests() {
log_info "Running e2e tests"

nyc --reporter=html mocha --forbid-only "../test/e2e/**/*.spec.js"

log_info "e2e tests complete"
}

destroy() {
log_info "Destroying cht-core."

if ./"$chtCoreDockerComposeFile" "$chtCoreProjectName.env" destroy; then
log_info "cht-core destroy complete. Exiting."
else
log_error "Failed to destroy cht-core. Manual cleanup may be required."
fi

cd "$currentDir"
rm -rf "$chtConfe2eFolderName"
}

setup

run_tests

0 comments on commit 61f4032

Please sign in to comment.