Skip to content

Commit

Permalink
test(node): Fix test runner (#14019)
Browse files Browse the repository at this point in the history
The changes in #13280 did not pass the error through the `done` callback
which means test failures are not detected when using
`createTestServer`.

Some tests had to be fixed because this change showed that they were in
fact failing!
  • Loading branch information
timfish authored Oct 23, 2024
1 parent 8a68fa9 commit c56d84d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Sentry.init({
tracePropagationTargets: [/\/v0/, 'v1'],
integrations: [],
transport: loggingTransport,
tracesSampleRate: 0.0,
// Ensure this gets a correct hint
beforeBreadcrumb(breadcrumb, hint) {
breadcrumb.data = breadcrumb.data || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ Sentry.init({
tracePropagationTargets: [/\/v0/, 'v1'],
integrations: [],
transport: loggingTransport,
// Ensure this gets a correct hint
beforeBreadcrumb(breadcrumb, hint) {
breadcrumb.data = breadcrumb.data || {};
const req = hint?.request as { path?: string };
breadcrumb.data.ADDED_PATH = req?.path;
return breadcrumb;
},
});

import * as http from 'http';

async function run(): Promise<void> {
Sentry.addBreadcrumb({ message: 'manual breadcrumb' });

await makeHttpRequest(`${process.env.SERVER_URL}/api/v0`);
await makeHttpGet(`${process.env.SERVER_URL}/api/v1`);
await makeHttpRequest(`${process.env.SERVER_URL}/api/v2`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('outgoing http requests are correctly instrumented with tracing disabled',
data: {
'http.method': 'GET',
url: `${SERVER_URL}/api/v0`,
status_code: 404,
status_code: 200,
ADDED_PATH: '/api/v0',
},
timestamp: expect.any(Number),
Expand All @@ -59,7 +59,7 @@ test('outgoing http requests are correctly instrumented with tracing disabled',
data: {
'http.method': 'GET',
url: `${SERVER_URL}/api/v1`,
status_code: 404,
status_code: 200,
ADDED_PATH: '/api/v1',
},
timestamp: expect.any(Number),
Expand All @@ -70,7 +70,7 @@ test('outgoing http requests are correctly instrumented with tracing disabled',
data: {
'http.method': 'GET',
url: `${SERVER_URL}/api/v2`,
status_code: 404,
status_code: 200,
ADDED_PATH: '/api/v2',
},
timestamp: expect.any(Number),
Expand All @@ -81,7 +81,7 @@ test('outgoing http requests are correctly instrumented with tracing disabled',
data: {
'http.method': 'GET',
url: `${SERVER_URL}/api/v3`,
status_code: 404,
status_code: 200,
ADDED_PATH: '/api/v3',
},
timestamp: expect.any(Number),
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/node-integration-tests/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export function createTestServer(done: (error?: unknown) => void) {
const address = server.address() as AddressInfo;
resolve([
`http://localhost:${address.port}`,
() => {
(error?: unknown) => {
server.close();
done();
done(error);
},
]);
});
Expand Down

0 comments on commit c56d84d

Please sign in to comment.