From 936ef0546552476a7f2fcf6c38c3c7a071d8115f Mon Sep 17 00:00:00 2001 From: QAComet Date: Mon, 25 Mar 2024 14:41:53 -0600 Subject: [PATCH] feat(action): write github action for running tests on new PR's --- .github/workflows/test-e2e.yaml | 136 ++++++++++++++++++++++++++++++++ playwright.config.ts | 2 +- 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-e2e.yaml diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml new file mode 100644 index 000000000..136a748cd --- /dev/null +++ b/.github/workflows/test-e2e.yaml @@ -0,0 +1,136 @@ +name: Medusa NextJS Template Tests + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +env: + PGHOST: localhost + PGPORT: 5432 + PGUSER: postgres + PGPASSWORD: password + PGDATABASE: postgres + + TEST_POSTGRES_USER: test_medusa_user + TEST_POSTGRES_PASSWORD: password + TEST_POSTGRES_DATABASE: test_medusa_db + TEST_POSTGRES_DATABASE_TEMPLATE: test_medusa_db_template + TEST_POSTGRES_HOST: localhost + TEST_POSTGREST_PORT: 5432 + PRODUCTION_POSTGRES_DATABASE: medusa_db + CLIENT_SERVER: http://localhost:9000 + + JWT_SECRET: something + COOKIE_SECRET: something + + DATABASE_TYPE: "postgres" + REDIS_URL: redis://localhost:6379 + DATABASE_URL: postgres://test_medusa_user:password@localhost/test_medusa_db + NEXT_PUBLIC_BASE_URL: http://localhost:8000 + +jobs: + e2e-test-runner: + timeout-minutes: 20 + runs-on: + - ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: password + POSTGRES_DB: test + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + meilisearch: + image: getmeili/meilisearch:v1.7 + ports: + - 7700:7700 + options: >- + --health-cmd "curl --fail http://localhost:7700/health" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + redis: + image: redis:latest + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v2 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Initialize PostgreSQL + run: | + echo "Initializing Databases" + psql -h localhost -U postgres -d test -c "CREATE USER ${{ env.TEST_POSTGRES_USER }} WITH PASSWORD '${{ env.TEST_POSTGRES_PASSWORD }}';" + psql -h localhost -U postgres -d test -c "CREATE DATABASE ${{ env.TEST_POSTGRES_DATABASE }} OWNER ${{ env.TEST_POSTGRES_USER }};" + + - name: Install Medusa CLI + run: npm install @medusajs/medusa-cli -g + - name: Setup medusa backend server + working-directory: ../ + # https://docs.medusajs.com/cli/reference#options + run: | + medusa new backend \ + -y \ + --skip-db \ + --skip-migrations \ + --skip-env \ + --db-user ${{ env.TEST_POSTGRES_USER }} \ + --db-pass ${{ env.TEST_POSTGRES_PASSWORD }} \ + --db-database ${{ env.TEST_POSTGRES_DATABASE }} \ + --db-host ${{ env.TEST_POSTGRES_HOST }} \ + --db-port ${{ env.TEST_POSTGREST_PORT }} + + - name: Build the backend + working-directory: ../backend + run: yarn build:admin + + - name: Seed data from default seed file + working-directory: ../backend + run: medusa seed --seed-file=data/seed.json + + - name: Run backend server + working-directory: ../backend + run: medusa develop & + + - name: Install packages + run: yarn install -y + + - name: Install playwright + run: yarn playwright install --with-deps + + - name: Copy environment + run: cp .env.template .env + + - name: Setup frontend + run: yarn build + + - name: Run Tests + run: yarn test-e2e + + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: test-results + retention-days: 30 diff --git a/playwright.config.ts b/playwright.config.ts index 3960498e4..ffca4f042 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -70,7 +70,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: { - command: 'npm run start', + command: 'yarn start', url: process.env.NEXT_PUBLIC_BASE_URL, // reuseExistingServer: !process.env.CI, },