From 5f17bfdce4abcb72b33a3e91621137251c925af3 Mon Sep 17 00:00:00 2001 From: manelcecs Date: Wed, 25 Oct 2023 13:21:37 +0200 Subject: [PATCH] Add test.sh usage Update README with testing usage --- README.md | 23 +++++++++++++++++++++++ test.sh => bin/test.sh | 11 +---------- 2 files changed, 24 insertions(+), 10 deletions(-) rename test.sh => bin/test.sh (84%) diff --git a/README.md b/README.md index bb6f6790..d13c26ac 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,29 @@ particular: If you are contributing to the development of this library, more information can be found in our [CONTRIBUTING](CONTRIBUTING.md) document. +## Testing + +In order maintain a good test coverage in this project, +we must write unit test of the entities we have and the new ones we create. + +The test must be written using the 'testContext' entity which stores the models, +the knex connection and the database transactions. +The aim to have the transactions is to be able to rollback the queries after the test suite. + +### Running the tests + +The test can be run with the bash script: bin/test.sh + +This will compose up the docker containers needed to run the tests, then will run the test suites. +After the tests, will set down the containers. + +### Debug the tests + +Assuming the use of VSCode, you can find two files inside '.vscode' folder. +This tasks describes the behaviour needed to debug the tests. + +Just simply add the breakpoints in the code editor and run 'Debug Jest' inside 'Debug and Run' tab. + ## License Copyright 2020 United Nations Office for the Coordination of Humanitarian Affairs diff --git a/test.sh b/bin/test.sh similarity index 84% rename from test.sh rename to bin/test.sh index 438bca9b..78e62e65 100755 --- a/test.sh +++ b/bin/test.sh @@ -1,14 +1,12 @@ root=$(pwd) #Global variables -USAGE='this is the usage' -DEBUG_USAGE='this is the debug usage' +USAGE='Usage: test.sh [options] [-- [options]].\n Options:\n -oc, --only-containers: only start docker containers\n -sc, --stop-containers: stop docker containers\n -k, --keep: keep jest runing after the completion of the tests suites\n -c: run tests with coverage\n -h, --help: show this help message\n --: pass extra options' KEEP=0 FORCE_STOP_JEST='--forceExit' ONLY_CONTAINERS=0 STOP_CONTAINERSq=0 COMMAND_ARGS='' -DOCKER_EXEC_ARGS='' function moveToTestDir { echo 'Moving to tests dir' @@ -23,10 +21,6 @@ function moveToRootDir { ## obtain options while [ "$1" != "" ]; do case $1 in - -d | --debug ) echo "Debug usage" - echo "$DEBUG_USAGE" - exit 0 - ;; -oc | --only-containers ) ONLY_CONTAINERS=1 ;; -sc | --stop-containers ) STOP_CONTAINERS=1 @@ -36,9 +30,6 @@ while [ "$1" != "" ]; do -c) shift COMMAND_ARGS="${COMMAND_ARGS} --coverage" ;; - --no-tty) shift - DOCKER_EXEC_ARGS="${DOCKER_EXEC_ARGS} -it" - ;; -h | --help ) echo "$USAGE" exit ;;