Skip to content

Commit

Permalink
JavaScript (v3): Update test script for better usability and error re…
Browse files Browse the repository at this point in the history
…porting.
  • Loading branch information
cpyle0819 committed Oct 4, 2023
1 parent 1d52fa7 commit 08cc79d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
3 changes: 2 additions & 1 deletion javascriptv3/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
*_test.log
12 changes: 8 additions & 4 deletions javascriptv3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ You can run tests for a specific service, or for every service in this repositor

`npm test`

- To run only unit tests, set the `TEST_SCOPE` variable to `unit`:
- To run only unit tests, use the "unit" argument:

`TEST_SCOPE=unit npm test`
`npm test unit`

- To run only integration tests, set the `TEST_SCOPE` variable to `integration`:
- To run only integration tests, use the "integration" argument:

`TEST_SCOPE=integration npm test`
`npm test integration`

- To run tests for a specific service, follow the instructions in the service's README.

### Output

If you run tests using the preceding commands, output will be stored in `unit_test.log` or `integration_test.log`. Errors are still logged to the console.

## Docker image (Beta)

This example is available in a container image
Expand Down
31 changes: 18 additions & 13 deletions javascriptv3/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/bin/bash

function run_unit_tests() {
if ! npm run test --workspaces --if-present; then
exit 1
fi
run_unit_tests() {
# Write stdout to a file and stderr to stdout
npm run test --workspaces --if-present -- --silent 2>&1 > unit_test.log
}

function run_integration_tests() {
if ! npm run integration-test --workspaces --if-present; then
exit 1
fi
run_integration_tests() {
# Write stdout to a file and stderr to stdout
npm run integration-test --workspaces --if-present --silent 2>&1 > integration_test.log
}

if [ -z "$1" ]; then
echo "Usage: $0 [unit|integration]"
run_all() {
if ! run_unit_tests || ! run_integration_tests; then
exit 1
elif [ "$1" == "unit" ]; then
fi
}

if [[ $# -eq 0 ]]; then
run_unit_tests
elif [[ "$1" == "unit" && "$2" == "integration" ]] || [[ "$1" == "integration" && "$2" == "unit" ]]; then
run_all
elif [[ "$1" == "unit" || "$2" == "unit" ]]; then
run_unit_tests
elif [[ "$1" == "integration" || "$2" == "integration" ]]; then
run_unit_tests
elif [ "$1" == "integration" ]; then
run_integration_tests
else
echo "Usage: $0 [unit|integration]"
exit 1
Expand Down

0 comments on commit 08cc79d

Please sign in to comment.