Skip to content

Commit

Permalink
test(e2e): Remove axios from E2E tests (#12275)
Browse files Browse the repository at this point in the history
No need for it anymore, and actually it is much simpler using fetch
because that does not throw when encountering a 404 error!
  • Loading branch information
mydea committed May 29, 2024
1 parent a1725a1 commit 91f6776
Show file tree
Hide file tree
Showing 32 changed files with 294 additions and 813 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

// Fix urls not resolving to localhost on Node v17+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
import { setDefaultResultOrder } from 'dns';
setDefaultResultOrder('ipv4first');

const testEnv = process.env['TEST_ENV'] || 'production';

if (!testEnv) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

// Fix urls not resolving to localhost on Node v17+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
import { setDefaultResultOrder } from 'dns';
setDefaultResultOrder('ipv4first');

const testEnv = process.env['TEST_ENV'] || 'production';

if (!testEnv) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

// Fix urls not resolving to localhost on Node v17+
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
import { setDefaultResultOrder } from 'dns';
setDefaultResultOrder('ipv4first');

const testEnv = process.env.TEST_ENV;

if (!testEnv) {
Expand Down
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';

const authToken = process.env.E2E_TEST_AUTH_TOKEN;
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
Expand All @@ -20,24 +19,12 @@ test('Sends a client-side 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}/`,
{ 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 @@ -71,28 +58,19 @@ 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}` } },
);

if (response.data.contexts.trace.op === 'pageload') {
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 === 'pageload') {
hadPageLoadTransaction = 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 @@ -136,28 +114,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
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';

const authToken = process.env.E2E_TEST_AUTH_TOKEN;
const sentryTestOrgSlug = process.env.E2E_TEST_SENTRY_ORG_SLUG;
Expand All @@ -18,21 +17,8 @@ test('Sends a server-side exception to Sentry', async ({ baseURL }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(url, { 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(url, { headers: { Authorization: `Bearer ${authToken}` } });
return response.status;
},
{ timeout: EVENT_POLLING_TIMEOUT },
)
Expand All @@ -53,21 +39,8 @@ test('Sends server-side transactions to Sentry', async ({ baseURL }) => {
await expect
.poll(
async () => {
try {
const response = await axios.get(url, { 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(url, { headers: { Authorization: `Bearer ${authToken}` } });
return response.status;
},
{ timeout: EVENT_POLLING_TIMEOUT },
)
Expand Down
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';

const EVENT_POLLING_TIMEOUT = 90_000;

Expand All @@ -21,24 +20,11 @@ test('Sends a client-side 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}/`,
{ 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 +58,19 @@ 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}` } },
);

if (response.data.contexts.trace.op === 'pageload') {
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 === 'pageload') {
hadPageLoadTransaction = 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 @@ -137,28 +114,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
Loading

0 comments on commit 91f6776

Please sign in to comment.