Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed May 28, 2024
1 parent e7d4f8a commit c974252
Showing 1 changed file with 42 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect, test } from '@playwright/test';
import axios, { AxiosError } from 'axios';
import { ReplayRecordingData } from './fixtures/ReplayRecordingData';

const EVENT_POLLING_TIMEOUT = 90_000;
Expand All @@ -22,23 +21,12 @@ test('Sends an exception to Sentry', async ({ page }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}XXX/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);
return response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
}
}
const response = await fetch(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

return response.status;
},
{
timeout: EVENT_POLLING_TIMEOUT,
Expand Down Expand Up @@ -72,28 +60,20 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);
const response = await fetch(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

if (response.data.contexts.trace.op === 'pageload') {
hadPageLoadTransaction = true;
}
if (response.ok) {
const data = await response.json();

return response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
if (data.contexts.trace.op === 'pageload') {
hadPageLoadTransaction = true;
}
}

return response.status;
},
{
timeout: EVENT_POLLING_TIMEOUT,
Expand Down Expand Up @@ -137,28 +117,19 @@ test('Sends a navigation transaction to Sentry', async ({ page }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

if (response.data.contexts.trace.op === 'navigation') {
const response = await fetch(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

if (response.ok) {
const data = await response.json();
if (data.contexts.trace.op === 'navigation') {
hadPageNavigationTransaction = true;
}

return response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
}
}

return response.status;
},
{
timeout: EVENT_POLLING_TIMEOUT,
Expand Down Expand Up @@ -195,24 +166,12 @@ test('Sends a Replay recording to Sentry', async ({ browser }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

return response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
}
}
const response = await fetch(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

return response.status;
},
{
timeout: EVENT_POLLING_TIMEOUT,
Expand All @@ -224,24 +183,17 @@ test('Sends a Replay recording to Sentry', async ({ browser }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/recording-segments/?cursor=100%3A0%3A1`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

return response.status === 200 ? response.data[0] : response.status;
} catch (e) {
if (e instanceof AxiosError && e.response) {
if (e.response.status !== 404) {
throw e;
} else {
return e.response.status;
}
} else {
throw e;
}
const response = await fetch(
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/recording-segments/?cursor=100%3A0%3A1`,
{ headers: { Authorization: `Bearer ${authToken}` } },
);

if (response.ok) {
const data = await response.json();
return data[0];
}

return response.status;
},
{
timeout: EVENT_POLLING_TIMEOUT,
Expand Down

0 comments on commit c974252

Please sign in to comment.