Skip to content

Commit

Permalink
Add test.sh usage
Browse files Browse the repository at this point in the history
Update README with testing usage
  • Loading branch information
manelcecs committed Nov 9, 2023
1 parent 5163f4c commit 5f17bfd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions test.sh → bin/test.sh
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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
;;
Expand Down

0 comments on commit 5f17bfd

Please sign in to comment.