Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run unit tests in WebKit and Firefox #1001

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install-playwright/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

jobs:
linkChecker:
name: Link Checker
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ on:
permissions: read-all

jobs:
unit-tests:
build:
name: Build
runs-on: ubuntu-latest
permissions: read-all
steps:
Expand All @@ -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
43 changes: 36 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
Expand All @@ -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/[email protected]
Expand All @@ -70,9 +86,21 @@ jobs:
path: packages/integration-tests/blob-report
retention-days: 1

- name: Run Unit Tests
run: npm run test:unit -- --browser.name=${{ matrix.browser }}

- name: Upload test:unit report
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1
if: ${{ !cancelled() }}
with:
name: vitest-report-${{ matrix.browser }}-attempt-${{ github.run_attempt }}
path: vitest-report/
retention-days: 14

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

runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -104,13 +132,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
Expand Down
10 changes: 9 additions & 1 deletion packages/web/src/session/cookie-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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'
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pretty": true,
"resolveJsonModule": true,
"target": "ES2017",
"types": ["vitest/global"],
"types": ["vitest/global", "@vitest/browser/providers/playwright"],
"noEmit": true,
"allowJs": true
},
Expand Down
7 changes: 7 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
Loading