Skip to content

Commit 91f6776

Browse files
authored
test(e2e): Remove axios from E2E tests (#12275)
No need for it anymore, and actually it is much simpler using fetch because that does not throw when encountering a 404 error!
1 parent a1725a1 commit 91f6776

File tree

32 files changed

+294
-813
lines changed

32 files changed

+294
-813
lines changed

dev-packages/e2e-tests/test-applications/angular-17/playwright.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { devices } from '@playwright/test';
33

4-
// Fix urls not resolving to localhost on Node v17+
5-
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6-
import { setDefaultResultOrder } from 'dns';
7-
setDefaultResultOrder('ipv4first');
8-
94
const testEnv = process.env['TEST_ENV'] || 'production';
105

116
if (!testEnv) {

dev-packages/e2e-tests/test-applications/angular-18/playwright.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { devices } from '@playwright/test';
33

4-
// Fix urls not resolving to localhost on Node v17+
5-
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6-
import { setDefaultResultOrder } from 'dns';
7-
setDefaultResultOrder('ipv4first');
8-
94
const testEnv = process.env['TEST_ENV'] || 'production';
105

116
if (!testEnv) {

dev-packages/e2e-tests/test-applications/create-next-app/playwright.config.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { devices } from '@playwright/test';
33

4-
// Fix urls not resolving to localhost on Node v17+
5-
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6-
import { setDefaultResultOrder } from 'dns';
7-
setDefaultResultOrder('ipv4first');
8-
94
const testEnv = process.env.TEST_ENV;
105

116
if (!testEnv) {

dev-packages/e2e-tests/test-applications/create-next-app/tests/behaviour-client.test.ts

Lines changed: 26 additions & 57 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

43
const authToken = process.env.E2E_TEST_AUTH_TOKEN;
54
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
@@ -20,24 +19,12 @@ test('Sends a client-side exception to Sentry', async ({ page }) => {
2019
await expect
2120
.poll(
2221
async () => {
23-
try {
24-
const response = await axios.get(
25-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}/`,
26-
{ headers: { Authorization: `Bearer ${authToken}` } },
27-
);
28-
29-
return response.status;
30-
} catch (e) {
31-
if (e instanceof AxiosError && e.response) {
32-
if (e.response.status !== 404) {
33-
throw e;
34-
} else {
35-
return e.response.status;
36-
}
37-
} else {
38-
throw e;
39-
}
40-
}
22+
const response = await fetch(
23+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}/`,
24+
{ headers: { Authorization: `Bearer ${authToken}` } },
25+
);
26+
27+
return response.status;
4128
},
4229
{
4330
timeout: EVENT_POLLING_TIMEOUT,
@@ -71,28 +58,19 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
7158
await expect
7259
.poll(
7360
async () => {
74-
try {
75-
const response = await axios.get(
76-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
77-
{ headers: { Authorization: `Bearer ${authToken}` } },
78-
);
79-
80-
if (response.data.contexts.trace.op === 'pageload') {
61+
const response = await fetch(
62+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
63+
{ headers: { Authorization: `Bearer ${authToken}` } },
64+
);
65+
66+
if (response.ok) {
67+
const data = await response.json();
68+
if (data.contexts.trace.op === 'pageload') {
8169
hadPageLoadTransaction = true;
8270
}
83-
84-
return response.status;
85-
} catch (e) {
86-
if (e instanceof AxiosError && e.response) {
87-
if (e.response.status !== 404) {
88-
throw e;
89-
} else {
90-
return e.response.status;
91-
}
92-
} else {
93-
throw e;
94-
}
9571
}
72+
73+
return response.status;
9674
},
9775
{
9876
timeout: EVENT_POLLING_TIMEOUT,
@@ -136,28 +114,19 @@ test('Sends a navigation transaction to Sentry', async ({ page }) => {
136114
await expect
137115
.poll(
138116
async () => {
139-
try {
140-
const response = await axios.get(
141-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
142-
{ headers: { Authorization: `Bearer ${authToken}` } },
143-
);
144-
145-
if (response.data.contexts.trace.op === 'navigation') {
117+
const response = await fetch(
118+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
119+
{ headers: { Authorization: `Bearer ${authToken}` } },
120+
);
121+
122+
if (response.ok) {
123+
const data = await response.json();
124+
if (data.contexts.trace.op === 'navigation') {
146125
hadPageNavigationTransaction = true;
147126
}
148-
149-
return response.status;
150-
} catch (e) {
151-
if (e instanceof AxiosError && e.response) {
152-
if (e.response.status !== 404) {
153-
throw e;
154-
} else {
155-
return e.response.status;
156-
}
157-
} else {
158-
throw e;
159-
}
160127
}
128+
129+
return response.status;
161130
},
162131
{
163132
timeout: EVENT_POLLING_TIMEOUT,

dev-packages/e2e-tests/test-applications/create-next-app/tests/behaviour-server.test.ts

Lines changed: 4 additions & 31 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

43
const authToken = process.env.E2E_TEST_AUTH_TOKEN;
54
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
@@ -18,21 +17,8 @@ test('Sends a server-side exception to Sentry', async ({ baseURL }) => {
1817
await expect
1918
.poll(
2019
async () => {
21-
try {
22-
const response = await axios.get(url, { headers: { Authorization: `Bearer ${authToken}` } });
23-
24-
return response.status;
25-
} catch (e) {
26-
if (e instanceof AxiosError && e.response) {
27-
if (e.response.status !== 404) {
28-
throw e;
29-
} else {
30-
return e.response.status;
31-
}
32-
} else {
33-
throw e;
34-
}
35-
}
20+
const response = await fetch(url, { headers: { Authorization: `Bearer ${authToken}` } });
21+
return response.status;
3622
},
3723
{ timeout: EVENT_POLLING_TIMEOUT },
3824
)
@@ -53,21 +39,8 @@ test('Sends server-side transactions to Sentry', async ({ baseURL }) => {
5339
await expect
5440
.poll(
5541
async () => {
56-
try {
57-
const response = await axios.get(url, { headers: { Authorization: `Bearer ${authToken}` } });
58-
59-
return response.status;
60-
} catch (e) {
61-
if (e instanceof AxiosError && e.response) {
62-
if (e.response.status !== 404) {
63-
throw e;
64-
} else {
65-
return e.response.status;
66-
}
67-
} else {
68-
throw e;
69-
}
70-
}
42+
const response = await fetch(url, { headers: { Authorization: `Bearer ${authToken}` } });
43+
return response.status;
7144
},
7245
{ timeout: EVENT_POLLING_TIMEOUT },
7346
)

dev-packages/e2e-tests/test-applications/create-remix-app-express-vite-dev/tests/behaviour-client.test.ts

Lines changed: 25 additions & 57 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

43
const EVENT_POLLING_TIMEOUT = 90_000;
54

@@ -21,24 +20,11 @@ test('Sends a client-side exception to Sentry', async ({ page }) => {
2120
await expect
2221
.poll(
2322
async () => {
24-
try {
25-
const response = await axios.get(
26-
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}/`,
27-
{ headers: { Authorization: `Bearer ${authToken}` } },
28-
);
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-
}
23+
const response = await fetch(
24+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${exceptionEventId}/`,
25+
{ headers: { Authorization: `Bearer ${authToken}` } },
26+
);
27+
return response.status;
4228
},
4329
{
4430
timeout: EVENT_POLLING_TIMEOUT,
@@ -72,28 +58,19 @@ test('Sends a pageload transaction to Sentry', async ({ page }) => {
7258
await expect
7359
.poll(
7460
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-
);
80-
81-
if (response.data.contexts.trace.op === 'pageload') {
61+
const response = await fetch(
62+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
63+
{ headers: { Authorization: `Bearer ${authToken}` } },
64+
);
65+
66+
if (response.ok) {
67+
const data = await response.json();
68+
if (data.contexts.trace.op === 'pageload') {
8269
hadPageLoadTransaction = true;
8370
}
84-
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;
95-
}
9671
}
72+
73+
return response.status;
9774
},
9875
{
9976
timeout: EVENT_POLLING_TIMEOUT,
@@ -137,28 +114,19 @@ test('Sends a navigation transaction to Sentry', async ({ page }) => {
137114
await expect
138115
.poll(
139116
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') {
117+
const response = await fetch(
118+
`https://sentry.io/api/0/projects/${sentryTestOrgSlug}/${sentryTestProject}/events/${transactionEventId}/`,
119+
{ headers: { Authorization: `Bearer ${authToken}` } },
120+
);
121+
122+
if (response.ok) {
123+
const data = await response.json();
124+
if (data.contexts.trace.op === 'navigation') {
147125
hadPageNavigationTransaction = true;
148126
}
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-
}
161127
}
128+
129+
return response.status;
162130
},
163131
{
164132
timeout: EVENT_POLLING_TIMEOUT,

0 commit comments

Comments
 (0)