Skip to content

Commit

Permalink
chore: combine examples scripts
Browse files Browse the repository at this point in the history
Signed-off-by: JP-Ellis <josh@jpellis.me>
  • Loading branch information
JP-Ellis committed Dec 16, 2024
1 parent 7074fbe commit 37102f7
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 87 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ Run a single example
Run all examples

1. Change into the examples folder `cd examples`
2. Install all the examples dependencies `./installAll.sh`
3. Run all the examples `./runAll.sh`
2. Run all examples `./run-all`

![----------](https://user-images.githubusercontent.com/53900/182992715-aa63e421-170b-41cf-8f95-82fe4b0846c2.png)

Expand Down
42 changes: 0 additions & 42 deletions examples/installAll.sh

This file was deleted.

94 changes: 94 additions & 0 deletions examples/run-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

set -o errexit # Exit on error
set -o nounset # Treat unset variables as an error

usage() {
echo "Usage: $0 [command]"
echo
echo "Run tests or a specific command in all examples"
echo
echo "Commands:"
echo " <none> Run all example tests (both 'npm ci' and 'npm test')"
echo " <cmd> Run a specific npm command (e.g., 'audit' for npm audit)"
echo
echo "Examples:"
echo " $0"
echo " $0 test"
echo " $0 audit"
exit 0
}

run_example() {
local example_dir="$1"
shift
if [ $# -gt 0 ]; then
echo "Ignoring extra arguments: $*"
fi

echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
echo "$(tput bold)$(tput setaf 7)Running example in $example_dir$(tput sgr0)"
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"

if [ -d "$example_dir/node_modules" ]; then
echo "$(tput bold)$(tput setaf 7)Skipping installation of dependencies$(tput sgr0)"
else
npm --prefix "$example_dir" ci
fi

echo "$(tput bold)$(tput setaf 7)Running tests$(tput sgr0)"
npm --prefix "$example_dir" run test
}

run_cmd() {
local example_dir="$1"
shift
if [ $# -eq 0 ]; then
echo "No command provided"
exit 1
fi
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
echo "$(tput bold)$(tput setaf 7)Running '$*' in $example_dir$(tput sgr0)"
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
npm --prefix "$example_dir" "$@"
}

main() {
if [ "${1-}" = "--help" ] || [ "${1-}" = "-h" ]; then
usage
fi

declare -a examples=(
examples/e2e
examples/graphql
examples/jest
examples/messages
examples/mocha
examples/serverless
examples/typescript
examples/v3/e2e
examples/v3/provider-state-injected
examples/v3/run-specific-verifications
examples/v3/todo-consumer
examples/v3/typescript
examples/v4/matchers
examples/v4/plugins
)

if [ $# -gt 0 ]; then
for example in "${examples[@]}"; do
run_cmd "$example" "$@"
done
else
declare -a failed_examples=()
for example in "${examples[@]}"; do
run_example "$example" || failed_examples+=("$example")
done

for failed_example in "${failed_examples[@]}"; do
echo "$(tput bold)$(tput setaf 1)Failed to run example in $failed_example$(tput sgr0)"
done
fi
}

main "$@"
43 changes: 0 additions & 43 deletions examples/runAll.sh

This file was deleted.

0 comments on commit 37102f7

Please sign in to comment.