From 64d0ec11b5df442289d6c71a1a8de6955798c21c Mon Sep 17 00:00:00 2001 From: Jozef Harag Date: Tue, 4 Mar 2025 12:12:28 +0100 Subject: [PATCH] chore: run unit tests in WebKit and Firefox --- .github/actions/install-playwright/action.yml | 2 +- .github/workflows/check-links.yml | 1 + .github/workflows/ci.yml | 12 +++---- .github/workflows/tests.yml | 35 +++++++++++++++---- packages/web/src/session/cookie-session.ts | 10 +++++- tsconfig.eslint.json | 2 +- vitest.config.mts | 7 ++++ 7 files changed, 51 insertions(+), 18 deletions(-) diff --git a/.github/actions/install-playwright/action.yml b/.github/actions/install-playwright/action.yml index e5a118e6..c78f1be9 100644 --- a/.github/actions/install-playwright/action.yml +++ b/.github/actions/install-playwright/action.yml @@ -37,6 +37,6 @@ runs: npx playwright install webkit - name: Install Playwright OS dependencies - if: steps.playwright-cache.outputs.cache-hit != 'true' + if: steps.playwright-cache.outputs.cache-hit == 'true' shell: bash run: npx playwright install-deps diff --git a/.github/workflows/check-links.yml b/.github/workflows/check-links.yml index 356f09dd..fa727cb4 100644 --- a/.github/workflows/check-links.yml +++ b/.github/workflows/check-links.yml @@ -7,6 +7,7 @@ on: jobs: linkChecker: + name: Link Checker runs-on: ubuntu-latest steps: - uses: actions/checkout@v4.2.2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d29bd4b1..621a49c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,8 @@ on: permissions: read-all jobs: - unit-tests: + build: + name: Build runs-on: ubuntu-latest permissions: read-all steps: @@ -33,12 +34,7 @@ jobs: - name: Transpile code run: npm run compile - - name: Install playwright - uses: ./.github/actions/install-playwright - - - name: Unit tests - run: npm run test:unit - - playwright: + tests: + name: Tests uses: ./.github/workflows/tests.yml secrets: inherit diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 161480b1..a9cb9e3e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,16 +1,16 @@ -name: Playwright tests +name: Unit & Integration Tests on: workflow_call: jobs: - playwright: + tests-linux: + name: Unit & Integration Tests - ${{ matrix.browser }} 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/checkout@v4.2.2 @@ -37,13 +37,29 @@ jobs: path: packages/integration-tests/blob-report retention-days: 1 - playwright-macos: + - name: Run Unit Tests + if: ${{ matrix.browser != 'edge' && matrix.browser != 'chrome' }} + # Firefox tests are flaky. + #Remove once this issue is resolved: https://github.com/vitest-dev/vitest/issues/7377 + continue-on-error: ${{ matrix.browser == 'firefox' }} + run: npm run test:unit -- --browser.name=${{ matrix.browser }} + + - name: Upload test:unit report + uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 + if: ${{ !cancelled() && matrix.browser != 'edge' && matrix.browser != 'chrome' }} + with: + name: vitest-report-${{ matrix.browser }}-attempt-${{ github.run_attempt }} + path: vitest-report/ + retention-days: 14 + + tests-macos: timeout-minutes: 60 runs-on: macos-latest strategy: fail-fast: false matrix: browser: [webkit] + name: Unit & Integration Tests - ${{ matrix.browser }} steps: - name: Checkout uses: actions/checkout@v4.2.2 @@ -70,9 +86,13 @@ jobs: path: packages/integration-tests/blob-report retention-days: 1 + - name: Run Unit Tests + run: npm run test:unit -- --browser.name=${{ matrix.browser }} + merge-reports: + name: Merge playwright reports if: ${{ !cancelled() }} - needs: [playwright, playwright-macos] + needs: [tests-linux, tests-macos] runs-on: ubuntu-latest steps: @@ -104,13 +124,14 @@ jobs: retention-days: 14 check-failure: - needs: [playwright, playwright-macos, merge-reports] + name: Check if all tests passed + needs: [tests-linux, tests-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 + if [ "${{ needs['tests-linux'].result }}" != "success" ] || [ "${{ needs['tests-macos'].result }}" != "success" ]; then echo "One or more tests failed." exit 1 else diff --git a/packages/web/src/session/cookie-session.ts b/packages/web/src/session/cookie-session.ts index 4612669f..0d08ab3d 100644 --- a/packages/web/src/session/cookie-session.ts +++ b/packages/web/src/session/cookie-session.ts @@ -21,6 +21,8 @@ import { SESSION_INACTIVITY_TIMEOUT_SECONDS, SESSION_STORAGE_KEY } from './const import { isSessionDurationExceeded, isSessionInactivityTimeoutReached, isSessionState } from './utils' import { throttle } from '../utils/throttle' +const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) + export const cookieStore = { cachedValue: null, set: (value: string) => { @@ -90,7 +92,13 @@ export function renewCookieTimeout( SESSION_STORAGE_KEY + '=' + cookieValue + '; path=/;' + domain + 'max-age=' + SESSION_INACTIVITY_TIMEOUT_SECONDS if (isIframe()) { - cookie += ';SameSite=None; Secure' + // Safari does not set cookie when the SameSite attribute is set to None and Secure is set to true in an iframe + // It fails also in our unit tests since they are running in iframe and on localhost. + if (['localhost', '127.0.0.1'].includes(window.location.hostname) && isSafari) { + cookie += ';SameSite=None' + } else { + cookie += ';SameSite=None; Secure' + } } else { cookie += ';SameSite=Strict' } diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 76a63998..4ba0de68 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -8,7 +8,7 @@ "pretty": true, "resolveJsonModule": true, "target": "ES2017", - "types": ["vitest/global"], + "types": ["vitest/global", "@vitest/browser/providers/playwright"], "noEmit": true, "allowJs": true }, diff --git a/vitest.config.mts b/vitest.config.mts index 264675f7..fc4b8ec5 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -29,12 +29,19 @@ export default defineConfig({ { browser: 'chromium', }, + { + browser: 'firefox', + }, + { + browser: 'webkit', + }, ], api: { host: '127.0.0.1', port: 1234, }, }, + retry: 3, clearMocks: true, coverage: { exclude: ['**/node_modules'],