diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index cff24b1e27a5..b254e472b2ff 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -81,7 +81,7 @@ jobs: SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} SANITY_E2E_DATASET: ${{ secrets.SANITY_E2E_DATASET }} - IS_AUTO_UPDATING: ${{ matrix.config == 'auto-updating' && 'true' || '' }} + SANITY_E2E_IS_AUTO_UPDATING: ${{ matrix.config == 'auto-updating' && 'true' || '' }} run: | if [ "${{ matrix.config }}" == "auto-update" ]; then pnpm e2e:setup && pnpm e2e:build --auto-updates @@ -98,7 +98,7 @@ jobs: SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} SANITY_E2E_DATASET: pr-${{ matrix.project }}-${{ github.event.number }} - IS_AUTO_UPDATING: ${{ matrix.config == 'auto-updating' && 'true' || '' }} + SANITY_E2E_IS_AUTO_UPDATING: ${{ matrix.config == 'auto-updating' && 'true' || '' }} run: | if [ "${{ matrix.config }}" == "auto-update" ]; then pnpm e2e:setup && pnpm e2e:build --auto-updates @@ -134,6 +134,7 @@ jobs: # Add more shards here if needed shardIndex: [1, 2] shardTotal: [2] + config: [auto-updating, normal] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -210,6 +211,7 @@ jobs: SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} SANITY_E2E_DATASET: ${{ secrets.SANITY_E2E_DATASET }} + SANITY_E2E_IS_AUTO_UPDATING: ${{ matrix.config == 'auto-updating' && 'true' || '' }} run: pnpm test:e2e --project ${{ matrix.project }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} - name: Run E2E tests on PR @@ -224,6 +226,7 @@ jobs: SANITY_E2E_SESSION_TOKEN: ${{ secrets.SANITY_E2E_SESSION_TOKEN_NEW }} SANITY_E2E_PROJECT_ID: ${{ secrets.SANITY_E2E_PROJECT_ID }} SANITY_E2E_DATASET: pr-${{ matrix.project }}-${{ github.event.number }} + SANITY_E2E_IS_AUTO_UPDATING: ${{ matrix.config == 'auto-updating' && 'true' || '' }} run: pnpm test:e2e --project ${{ matrix.project }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} - uses: actions/upload-artifact@v3 diff --git a/test/e2e/env.ts b/test/e2e/env.ts index 5e773c6b6e6d..8d704bb1f975 100644 --- a/test/e2e/env.ts +++ b/test/e2e/env.ts @@ -5,10 +5,10 @@ import {loadEnvFiles} from '../../scripts/utils/loadEnvFiles' loadEnvFiles() +const SANITY_E2E_IS_AUTO_UPDATING = process.env.SANITY_E2E_IS_AUTO_UPDATING === 'true' const SANITY_E2E_SESSION_TOKEN = process.env.SANITY_E2E_SESSION_TOKEN! const SANITY_E2E_PROJECT_ID = process.env.SANITY_E2E_PROJECT_ID! const SANITY_E2E_DATASET = process.env.SANITY_E2E_DATASET! -const IS_AUTO_UPDATING = process.env.IS_AUTO_UPDATING === 'true' if (!SANITY_E2E_SESSION_TOKEN) { console.error('Missing `SANITY_E2E_SESSION_TOKEN` environment variable.') @@ -28,4 +28,9 @@ if (!SANITY_E2E_DATASET) { process.exit(1) } -export {IS_AUTO_UPDATING, SANITY_E2E_DATASET, SANITY_E2E_PROJECT_ID, SANITY_E2E_SESSION_TOKEN} +export { + SANITY_E2E_DATASET, + SANITY_E2E_IS_AUTO_UPDATING, + SANITY_E2E_PROJECT_ID, + SANITY_E2E_SESSION_TOKEN, +} diff --git a/test/e2e/tests/error-reporting/sentryErrorReporter.test.ts b/test/e2e/tests/error-reporting/sentryErrorReporter.test.ts new file mode 100644 index 000000000000..32da6e776a41 --- /dev/null +++ b/test/e2e/tests/error-reporting/sentryErrorReporter.test.ts @@ -0,0 +1,34 @@ +import {expect} from '@playwright/test' +import {test} from '@sanity/test' + +import {SANITY_E2E_IS_AUTO_UPDATING} from '../../env' + +const SENTRY_URL = 'https://sentry.sanity.io/**' + +test('Sentry session should begin if in an updating studio', async ({page, baseURL}) => { + let apiCalled = false + + // Create a promise that resolves when the route is called + const apiCalledPromise = new Promise((resolve) => { + page.route(SENTRY_URL, (route) => { + apiCalled = true + route.continue() + resolve() + }) + }) + + await page.goto(baseURL ?? '') + + await Promise.race([ + apiCalledPromise, + new Promise((_, reject) => + setTimeout(() => reject(new Error('Sentry API was not called')), 10000), + ), + ]) + + if (SANITY_E2E_IS_AUTO_UPDATING) { + expect(apiCalled).toBe(true) + } else { + expect(apiCalled).toBe(false) + } +})