Skip to content

Commit

Permalink
chore(internal): add scripts/test, scripts/mock and add ci job (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed May 1, 2024
1 parent 9e9e7f4 commit 1ce2aac
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,22 @@ jobs:
- name: Check types
run: |
yarn build
test:
name: test
runs-on: ubuntu-latest
if: github.repository == 'Finch-API/finch-api-node'

steps:
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Run tests
run: ./scripts/test

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
/*.tgz
Expand Down
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
brew "node"
9 changes: 9 additions & 0 deletions scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ set -e

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

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then
brew bundle check >/dev/null 2>&1 || {
echo "==> Installing Homebrew dependencies…"
brew bundle
}
fi

echo "==> Installing Node dependencies…"

PACKAGE_MANAGER=$(command -v yarn >/dev/null 2>&1 && echo "yarn" || echo "npm")

$PACKAGE_MANAGER install
5 changes: 4 additions & 1 deletion scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

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

if [ -n "$1" ]; then
if [[ -n "$1" && "$1" != '--'* ]]; then
URL="$1"
shift
else
Expand All @@ -17,11 +17,14 @@ if [ -z "$URL" ]; then
exit 1
fi

echo "==> Starting mock server with URL ${URL}"

# Run prism mock on the given spec
if [ "$1" == "--daemon" ]; then
npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock "$URL" &> .prism.log &

# Wait for server to come online
echo -n "Waiting for server"
while ! grep -q "✖ fatal\|Prism is listening" ".prism.log" ; do
echo -n "."
sleep 0.1
Expand Down
10 changes: 7 additions & 3 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ if ! is_overriding_api_base_url && ! prism_is_running ; then
trap 'kill_server_on_port 4010' EXIT

# Start the dev server
./scripts/mock --daemon &> /dev/null
./scripts/mock --daemon
fi

if ! prism_is_running ; then
if is_overriding_api_base_url ; then
echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}"
echo
elif ! prism_is_running ; then
echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server"
echo -e "running against your OpenAPI spec."
echo
echo -e "To run the server, pass in the path or url of your OpenAPI"
echo -e "spec to the prism command:"
echo
echo -e " \$ ${YELLOW}npm exec prism mock path/to/your.openapi.yml${NC}"
echo -e " \$ ${YELLOW}npm exec --package=@stoplight/prism-cli@~5.3.2 -- prism mock path/to/your.openapi.yml${NC}"
echo

exit 1
Expand All @@ -50,4 +53,5 @@ else
fi

# Run tests
echo "==> Running tests"
./node_modules/.bin/jest

0 comments on commit 1ce2aac

Please sign in to comment.