name: Dusk
on: [ push ]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false

jobs:
  dusk:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: true
      max-parallel: 1
      matrix:
        php-versions: [ '8.2' ]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        env:
          DEBUG: true
          APP_ENV: "testing"
      - uses: ./.github/actions/setup-php
        with:
          php_version: ${{ matrix.php-versions }}
          extensions: mbstring, dom, fileinfo, mysql, gd, curl, zip, sqlite, xml,
      - name: Npm install
        uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: 'npm'
          cache-dependency-path: ./package-lock.json
      - run: npm install
      - run: npm run build
      - run: php artisan dusk:install
      - run: php artisan dusk:chrome-driver
      - name: Remove screenshot layout test
        run: |
          rm -f userfiles/templates/big/src/tests/Browser/BigScreenshotLayoutsTest.php
      - name: Run Laravel Server
        #run: php artisan serve-test --env=testing > /dev/null 2>&1 &
        #run: APP_ENV=testing && php -d variables_order=EGPCS -S 127.0.0.1:8000 > /dev/null 2>&1 &
       # run: APP_ENV=testing && php -d variables_order=EGPCS -S 127.0.0.1:8000 > /home/runner/work/microweber/microweber/storage/logs/serve.log 2>&1 &
        run: APP_ENV=testing && php artisan serve-test-code-coverage --ansi --env=testing --no-interaction --quiet &
      - name: Run Dusk Tests
        run: |
          chmod -R 0755 vendor/laravel/dusk/bin/
          composer test:dusk
      - name: Upload Screenshots
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: screenshots
          path: tests/Browser/screenshots
      - name: Upload Console Logs
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: console
          path: tests/Browser/console
      - name: Upload Laravel Storage Logs
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: storage-logs
          path: storage/logs
      - name: Upload Laravel config
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: config
          path: config
