Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript (v3): Update test script for better usability and error reporting. #5471

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 17 additions & 12 deletions javascriptv3/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -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]"
Expand Down
Loading