Skip to content

Commit

Permalink
test: add test for sentry session start in AUS
Browse files Browse the repository at this point in the history
  • Loading branch information
cngonzalez committed Jun 20, 2024
1 parent 7967653 commit 9cf808e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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,
}
34 changes: 34 additions & 0 deletions test/e2e/tests/error-reporting/sentryErrorReporter.test.ts
Original file line number Diff line number Diff line change
@@ -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<void>((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)
}
})

0 comments on commit 9cf808e

Please sign in to comment.