diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 8309a99..c3b19e2 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -26,10 +26,6 @@ runs: run: pnpm test:ci shell: bash - - name: stop test DB - run: docker compose down - shell: bash - - name: tsc run: pnpm tsc shell: bash @@ -37,3 +33,8 @@ runs: - name: build run: pnpm build shell: bash + + - name: e2e local + uses: ./.github/actions/e2e + with: + target: e2e-local diff --git a/.github/actions/e2e/action.yml b/.github/actions/e2e/action.yml new file mode 100644 index 0000000..f1b1aa8 --- /dev/null +++ b/.github/actions/e2e/action.yml @@ -0,0 +1,36 @@ +name: e2e tests +description: Run e2e tests +inputs: + target: + description: 'make target to execute' + required: true +runs: + using: composite + steps: + - name: Get installed Playwright version + id: playwright-version + run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package.json').devDependencies['@playwright/test'])")" >> $GITHUB_ENV + shell: bash + + - name: Cache playwright binaries + uses: actions/cache@v3 + id: playwright-cache + with: + path: | + ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }} + + - name: Install browsers + if: steps.playwright-cache.outputs.cache-hit != 'true' + run: make e2e-install-browsers + shell: bash + + - name: ${{ inputs.environment }} UI tests + if: inputs.target == 'e2e-local' + run: ./scripts/setup-e2edb.sh && pnpx start-server-and-test dev 8000 e2e:local + shell: bash + + - name: ${{ inputs.environment }} UI tests + if: inputs.target != 'e2e-local' + run: make ${{ inputs.target }} + shell: bash diff --git a/package.json b/package.json index 32596cd..fa04e0e 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "build": "npm run clean && tsc", "clean": "rm -rf dist", "commit": "npx cz", + "e2e:local": "make e2e-local", "db:seed": "ts-node prisma/seed.ts", "db:down": "pnpm prisma migrate reset", "db:drop": "pnpm prisma db push --force-reset", diff --git a/scripts/setup-e2edb.sh b/scripts/setup-e2edb.sh new file mode 100755 index 0000000..b7d067d --- /dev/null +++ b/scripts/setup-e2edb.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +trap 'echo -e "\033[31m✖ An error occurred. Exiting...\033[0m"; exit 1;' ERR + +DATABASE_URL='postgresql://pets:pets@localhost:5432/pets?schema=public' pnpm db:migrate-dev && DATABASE_URL='postgresql://pets:pets@localhost:5432/pets?schema=public' pnpm prisma db push +echo -e "\033[32m✔ Test Database migrated\033[0m" \ No newline at end of file