Skip to content

Commit b7a3d87

Browse files
chore(internal): allow the mock server port to be set with STAINLESS_MOCK_PORT
1 parent 3f47b22 commit b7a3d87

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

scripts/mock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -e
44

55
cd "$(dirname "$0")/.."
66

7+
if [ "$1" == "--install" ]; then
8+
npm exec --package=@stdy/cli@0.22.1 -- steady --version
9+
exit 0
10+
fi
11+
712
if [[ -n "$1" && "$1" != '--'* ]]; then
813
URL="$1"
914
shift
@@ -20,16 +25,18 @@ fi
2025
echo "==> Starting mock server with URL ${URL}"
2126

2227
# Run steady mock on the given spec
28+
MOCK_PORT="${STAINLESS_MOCK_PORT:-4010}"
29+
2330
if [ "$1" == "--daemon" ]; then
2431
# Pre-install the package so the download doesn't eat into the startup timeout
2532
npm exec --package=@stdy/cli@0.22.1 -- steady --version
2633

27-
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
34+
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p "$MOCK_PORT" --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
2835

2936
# Wait for server to come online via health endpoint (max 30s)
3037
echo -n "Waiting for server"
3138
attempts=0
32-
while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do
39+
while ! curl --silent --fail "http://127.0.0.1:$MOCK_PORT/_x-steady/health" >/dev/null 2>&1; do
3340
if ! kill -0 $! 2>/dev/null; then
3441
echo
3542
cat .stdy.log
@@ -48,5 +55,5 @@ if [ "$1" == "--daemon" ]; then
4855

4956
echo
5057
else
51-
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
58+
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p "$MOCK_PORT" --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
5259
fi

scripts/test

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ GREEN='\033[0;32m'
99
YELLOW='\033[0;33m'
1010
NC='\033[0m' # No Color
1111

12+
MOCK_PORT="${STAINLESS_MOCK_PORT:-4010}"
13+
1214
function steady_is_running() {
13-
curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1
15+
curl --silent "http://127.0.0.1:$MOCK_PORT/_x-steady/health" >/dev/null 2>&1
1416
}
1517

1618
find_pids_on_port_via_proc() {
@@ -60,7 +62,7 @@ function is_overriding_api_base_url() {
6062

6163
if ! is_overriding_api_base_url && ! steady_is_running ; then
6264
# When we exit this script, make sure to kill the background mock server process
63-
trap 'kill_server_on_port 4010' EXIT
65+
trap 'kill_server_on_port "$MOCK_PORT"' EXIT
6466

6567
# Start the dev server
6668
./scripts/mock --daemon
@@ -76,7 +78,7 @@ elif ! steady_is_running ; then
7678
echo -e "To run the server, pass in the path or url of your OpenAPI"
7779
echo -e "spec to the steady command:"
7880
echo
79-
echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
81+
echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p $MOCK_PORT --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
8082
echo
8183

8284
exit 1
@@ -85,6 +87,10 @@ else
8587
echo
8688
fi
8789

90+
if [ -n "${STAINLESS_MOCK_PORT:-}" ] && ! is_overriding_api_base_url ; then
91+
export TEST_API_BASE_URL="http://127.0.0.1:$MOCK_PORT"
92+
fi
93+
8894
export DEFER_PYDANTIC_BUILD=false
8995

9096
# Note that we need to specify the patch version here so that uv

0 commit comments

Comments
 (0)