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
Expand Up @@ -2,13 +2,19 @@ import { expect, test } from '@playwright/test';
import { waitForError, waitForStreamedSpan } from '@sentry-internal/test-utils';

test('Sends exceptions to Sentry on error in @Cron decorated method', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs-basic', event => {
return (
!event.type &&
event.exception?.values?.[0]?.value === 'Test error from schedule cron' &&
event.exception?.values?.[0]?.mechanism?.type === 'auto.function.nestjs.cron'
);
});
// The job throws the same error on every tick, so the Dedupe integration drops all but the first
// one unless another error is sent in between. That first error may predate this test.
const errorEventPromise = waitForError(
'nestjs-basic',
event => {
return (
!event.type &&
event.exception?.values?.[0]?.value === 'Test error from schedule cron' &&
event.exception?.values?.[0]?.mechanism?.type === 'auto.function.nestjs.cron'
);
},
0,
);

const errorEvent = await errorEventPromise;

Expand All @@ -23,13 +29,18 @@ test('Sends exceptions to Sentry on error in @Cron decorated method', async ({ b
});

test('Sends exceptions to Sentry on error in @Interval decorated method', async ({ baseURL }) => {
const errorEventPromise = waitForError('nestjs-basic', event => {
return (
!event.type &&
event.exception?.values?.[0]?.value === 'Test error from schedule interval' &&
event.exception?.values?.[0]?.mechanism?.type === 'auto.function.nestjs.interval'
);
});
// See the @Cron test above for why this looks back to app startup.
const errorEventPromise = waitForError(
'nestjs-basic',
event => {
return (
!event.type &&
event.exception?.values?.[0]?.value === 'Test error from schedule interval' &&
event.exception?.values?.[0]?.mechanism?.type === 'auto.function.nestjs.interval'
);
},
0,
);

const errorEvent = await errorEventPromise;

Expand Down
9 changes: 7 additions & 2 deletions dev-packages/test-utils/src/event-proxy-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,17 @@ export function waitForEnvelopeItem(
});
}

/** Wait for an error to be sent. */
/**
* Wait for an error to be sent.
*
* Pass `timestamp` to look further back than the moment of the call, e.g. `0` for an error the app
* emits on its own, before any test can start listening.
*/
export function waitForError(
proxyServerName: string,
callback: (errorEvent: Event) => Promise<boolean> | boolean,
timestamp: number = getNanosecondTimestamp(),
): Promise<Event> {
const timestamp = getNanosecondTimestamp();
return new Promise((resolve, reject) => {
waitForEnvelopeItem(
proxyServerName,
Expand Down
Loading