From fd4241cf2c50dbe6ebbae5fab01498ea0bf3f1a2 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 14 Feb 2024 02:53:09 +0100 Subject: [PATCH] add a github action to test the docker compose app --- .github/workflows/startup-tests.yml | 50 +++++++++++++++++++++++++---- frontend/playwright.config.ts | 5 +-- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index ae3244bf7..af023b145 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -1,4 +1,4 @@ -name: Startup Functional Tests +name: Startup Tests on: pull_request: @@ -6,13 +6,12 @@ on: env: GITHUB_WORKFLOW: github_actions + backend-directory: ./backend + working-directory: ./frontend jobs: - startup-tests: + startup-functional-test: runs-on: ubuntu-latest - env: - backend-directory: ./backend - working-directory: ./frontend services: postgres: @@ -88,8 +87,45 @@ jobs: - uses: actions/upload-artifact@v4 if: always() with: - name: startup-tests-report + name: startup-functional-test-report + path: | + ${{ env.working-directory }}/tests/reports/ + ${{ env.working-directory }}/tests/results/ + retention-days: 30 + startup-docker-compose-test: + runs-on: ubuntu-latest + env: + DJANGO_SUPERUSER_EMAIL: admin@tests.com + DJANGO_SUPERUSER_PASSWORD: 1234 + DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }} + COMPOSE_TEST: True + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: latest + - name: Install dependencies + working-directory: ${{ env.working-directory }} + run: | + npm install + npm ci + - name: Install Playwright Browsers + working-directory: ${{ env.working-directory }} + run: npx playwright install --with-deps + - name: Build the Docker app + run: docker compose up -d --build + - name: Config the Docker app + run: | + docker compose exec backend python manage.py migrate + docker compose exec backend python manage.py createsuperuser --noinput + - name: Run tests + working-directory: ${{ env.working-directory }} + run: npx playwright test tests/functional/startup.test.ts + - uses: actions/upload-artifact@v4 + if: always() + with: + name: startup-docker-test-report path: | ${{ env.working-directory }}/tests/reports/ ${{ env.working-directory }}/tests/results/ - retention-days: 30 \ No newline at end of file + retention-days: 5 \ No newline at end of file diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 46d833396..639ac2066 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -3,8 +3,9 @@ import { devices } from '@playwright/test'; const config: PlaywrightTestConfig = { webServer: { - command: 'npm run build && npm run preview', - port: 4173 + command: process.env.COMPOSE_TEST ? 'echo "The docker compose frontend server didn\'t start correctly"' : 'npm run build && npm run preview', + port: process.env.COMPOSE_TEST ? 3000 : 4173, + reuseExistingServer: process.env.COMPOSE_TEST }, testDir: 'tests', outputDir: 'tests/results',