-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(internal): add scripts/test and scripts/mock (#801)
- Loading branch information
1 parent
c6629c3
commit 6656105
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "$1" ]; then | ||
URL="$1" | ||
shift | ||
else | ||
URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)" | ||
fi | ||
|
||
# Check if the URL is empty | ||
if [ -z "$URL" ]; then | ||
echo "Error: No OpenAPI spec path/url provided or found in .stats.yml" | ||
exit 1 | ||
fi | ||
|
||
# Run prism mock on the given spec | ||
if [ "$1" == "--daemon" ]; then | ||
npm exec prism mock "$URL" &> .prism.log & | ||
|
||
# Wait for server to come online | ||
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do | ||
echo -n "." | ||
sleep 0.1 | ||
done | ||
|
||
if grep -q "✖ fatal" ".prism.log"; then | ||
cat .prism.log | ||
exit 1 | ||
fi | ||
|
||
echo | ||
else | ||
npm exec prism mock "$URL" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
function prism_is_running() { | ||
curl --silent "http://localhost:4010" >/dev/null 2>&1 | ||
} | ||
|
||
kill_server_on_port() { | ||
pids=$(lsof -t -i tcp:"$1" || echo "") | ||
if [ "$pids" != "" ]; then | ||
kill "$pids" | ||
echo "Stopped $pids." | ||
fi | ||
} | ||
|
||
if ! prism_is_running; then | ||
# When we exit this script, make sure to kill the background mock server process | ||
trap 'kill_server_on_port 4010' EXIT | ||
|
||
# Start the dev server | ||
./scripts/mock --daemon | ||
|
||
# Sanity check and print a nice error message | ||
if ! ./bin/check-test-server; then | ||
exit | ||
fi | ||
fi | ||
|
||
# Run tests | ||
./node_modules/.bin/jest |