diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 934826c..ff17cab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 - diff --git a/.gitignore b/.gitignore index 425a011..9a5858a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules yarn-error.log codegen.log +Brewfile.lock.json dist /deno /*.tgz diff --git a/Brewfile b/Brewfile new file mode 100644 index 0000000..e4feee6 --- /dev/null +++ b/Brewfile @@ -0,0 +1 @@ +brew "node" diff --git a/scripts/bootstrap b/scripts/bootstrap index 6752d0e..05dd47a 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -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 diff --git a/scripts/mock b/scripts/mock index 2bba227..5a8c35b 100755 --- a/scripts/mock +++ b/scripts/mock @@ -4,7 +4,7 @@ set -e cd "$(dirname "$0")/.." -if [ -n "$1" ]; then +if [[ -n "$1" && "$1" != '--'* ]]; then URL="$1" shift else @@ -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 diff --git a/scripts/test b/scripts/test index 48b637a..aa94b72 100755 --- a/scripts/test +++ b/scripts/test @@ -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 @@ -50,4 +53,5 @@ else fi # Run tests +echo "==> Running tests" ./node_modules/.bin/jest