diff --git a/javascriptv3/.gitignore b/javascriptv3/.gitignore index 40b878db5b1..e84913c8b63 100644 --- a/javascriptv3/.gitignore +++ b/javascriptv3/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +*_test.log \ No newline at end of file diff --git a/javascriptv3/README.md b/javascriptv3/README.md index 43720f87e06..19d0e4f503e 100644 --- a/javascriptv3/README.md +++ b/javascriptv3/README.md @@ -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 diff --git a/javascriptv3/scripts/run_tests.sh b/javascriptv3/scripts/run_tests.sh index bd9720136d1..bbcbf493e27 100755 --- a/javascriptv3/scripts/run_tests.sh +++ b/javascriptv3/scripts/run_tests.sh @@ -1,23 +1,28 @@ #!/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" ]; then +elif [[ "$1" == "integration" || "$2" == "integration" ]]; then run_integration_tests else echo "Usage: $0 [unit|integration]"