Skip to content

Commit 7f1bef6

Browse files
committed
test(node): Remove axios in favor of using fetch
1 parent 2e164e1 commit 7f1bef6

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

dev-packages/node-integration-tests/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"ai": "^4.0.6",
4040
"amqplib": "^0.10.7",
4141
"apollo-server": "^3.11.1",
42-
"axios": "^1.7.7",
4342
"body-parser": "^1.20.3",
4443
"connect": "^3.7.0",
4544
"cors": "^2.8.5",

dev-packages/node-integration-tests/suites/tracing/meta-tags/test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ describe('getTraceMetaTags', () => {
1212

1313
const runner = createRunner(__dirname, 'server.js').start();
1414

15-
const response = await runner.makeRequest('get', '/test', {
15+
const response = await runner.makeRequest<{ response: string }>('get', '/test', {
1616
headers: {
1717
'sentry-trace': `${traceId}-${parentSpanId}-1`,
1818
baggage: 'sentry-environment=production,sentry-sample_rand=0.42',
1919
},
2020
});
2121

22-
// @ts-ignore - response is defined, types just don't reflect it
23-
const html = response?.response as unknown as string;
22+
const html = response?.response;
2423

2524
expect(html).toMatch(/<meta name="sentry-trace" content="cd7ee7a6fe3ebe7ab9c3271559bc203c-[a-z0-9]{16}-1"\/>/);
2625
expect(html).toContain('<meta name="baggage" content="sentry-environment=production,sentry-sample_rand=0.42"/>');
@@ -29,12 +28,11 @@ describe('getTraceMetaTags', () => {
2928
test('injects <meta> tags with new trace if no incoming headers', async () => {
3029
const runner = createRunner(__dirname, 'server.js').start();
3130

32-
const response = await runner.makeRequest('get', '/test');
31+
const response = await runner.makeRequest<{ response: string }>('get', '/test');
3332

34-
// @ts-ignore - response is defined, types just don't reflect it
35-
const html = response?.response as unknown as string;
33+
const html = response?.response;
3634

37-
const traceId = html.match(/<meta name="sentry-trace" content="([a-z0-9]{32})-[a-z0-9]{16}-1"\/>/)?.[1];
35+
const traceId = html?.match(/<meta name="sentry-trace" content="([a-z0-9]{32})-[a-z0-9]{16}-1"\/>/)?.[1];
3836
expect(traceId).not.toBeUndefined();
3937

4038
expect(html).toContain('<meta name="baggage"');
@@ -44,12 +42,11 @@ describe('getTraceMetaTags', () => {
4442
test('injects <meta> tags with negative sampling decision if tracesSampleRate is 0', async () => {
4543
const runner = createRunner(__dirname, 'server-tracesSampleRate-zero.js').start();
4644

47-
const response = await runner.makeRequest('get', '/test');
45+
const response = await runner.makeRequest<{ response: string }>('get', '/test');
4846

49-
// @ts-ignore - response is defined, types just don't reflect it
50-
const html = response?.response as unknown as string;
47+
const html = response?.response;
5148

52-
const traceId = html.match(/<meta name="sentry-trace" content="([a-z0-9]{32})-[a-z0-9]{16}-0"\/>/)?.[1];
49+
const traceId = html?.match(/<meta name="sentry-trace" content="([a-z0-9]{32})-[a-z0-9]{16}-0"\/>/)?.[1];
5350
expect(traceId).not.toBeUndefined();
5451

5552
expect(html).toContain('<meta name="baggage"');
@@ -63,15 +60,14 @@ describe('getTraceMetaTags', () => {
6360

6461
const runner = createRunner(__dirname, 'server-sdk-disabled.js').start();
6562

66-
const response = await runner.makeRequest('get', '/test', {
63+
const response = await runner.makeRequest<{ response: string }>('get', '/test', {
6764
headers: {
6865
'sentry-trace': `${traceId}-${parentSpanId}-1`,
6966
baggage: 'sentry-environment=production',
7067
},
7168
});
7269

73-
// @ts-ignore - response is defined, types just don't reflect it
74-
const html = response?.response as unknown as string;
70+
const html = response?.response;
7571

7672
expect(html).not.toContain('"sentry-trace"');
7773
expect(html).not.toContain('"baggage"');

dev-packages/node-integration-tests/utils/runner.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
TransactionEvent,
1313
} from '@sentry/core';
1414
import { normalize } from '@sentry/core';
15-
import axios from 'axios';
1615
import { execSync, spawn, spawnSync } from 'child_process';
1716
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
1817
import { join } from 'path';
@@ -532,7 +531,7 @@ export function createRunner(...paths: string[]) {
532531
makeRequest: async function <T>(
533532
method: 'get' | 'post',
534533
path: string,
535-
options: { headers?: Record<string, string>; data?: unknown; expectError?: boolean } = {},
534+
options: { headers?: Record<string, string>; data?: Record<string, unknown>; expectError?: boolean } = {},
536535
): Promise<T | undefined> {
537536
try {
538537
await waitFor(() => scenarioServerPort !== undefined, 10_000, 'Timed out waiting for server port');
@@ -548,16 +547,31 @@ export function createRunner(...paths: string[]) {
548547

549548
if (process.env.DEBUG) log('making request', method, url, headers, data);
550549

550+
if (data) {
551+
headers['Content-Type'] = 'application/json';
552+
}
553+
551554
try {
552-
const res =
553-
method === 'post' ? await axios.post(url, data, { headers }) : await axios.get(url, { headers });
555+
const res = await fetch(url, { headers, method, body: data ? JSON.stringify(data) : undefined });
556+
557+
if (!res.ok) {
558+
if (!expectError) {
559+
complete(new Error(`Expected request to "${path}" to succeed, but got a ${res.status} response`));
560+
}
561+
562+
return;
563+
}
554564

555565
if (expectError) {
556566
complete(new Error(`Expected request to "${path}" to fail, but got a ${res.status} response`));
557567
return;
558568
}
559569

560-
return res.data;
570+
if (res.headers.get('content-type')?.includes('application/json')) {
571+
return await res.json();
572+
}
573+
574+
return (await res.text()) as T;
561575
} catch (e) {
562576
if (expectError) {
563577
return;

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10168,7 +10168,7 @@ aws-ssl-profiles@^1.1.1:
1016810168
resolved "https://registry.yarnpkg.com/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz#157dd77e9f19b1d123678e93f120e6f193022641"
1016910169
integrity sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==
1017010170

10171-
axios@1.8.2, axios@^1.0.0, axios@^1.7.7:
10171+
axios@1.8.2, axios@^1.0.0:
1017210172
version "1.8.2"
1017310173
resolved "https://registry.yarnpkg.com/axios/-/axios-1.8.2.tgz#fabe06e241dfe83071d4edfbcaa7b1c3a40f7979"
1017410174
integrity sha512-ls4GYBm5aig9vWx8AWDSGLpnpDQRtWAfrjU+EuytuODrFBkqesN2RkOQCBzrA1RQNHw1SmRMSDDDSwzNAYQ6Rg==

0 commit comments

Comments
 (0)