Skip to content

Commit c974252

Browse files
committed
improve test
1 parent e7d4f8a commit c974252

File tree

1 file changed

+42
-90
lines changed

1 file changed

+42
-90
lines changed

dev-packages/e2e-tests/test-applications/react-send-to-sentry/tests/behaviour-test.spec.ts renamed to dev-packages/e2e-tests/test-applications/react-send-to-sentry/tests/send-to-sentry.test.ts

Lines changed: 42 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect, test } from '@playwright/test';
2-
import axios, { AxiosError } from 'axios';
32
import { ReplayRecordingData } from './fixtures/ReplayRecordingData';
43

54
const EVENT_POLLING_TIMEOUT = 90_000;
@@ -22,23 +21,12 @@ test('Sends an exception to Sentry', async ({ page }) => {
2221
await expect
2322
.poll(
2423
async () => {
25-
try {
26-
const response = await axios.get(
27-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}XXX/`,
28-
{ headers: { Authorization: `Bearer ${authToken}` } },
29-
);
30-
return response.status;
31-
} catch (e) {
32-
if (e instanceof AxiosError && e.response) {
33-
if (e.response.status !== 404) {
34-
throw e;
35-
} else {
36-
return e.response.status;
37-
}
38-
} else {
39-
throw e;
40-
}
41-
}
24+
const response = await fetch(
25+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}/`,
26+
{ headers: { Authorization: `Bearer ${authToken}` } },
27+
);
28+
29+
return response.status;
4230
},
4331
{
4432
timeout: EVENT_POLLING_TIMEOUT,
@@ -72,28 +60,20 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
7260
await expect
7361
.poll(
7462
async () => {
75-
try {
76-
const response = await axios.get(
77-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
78-
{ headers: { Authorization: `Bearer ${authToken}` } },
79-
);
63+
const response = await fetch(
64+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
65+
{ headers: { Authorization: `Bearer ${authToken}` } },
66+
);
8067

81-
if (response.data.contexts.trace.op === 'pageload') {
82-
hadPageLoadTransaction = true;
83-
}
68+
if (response.ok) {
69+
const data = await response.json();
8470

85-
return response.status;
86-
} catch (e) {
87-
if (e instanceof AxiosError && e.response) {
88-
if (e.response.status !== 404) {
89-
throw e;
90-
} else {
91-
return e.response.status;
92-
}
93-
} else {
94-
throw e;
71+
if (data.contexts.trace.op === 'pageload') {
72+
hadPageLoadTransaction = true;
9573
}
9674
}
75+
76+
return response.status;
9777
},
9878
{
9979
timeout: EVENT_POLLING_TIMEOUT,
@@ -137,28 +117,19 @@ test('Sends a navigation transaction to Sentry', async ({ page }) => {
137117
await expect
138118
.poll(
139119
async () => {
140-
try {
141-
const response = await axios.get(
142-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
143-
{ headers: { Authorization: `Bearer ${authToken}` } },
144-
);
145-
146-
if (response.data.contexts.trace.op === 'navigation') {
120+
const response = await fetch(
121+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
122+
{ headers: { Authorization: `Bearer ${authToken}` } },
123+
);
124+
125+
if (response.ok) {
126+
const data = await response.json();
127+
if (data.contexts.trace.op === 'navigation') {
147128
hadPageNavigationTransaction = true;
148129
}
149-
150-
return response.status;
151-
} catch (e) {
152-
if (e instanceof AxiosError && e.response) {
153-
if (e.response.status !== 404) {
154-
throw e;
155-
} else {
156-
return e.response.status;
157-
}
158-
} else {
159-
throw e;
160-
}
161130
}
131+
132+
return response.status;
162133
},
163134
{
164135
timeout: EVENT_POLLING_TIMEOUT,
@@ -195,24 +166,12 @@ test('Sends a Replay recording to Sentry', async ({ browser }) => {
195166
await expect
196167
.poll(
197168
async () => {
198-
try {
199-
const response = await axios.get(
200-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/`,
201-
{ headers: { Authorization: `Bearer ${authToken}` } },
202-
);
203-
204-
return response.status;
205-
} catch (e) {
206-
if (e instanceof AxiosError && e.response) {
207-
if (e.response.status !== 404) {
208-
throw e;
209-
} else {
210-
return e.response.status;
211-
}
212-
} else {
213-
throw e;
214-
}
215-
}
169+
const response = await fetch(
170+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/`,
171+
{ headers: { Authorization: `Bearer ${authToken}` } },
172+
);
173+
174+
return response.status;
216175
},
217176
{
218177
timeout: EVENT_POLLING_TIMEOUT,
@@ -224,24 +183,17 @@ test('Sends a Replay recording to Sentry', async ({ browser }) => {
224183
await expect
225184
.poll(
226185
async () => {
227-
try {
228-
const response = await axios.get(
229-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/recording-segments/?cursor=100%3A0%3A1`,
230-
{ headers: { Authorization: `Bearer ${authToken}` } },
231-
);
232-
233-
return response.status === 200 ? response.data[0] : response.status;
234-
} catch (e) {
235-
if (e instanceof AxiosError && e.response) {
236-
if (e.response.status !== 404) {
237-
throw e;
238-
} else {
239-
return e.response.status;
240-
}
241-
} else {
242-
throw e;
243-
}
186+
const response = await fetch(
187+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/replays/${replayId}/recording-segments/?cursor=100%3A0%3A1`,
188+
{ headers: { Authorization: `Bearer ${authToken}` } },
189+
);
190+
191+
if (response.ok) {
192+
const data = await response.json();
193+
return data[0];
244194
}
195+
196+
return response.status;
245197
},
246198
{
247199
timeout: EVENT_POLLING_TIMEOUT,

0 commit comments

Comments
 (0)