From 61f403241beea6ee5042e139a8d2c4eedf75e51b Mon Sep 17 00:00:00 2001 From: Sugat Bajracharya Date: Tue, 30 Jan 2024 11:42:26 +0545 Subject: [PATCH] feat(#425): Create e2e test setup --- package.json | 1 + test/e2e/test_runner.sh | 71 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 test/e2e/test_runner.sh diff --git a/package.json b/package.json index 7eaa0e646..1962a14ce 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/e2e/test_runner.sh b/test/e2e/test_runner.sh new file mode 100755 index 000000000..859457d44 --- /dev/null +++ b/test/e2e/test_runner.sh @@ -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