Skip to content
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Sentry from '@sentry/nestjs';

Sentry.init({
traceLifecycle: 'static',
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
import { collectStreamedSpansUntilSegment, waitForError } from '@sentry-internal/test-utils';

const APP_NAME = 'nestjs-with-submodules';

test('Sends unexpected exception to Sentry if thrown in module with global filter', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs-with-submodules', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

Expand Down Expand Up @@ -36,7 +38,7 @@ test('Sends unexpected exception to Sentry if thrown in module with global filte
});

test('Sends unexpected exception to Sentry if thrown in module with local filter', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs-with-submodules', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

Expand Down Expand Up @@ -72,7 +74,7 @@ test('Sends unexpected exception to Sentry if thrown in module with local filter
test('Sends unexpected exception to Sentry if thrown in module that was registered before Sentry', async ({
baseURL,
}) => {
const errorEventPromise = waitForError('nestjs-with-submodules', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

Expand Down Expand Up @@ -110,24 +112,24 @@ test('Does not send exception to Sentry if user-defined global exception filter
}) => {
let errorEventOccurred = false;

waitForError('nestjs-with-submodules', event => {
waitForError(APP_NAME, event => {
if (!event.type && event.exception?.values?.[0]?.value === 'Something went wrong in the example module!') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /example-module/expected-exception';
});

const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module/expected-exception';
});
// Waiting for each request's segment span is how this spec knows the request finished and
// any error it would have produced had its chance to be sent.
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-module/expected-exception');

const response = await fetch(`${baseURL}/example-module/expected-exception`);
expect(response.status).toBe(400);

await transactionEventPromise;
await spansPromise;

(await fetch(`${baseURL}/flush`)).text();
await fetch(`${baseURL}/flush`);

expect(errorEventOccurred).toBe(false);
});
Expand All @@ -137,7 +139,7 @@ test('Does not send exception to Sentry if user-defined local exception filter a
}) => {
let errorEventOccurred = false;

waitForError('nestjs-with-submodules', event => {
waitForError(APP_NAME, event => {
if (
!event.type &&
event.exception?.values?.[0]?.value === 'Something went wrong in the example module with local filter!'
Expand All @@ -148,16 +150,17 @@ test('Does not send exception to Sentry if user-defined local exception filter a
return event?.transaction === 'GET /example-module-local-filter/expected-exception';
});

const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module-local-filter/expected-exception';
});
const spansPromise = collectStreamedSpansUntilSegment(
APP_NAME,
'GET /example-module-local-filter/expected-exception',
);

const response = await fetch(`${baseURL}/example-module-local-filter/expected-exception`);
expect(response.status).toBe(400);

await transactionEventPromise;
await spansPromise;

(await fetch(`${baseURL}/flush`)).text();
await fetch(`${baseURL}/flush`);

expect(errorEventOccurred).toBe(false);
});
Expand All @@ -167,24 +170,25 @@ test('Does not send expected exception to Sentry if exception is thrown in modul
}) => {
let errorEventOccurred = false;

waitForError('nestjs-with-submodules', event => {
waitForError(APP_NAME, event => {
if (!event.type && event.exception?.values?.[0].value === 'Something went wrong in the example module!') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /example-module-registered-first/expected-exception';
});

const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module-registered-first/expected-exception';
});
const spansPromise = collectStreamedSpansUntilSegment(
APP_NAME,
'GET /example-module-registered-first/expected-exception',
);

const response = await fetch(`${baseURL}/example-module-registered-first/expected-exception`);
expect(response.status).toBe(400);

await transactionEventPromise;
await spansPromise;

(await fetch(`${baseURL}/flush`)).text();
await fetch(`${baseURL}/flush`);

expect(errorEventOccurred).toBe(false);
});
Expand All @@ -194,17 +198,15 @@ test('Global specific exception filter registered in main module is applied and
}) => {
let errorEventOccurred = false;

waitForError('nestjs-with-submodules', event => {
waitForError(APP_NAME, event => {
if (!event.type && event.exception?.values?.[0]?.value === 'Example exception was handled by specific filter!') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /example-exception-specific-filter';
});

const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-exception-specific-filter';
});
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-exception-specific-filter');

const response = await fetch(`${baseURL}/example-exception-specific-filter`);
const responseBody = await response.json();
Expand All @@ -217,9 +219,9 @@ test('Global specific exception filter registered in main module is applied and
message: 'Example exception was handled by specific filter!',
});

await transactionEventPromise;
await spansPromise;

(await fetch(`${baseURL}/flush`)).text();
await fetch(`${baseURL}/flush`);

expect(errorEventOccurred).toBe(false);
});
Expand All @@ -229,17 +231,15 @@ test('Local specific exception filter registered in main module is applied and e
}) => {
let errorEventOccurred = false;

waitForError('nestjs-with-submodules', event => {
waitForError(APP_NAME, event => {
if (!event.type && event.exception?.values?.[0]?.value === 'Example exception was handled by local filter!') {
errorEventOccurred = true;
}

return event?.transaction === 'GET /example-exception-local-filter';
});

const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-exception-local-filter';
});
const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-exception-local-filter');

const response = await fetch(`${baseURL}/example-exception-local-filter`);
const responseBody = await response.json();
Expand All @@ -252,9 +252,9 @@ test('Local specific exception filter registered in main module is applied and e
message: 'Example exception was handled by local filter!',
});

await transactionEventPromise;
await spansPromise;

(await fetch(`${baseURL}/flush`)).text();
await fetch(`${baseURL}/flush`);

expect(errorEventOccurred).toBe(false);
});
Loading
Loading