Skip to content

Commit 053e707

Browse files
committed
Align e2e tests
1 parent 11d2c5d commit 053e707

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

dev-packages/e2e-tests/test-applications/node-fastify-3/src/app.ts

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ app.get('/test-outgoing-http-external-disallowed', async function (req, res) {
109109
res.send(data);
110110
});
111111

112+
app.post('/test-post', function (req, res) {
113+
res.send({ status: 'ok', body: req.body });
114+
});
115+
112116
app.listen({ port: port });
113117

114118
// A second app so we can test header propagation between external URLs

dev-packages/e2e-tests/test-applications/node-fastify-4/tests/transactions.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,40 @@ test('Sends an API route transaction', async ({ baseURL }) => {
106106
origin: 'manual',
107107
});
108108
});
109+
110+
test('Captures request metadata', async ({ baseURL }) => {
111+
const transactionEventPromise = waitForTransaction('node-fastify-4', transactionEvent => {
112+
return (
113+
transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'POST /test-post'
114+
);
115+
});
116+
117+
const res = await fetch(`${baseURL}/test-post`, {
118+
method: 'POST',
119+
body: JSON.stringify({ foo: 'bar', other: 1 }),
120+
headers: {
121+
'Content-Type': 'application/json',
122+
},
123+
});
124+
const resBody = await res.json();
125+
126+
expect(resBody).toEqual({ status: 'ok', body: { foo: 'bar', other: 1 } });
127+
128+
const transactionEvent = await transactionEventPromise;
129+
130+
expect(transactionEvent.request).toEqual({
131+
cookies: {},
132+
url: expect.stringMatching(/^http:\/\/localhost:(\d+)\/test-post$/),
133+
method: 'POST',
134+
headers: expect.objectContaining({
135+
'user-agent': expect.stringContaining(''),
136+
'content-type': 'application/json',
137+
}),
138+
data: JSON.stringify({
139+
foo: 'bar',
140+
other: 1,
141+
}),
142+
});
143+
144+
expect(transactionEvent.user).toEqual(undefined);
145+
});

dev-packages/e2e-tests/test-applications/node-fastify-5/src/app.ts

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ app.get('/test-outgoing-http-external-disallowed', async function (req, res) {
109109
res.send(data);
110110
});
111111

112+
app.post('/test-post', function (req, res) {
113+
res.send({ status: 'ok', body: req.body });
114+
});
115+
112116
app.listen({ port: port });
113117

114118
// A second app so we can test header propagation between external URLs

dev-packages/e2e-tests/test-applications/node-fastify-5/tests/transactions.test.ts

+37
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,40 @@ test('Sends an API route transaction', async ({ baseURL }) => {
106106
origin: 'manual',
107107
});
108108
});
109+
110+
test('Captures request metadata', async ({ baseURL }) => {
111+
const transactionEventPromise = waitForTransaction('node-fastify-5', transactionEvent => {
112+
return (
113+
transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'POST /test-post'
114+
);
115+
});
116+
117+
const res = await fetch(`${baseURL}/test-post`, {
118+
method: 'POST',
119+
body: JSON.stringify({ foo: 'bar', other: 1 }),
120+
headers: {
121+
'Content-Type': 'application/json',
122+
},
123+
});
124+
const resBody = await res.json();
125+
126+
expect(resBody).toEqual({ status: 'ok', body: { foo: 'bar', other: 1 } });
127+
128+
const transactionEvent = await transactionEventPromise;
129+
130+
expect(transactionEvent.request).toEqual({
131+
cookies: {},
132+
url: expect.stringMatching(/^http:\/\/localhost:(\d+)\/test-post$/),
133+
method: 'POST',
134+
headers: expect.objectContaining({
135+
'user-agent': expect.stringContaining(''),
136+
'content-type': 'application/json',
137+
}),
138+
data: JSON.stringify({
139+
foo: 'bar',
140+
other: 1,
141+
}),
142+
});
143+
144+
expect(transactionEvent.user).toEqual(undefined);
145+
});

0 commit comments

Comments
 (0)