Skip to content

Commit 150fa53

Browse files
committed
add integration test
1 parent 49e907e commit 150fa53

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

packages/node-integration-tests/utils/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as Sentry from '@sentry/node';
33
import { EnvelopeItemType } from '@sentry/types';
44
import { logger, parseSemver } from '@sentry/utils';
5-
import axios from 'axios';
5+
import axios, { AxiosRequestConfig } from 'axios';
66
import { Express } from 'express';
77
import * as http from 'http';
88
import nock from 'nock';
@@ -102,12 +102,16 @@ export async function runScenario(url: string): Promise<void> {
102102
await Sentry.flush();
103103
}
104104

105-
async function makeRequest(method: 'get' | 'post' = 'get', url: string): Promise<void> {
105+
async function makeRequest(
106+
method: 'get' | 'post' = 'get',
107+
url: string,
108+
axiosConfig?: AxiosRequestConfig,
109+
): Promise<void> {
106110
try {
107111
if (method === 'get') {
108-
await axios.get(url);
112+
await axios.get(url, axiosConfig);
109113
} else {
110-
await axios.post(url);
114+
await axios.post(url, axiosConfig);
111115
}
112116
} catch (e) {
113117
// We sometimes expect the request to fail, but not the test.
@@ -161,7 +165,10 @@ export class TestEnv {
161165
* @param {DataCollectorOptions} options
162166
* @returns The intercepted envelopes.
163167
*/
164-
public async getMultipleEnvelopeRequest(options: DataCollectorOptions): Promise<Record<string, unknown>[][]> {
168+
public async getMultipleEnvelopeRequest(
169+
options: DataCollectorOptions,
170+
axiosConfig?: AxiosRequestConfig,
171+
): Promise<Record<string, unknown>[][]> {
165172
const envelopeTypeArray =
166173
typeof options.envelopeType === 'string'
167174
? [options.envelopeType]
@@ -173,7 +180,7 @@ export class TestEnv {
173180
envelopeTypeArray,
174181
);
175182

176-
void makeRequest(options.method, options.url || this.url);
183+
void makeRequest(options.method, options.url || this.url, axiosConfig);
177184
return resProm;
178185
}
179186

@@ -183,8 +190,11 @@ export class TestEnv {
183190
* @param {DataCollectorOptions} options
184191
* @returns The extracted envelope.
185192
*/
186-
public async getEnvelopeRequest(options?: DataCollectorOptions): Promise<Array<Record<string, unknown>>> {
187-
return (await this.getMultipleEnvelopeRequest({ ...options, count: 1 }))[0];
193+
public async getEnvelopeRequest(
194+
options?: DataCollectorOptions,
195+
axiosConfig?: AxiosRequestConfig,
196+
): Promise<Array<Record<string, unknown>>> {
197+
return (await this.getMultipleEnvelopeRequest({ ...options, count: 1 }, axiosConfig))[0];
188198
}
189199

190200
/**

packages/remix/test/integration/test/server/loader.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,32 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
157157
expect(tags[key]).toEqual(val);
158158
});
159159
});
160+
161+
it('continues transaction from sentry-trace header and baggage', async () => {
162+
const env = await RemixTestEnv.init(adapter);
163+
const url = `${env.url}/loader-json-response/3`;
164+
165+
const envelope = await env.getEnvelopeRequest(
166+
{ url, envelopeType: 'transaction' },
167+
{
168+
headers: {
169+
'sentry-trace': '12312012123120121231201212312012-1121201211212012-1',
170+
baggage: 'sentry-version=1.0,sentry-environment=production,sentry-trace_id=12312012123120121231201212312012',
171+
},
172+
},
173+
);
174+
175+
expect(envelope[0].trace).toMatchObject({
176+
trace_id: '12312012123120121231201212312012',
177+
});
178+
179+
assertSentryTransaction(envelope[2], {
180+
contexts: {
181+
trace: {
182+
trace_id: '12312012123120121231201212312012',
183+
parent_span_id: '1121201211212012',
184+
},
185+
},
186+
});
187+
});
160188
});

0 commit comments

Comments
 (0)