|
1 | 1 | import { expect, test } from '@playwright/test'; |
2 | | -import { waitForError, waitForRequest } from '@sentry-internal/test-utils'; |
| 2 | +import { waitForError, waitForRequest, waitForTransaction } from '@sentry-internal/test-utils'; |
3 | 3 | import { SDK_VERSION } from '@sentry/cloudflare'; |
| 4 | +import { waitForDebugger } from 'inspector'; |
4 | 5 | import { WebSocket } from 'ws'; |
5 | 6 |
|
6 | 7 | test('Index page', async ({ baseURL }) => { |
@@ -82,3 +83,33 @@ test('sends user-agent header with SDK name and version in envelope requests', a |
82 | 83 | 'user-agent': `sentry.javascript.cloudflare/${SDK_VERSION}`, |
83 | 84 | }); |
84 | 85 | }); |
| 86 | + |
| 87 | +test('waitUntil', async ({ baseURL }) => { |
| 88 | + const errorWaiter = waitForError('cloudflare-workers', () => true); |
| 89 | + const waitUntilSpanWaiter = waitForTransaction('cloudflare-workers', span => span.transaction === 'waitUntil'); |
| 90 | + const httpTransactionWaiter = waitForTransaction( |
| 91 | + 'cloudflare-workers', |
| 92 | + transactionEvent => transactionEvent.contexts?.trace?.op === 'http.server', |
| 93 | + ); |
| 94 | + |
| 95 | + const response = await fetch(`${baseURL}/waitUntil`); |
| 96 | + |
| 97 | + const transactionRequest = await httpTransactionWaiter; |
| 98 | + const waitUntilSpan = await waitUntilSpanWaiter; |
| 99 | + const errorEvent = await errorWaiter; |
| 100 | + |
| 101 | + expect(response.status).toBe(200); |
| 102 | + |
| 103 | + // All traceIds should be the same |
| 104 | + expect(transactionRequest.contexts?.trace?.trace_id).toBe(waitUntilSpan.contexts?.trace?.trace_id); |
| 105 | + expect(transactionRequest.contexts?.trace?.trace_id).toBe(errorEvent.contexts?.trace?.trace_id); |
| 106 | + |
| 107 | + expect(errorEvent.exception?.values?.[0]?.value).toBe('ʕノ•ᴥ•ʔノ ︵ ┻━┻'); |
| 108 | + expect(errorEvent.breadcrumbs).toStrictEqual(waitUntilSpan.breadcrumbs); |
| 109 | + |
| 110 | + expect(waitUntilSpan.contexts?.trace?.parent_span_id).toBe(transactionRequest.contexts?.trace?.span_id); |
| 111 | + |
| 112 | + console.log(JSON.stringify(transactionRequest, null, 2)); |
| 113 | + console.log(JSON.stringify(waitUntilSpan, null, 2)); |
| 114 | + console.log(JSON.stringify(errorEvent, null, 2)); |
| 115 | +}); |
0 commit comments