Skip to content

Commit

Permalink
chore: replace karma with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
Joozty committed Nov 7, 2024
1 parent adc7496 commit 68b4baa
Show file tree
Hide file tree
Showing 20 changed files with 2,423 additions and 122 deletions.
36 changes: 36 additions & 0 deletions .github/actions/install-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Install playwright'
description: 'Install Playwright browser binaries and OS dependencies'
runs:
using: 'composite'
steps:
- name: Get installed Playwright version
id: playwright-version
shell: bash
run: |
PLAYWRIGHT_VERSION=$(npm ls --json playwright | jq --raw-output '.[0].devDependencies.playwright.version')
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Set up path for Playwright cache
shell: bash
run: echo "PLAYWRIGHT_CACHE_PATH=$(if [[ $RUNNER_OS == 'macOS' ]]; then echo '~/Library/Caches/ms-playwright'; else echo '~/.cache/ms-playwright'; fi)" >> $GITHUB_ENV

- name: Cache Playwright binaries
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
id: playwright-cache
with:
path: ${{ env.PLAYWRIGHT_CACHE_PATH }}
key: '${{ runner.os }}-playwright-cache-${{ env.PLAYWRIGHT_VERSION }}-splunk-otel-js-web-artifacts'

- name: Install Playwright browser binaries
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash
run: |
npm exec playwright install --with-deps
npm exec playwright install chrome
npm exec playwright install msedge
npm exec playwright install webkit
- name: Install Playwright OS dependencies
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash
run: npm exec playwright install-deps
4 changes: 4 additions & 0 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ jobs:
- run: npm run compile
- name: Local integration tests using ${{ matrix.browser }}
run: npm run test:integration:local:${{ matrix.browser }}:_execute

playwright:
uses: ./.github/workflows/tests.yml
secrets: inherit
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ jobs:
path: |
packages/web/tests_output/
packages/web/logs/
playwright:
uses: ./.github/workflows/tests.yml
secrets: inherit
118 changes: 118 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Playwright tests
on:
workflow_call:

jobs:
playwright:
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox, chrome, edge]
name: Playwright Tests - ${{ matrix.browser }}
steps:
- name: Checkout
uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: '18'
cache: 'npm'
- run: npm ci
- run: npm run compile

- name: Install playwright
uses: ./.github/actions/install-playwright

- name: Run Playwright tests
run: |
pnpm exec playwright test --project ${{ matrix.browser }}
working-directory: ./packages/integration-tests

- name: Upload blob report to GitHub Actions Artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: blob-report-${{ matrix.browser }}-attempt-${{ github.run_attempt }}
path: packages/integration-tests/blob-report
retention-days: 1

playwright-macos:
timeout-minutes: 60
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
browser: [webkit]
steps:
- name: Checkout
uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: '18'
cache: 'npm'
- run: npm ci
- run: npm run compile

- name: Install playwright
uses: ./.github/actions/install-playwright

- name: Run Playwright tests
run: |
pnpm exec playwright test --project ${{ matrix.browser }}
working-directory: ./packages/integration-tests

- name: Upload blob report to GitHub Actions Artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: blob-report-${{ matrix.browser }}-attempt-${{ github.run_attempt }}
path: packages/integration-tests/blob-report
retention-days: 1

merge-reports:
if: ${{ !cancelled() }}
needs: [playwright, playwright-macos]

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: '18'
cache: 'npm'
- run: npm ci
- run: npm run compile

- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
path: packages/integration-tests/all-blob-reports
pattern: blob-report-*
merge-multiple: true

- name: Merge into HTML Report
run: pnpm exec playwright merge-reports --reporter html ./all-blob-reports -c playwright.config.ts
working-directory: ./packages/integration-tests

- name: Upload HTML report
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: playwright-report--attempt-${{ github.run_attempt }}
path: packages/integration-tests/playwright-report
retention-days: 14

check-failure:
needs: [playwright, playwright-macos, merge-reports]
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Check if any playwright tests failed
run: |
if [ "${{ needs.playwright.result }}" != "success" ] || [ "${{ needs['playwright-macos'].result }}" != "success" ]; then
echo "One or more tests failed."
exit 1
else
echo "All tests passed."
fi
5 changes: 5 additions & 0 deletions packages/integration-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
Loading

0 comments on commit 68b4baa

Please sign in to comment.