|
1 | 1 | import { expect, test } from '@playwright/test';
|
2 |
| -import { waitForEnvelopeItem } from '@sentry-internal/test-utils'; |
| 2 | +import { waitForEnvelopeItem, waitForError } from '@sentry-internal/test-utils'; |
3 | 3 |
|
4 | 4 | test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
|
5 | 5 | const inProgressEnvelopePromise = waitForEnvelopeItem('nestjs-basic', envelope => {
|
6 |
| - return envelope[0].type === 'check_in' && envelope[1]['status'] === 'in_progress'; |
| 6 | + return ( |
| 7 | + envelope[0].type === 'check_in' && |
| 8 | + envelope[1]['monitor_slug'] === 'test-cron-slug' && |
| 9 | + envelope[1]['status'] === 'in_progress' |
| 10 | + ); |
7 | 11 | });
|
8 | 12 |
|
9 | 13 | const okEnvelopePromise = waitForEnvelopeItem('nestjs-basic', envelope => {
|
10 |
| - return envelope[0].type === 'check_in' && envelope[1]['status'] === 'ok'; |
| 14 | + return ( |
| 15 | + envelope[0].type === 'check_in' && |
| 16 | + envelope[1]['monitor_slug'] === 'test-cron-slug' && |
| 17 | + envelope[1]['status'] === 'ok' |
| 18 | + ); |
11 | 19 | });
|
12 | 20 |
|
13 | 21 | const inProgressEnvelope = await inProgressEnvelopePromise;
|
@@ -51,5 +59,23 @@ test('Cron job triggers send of in_progress envelope', async ({ baseURL }) => {
|
51 | 59 | );
|
52 | 60 |
|
53 | 61 | // kill cron so tests don't get stuck
|
54 |
| - await fetch(`${baseURL}/kill-test-cron`); |
| 62 | + await fetch(`${baseURL}/kill-test-cron/test-cron-job`); |
| 63 | +}); |
| 64 | + |
| 65 | +test('Sends exceptions to Sentry on error in cron job', async ({ baseURL }) => { |
| 66 | + const errorEventPromise = waitForError('nestjs-basic', event => { |
| 67 | + return !event.type && event.exception?.values?.[0]?.value === 'Test error from cron job'; |
| 68 | + }); |
| 69 | + |
| 70 | + const errorEvent = await errorEventPromise; |
| 71 | + |
| 72 | + expect(errorEvent.exception?.values).toHaveLength(1); |
| 73 | + expect(errorEvent.exception?.values?.[0]?.value).toBe('Test error from cron job'); |
| 74 | + expect(errorEvent.contexts?.trace).toEqual({ |
| 75 | + trace_id: expect.any(String), |
| 76 | + span_id: expect.any(String), |
| 77 | + }); |
| 78 | + |
| 79 | + // kill cron so tests don't get stuck |
| 80 | + await fetch(`${baseURL}/kill-test-cron/test-cron-error`); |
55 | 81 | });
|
0 commit comments