Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
import { waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils';

const APP_NAME = 'nestjs-with-submodules-decorator';

/**
* Resolves once the request's segment span has been streamed, which is how these specs know the
* request finished and any error it would have produced had its chance to be sent.
*/
function waitForSegmentSpan(name: string): Promise<unknown> {
return waitForStreamedSpan(APP_NAME, span => span.is_segment && span.name === name);
}

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

Expand Down Expand Up @@ -44,7 +54,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-decorator', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

Expand Down Expand Up @@ -88,7 +98,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-decorator', event => {
const errorEventPromise = waitForError(APP_NAME, event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!';
});

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

waitForError('nestjs-with-submodules-decorator', 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-decorator', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module/expected-exception';
});
const segmentSpanPromise = waitForSegmentSpan('GET /example-module/expected-exception');

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

await transactionEventPromise;
await segmentSpanPromise;

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

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

waitForError('nestjs-with-submodules-decorator', 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 @@ -172,14 +180,12 @@ 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-decorator', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module-local-filter/expected-exception';
});
const segmentSpanPromise = waitForSegmentSpan('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 segmentSpanPromise;

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

Expand All @@ -191,22 +197,20 @@ test('Does not send expected exception to Sentry if exception is thrown in modul
}) => {
let errorEventOccurred = false;

waitForError('nestjs-with-submodules-decorator', 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-decorator', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-module-registered-first/expected-exception';
});
const segmentSpanPromise = waitForSegmentSpan('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 segmentSpanPromise;

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

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

waitForError('nestjs-with-submodules-decorator', 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-decorator', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-exception-specific-filter';
});
const segmentSpanPromise = waitForSegmentSpan('GET /example-exception-specific-filter');

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

await transactionEventPromise;
await segmentSpanPromise;

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

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

waitForError('nestjs-with-submodules-decorator', 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-decorator', transactionEvent => {
return transactionEvent?.transaction === 'GET /example-exception-local-filter';
});
const segmentSpanPromise = waitForSegmentSpan('GET /example-exception-local-filter');

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

await transactionEventPromise;
await segmentSpanPromise;

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

Expand Down
Loading
Loading