Skip to content

Commit 37102f7

Browse files
committed
chore: combine examples scripts
Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent 7074fbe commit 37102f7

File tree

4 files changed

+95
-87
lines changed

4 files changed

+95
-87
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ Run a single example
202202
Run all examples
203203

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

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

examples/installAll.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

examples/run-all

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
set -o errexit # Exit on error
4+
set -o nounset # Treat unset variables as an error
5+
6+
usage() {
7+
echo "Usage: $0 [command]"
8+
echo
9+
echo "Run tests or a specific command in all examples"
10+
echo
11+
echo "Commands:"
12+
echo " <none> Run all example tests (both 'npm ci' and 'npm test')"
13+
echo " <cmd> Run a specific npm command (e.g., 'audit' for npm audit)"
14+
echo
15+
echo "Examples:"
16+
echo " $0"
17+
echo " $0 test"
18+
echo " $0 audit"
19+
exit 0
20+
}
21+
22+
run_example() {
23+
local example_dir="$1"
24+
shift
25+
if [ $# -gt 0 ]; then
26+
echo "Ignoring extra arguments: $*"
27+
fi
28+
29+
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
30+
echo "$(tput bold)$(tput setaf 7)Running example in $example_dir$(tput sgr0)"
31+
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
32+
33+
if [ -d "$example_dir/node_modules" ]; then
34+
echo "$(tput bold)$(tput setaf 7)Skipping installation of dependencies$(tput sgr0)"
35+
else
36+
npm --prefix "$example_dir" ci
37+
fi
38+
39+
echo "$(tput bold)$(tput setaf 7)Running tests$(tput sgr0)"
40+
npm --prefix "$example_dir" run test
41+
}
42+
43+
run_cmd() {
44+
local example_dir="$1"
45+
shift
46+
if [ $# -eq 0 ]; then
47+
echo "No command provided"
48+
exit 1
49+
fi
50+
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
51+
echo "$(tput bold)$(tput setaf 7)Running '$*' in $example_dir$(tput sgr0)"
52+
echo "$(tput bold)$(tput setaf 7)========================================$(tput sgr0)"
53+
npm --prefix "$example_dir" "$@"
54+
}
55+
56+
main() {
57+
if [ "${1-}" = "--help" ] || [ "${1-}" = "-h" ]; then
58+
usage
59+
fi
60+
61+
declare -a examples=(
62+
examples/e2e
63+
examples/graphql
64+
examples/jest
65+
examples/messages
66+
examples/mocha
67+
examples/serverless
68+
examples/typescript
69+
examples/v3/e2e
70+
examples/v3/provider-state-injected
71+
examples/v3/run-specific-verifications
72+
examples/v3/todo-consumer
73+
examples/v3/typescript
74+
examples/v4/matchers
75+
examples/v4/plugins
76+
)
77+
78+
if [ $# -gt 0 ]; then
79+
for example in "${examples[@]}"; do
80+
run_cmd "$example" "$@"
81+
done
82+
else
83+
declare -a failed_examples=()
84+
for example in "${examples[@]}"; do
85+
run_example "$example" || failed_examples+=("$example")
86+
done
87+
88+
for failed_example in "${failed_examples[@]}"; do
89+
echo "$(tput bold)$(tput setaf 1)Failed to run example in $failed_example$(tput sgr0)"
90+
done
91+
fi
92+
}
93+
94+
main "$@"

examples/runAll.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)