-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from UN-OCHA/tests
HPC-8232, HPC-7811, HPC-8130 - setup testing environment with jest and docker
- Loading branch information
Showing
19 changed files
with
10,290 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,4 @@ | |
/index.d.ts | ||
/yarn-error.log | ||
package-lock.json | ||
|
||
# IDE artifacts | ||
.vscode | ||
tests/data/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Jest Tests", | ||
"type": "node", | ||
"preLaunchTask": "start-containers", | ||
"request": "launch", | ||
"runtimeArgs": [ | ||
"--inspect-brk", | ||
"${workspaceRoot}/node_modules/.bin/jest", | ||
"--runInBand", | ||
"--detectOpenHandles" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "start-containers", | ||
"type": "shell", | ||
"command": "${workspaceRoot}/bin/test.sh", | ||
"args": ["-oc"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env bash | ||
|
||
root=$(pwd) | ||
|
||
# Global variables | ||
USAGE="$(basename "$0") [-h] [-oc] [-k] [-w ${ALL_CONFIGS:1}] | ||
where: | ||
-oc, --only-containers: Only start docker containers | ||
-sc, --stop-containers: Stop docker containers | ||
-k, --keep : Keep Jest runing after the completion of the tests suites | ||
-c : Run tests with coverage | ||
-h, --help : Show this help text | ||
--[a1] [a2]... : Pass additional arguments to test script" | ||
KEEP=0 | ||
FORCE_STOP_JEST='--forceExit' | ||
ONLY_CONTAINERS=0 | ||
COMMAND_ARGS='' | ||
|
||
function moveToTestDir { | ||
cd ${root}/tests | ||
} | ||
|
||
function moveToRootDir { | ||
cd ${root} | ||
} | ||
|
||
# Obtain options | ||
while [ "$1" != "" ]; do | ||
case $1 in | ||
-oc | --only-containers ) ONLY_CONTAINERS=1 | ||
;; | ||
-sc | --stop-containers ) STOP_CONTAINERS=1 | ||
;; | ||
-k | --keep ) KEEP=1 | ||
;; | ||
-c) shift | ||
COMMAND_ARGS="${COMMAND_ARGS} --coverage" | ||
;; | ||
-h | --help ) echo "$USAGE" | ||
exit | ||
;; | ||
--) shift | ||
while [ "$1" != "" ]; do | ||
COMMAND_ARGS="${COMMAND_ARGS} -- $1" | ||
shift | ||
done | ||
;; | ||
* ) echo "$USAGE" | ||
exit 1 | ||
esac | ||
shift | ||
done | ||
|
||
# STOP_CONTAINERS is a final option | ||
if [ "$STOP_CONTAINERS" -eq 1 ]; then | ||
echo 'Stopping Docker containers' | ||
moveToTestDir | ||
docker compose down | ||
exit 0 | ||
fi | ||
|
||
# ONLY_CONTAINERS must be 1 and STOP must be 0 | ||
if [ $ONLY_CONTAINERS -eq 1 ] && [ "$STOP" -eq 1 ]; then | ||
echo 'Invalid options - when using option -oc, option -ns must be used as well' | ||
echo "$USAGE" | ||
exit 1 | ||
fi | ||
|
||
echo 'Starting Docker containers' | ||
moveToTestDir | ||
docker compose up -d | ||
|
||
if [ $ONLY_CONTAINERS -eq 1 ]; then | ||
exit 0 | ||
fi | ||
|
||
# Run tests | ||
echo 'Running tests' | ||
moveToRootDir | ||
|
||
if [ $KEEP -eq 0 ]; then | ||
FORCE_STOP_JEST='' | ||
fi | ||
|
||
yarn jest "$COMMAND_ARGS" $FORCE_STOP_JEST | ||
|
||
if [ $KEEP -eq 0 ]; then | ||
# Stop Docker containers | ||
echo 'Stopping docker containers' | ||
moveToTestDir | ||
docker compose down | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
const config: Config.InitialOptions = { | ||
verbose: true, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testPathIgnorePatterns: ['<rootDir>/node_modules/'], | ||
testMatch: ['<rootDir>/**/*.spec.ts'], | ||
coveragePathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/'], | ||
clearMocks: true, | ||
transform: { | ||
'^.+\\.ts?$': 'ts-jest', | ||
}, | ||
transformIgnorePatterns: ['node_modules/(?!(@unocha)/)'], | ||
modulePathIgnorePatterns: ['<rootDir>/test/'], | ||
setupFilesAfterEnv: ['<rootDir>/tests/test-environment-setup.ts'], | ||
testTimeout: 100_000, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
services: | ||
db: | ||
image: postgres:14.8-alpine3.18 | ||
container_name: hpc-postgres-test-api-core | ||
ports: | ||
- 6432:5432 | ||
environment: | ||
- POSTGRES_DB=hpc-test | ||
- POSTGRES_USER=postgres | ||
- POSTGRES_HOST_AUTH_METHOD=trust | ||
volumes: | ||
- ./migration/schema-2024-02-29.sql:/docker-entrypoint-initdb.d/init.sql |
Oops, something went wrong.