Skip to content

Commit

Permalink
test(browser): Add sample integration test for breadcrumb log level
Browse files Browse the repository at this point in the history
Signed-off-by: Kaung Zin Hein <kaungzinhein113@gmail.com>
  • Loading branch information
Zen-cronic committed Sep 18, 2024
1 parent 7cea142 commit a71e07e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
status_code: 200,
url: 'http://sentry-test.io/foo',
},
level: 'info',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ sentryTest('captures Breadcrumb for basic GET request that uses request object',
status_code: 200,
url: 'http://sentry-test.io/foo',
},
level: 'info',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
status_code: 200,
url: 'http://sentry-test.io/foo',
},
level: 'info',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,64 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
status_code: 200,
url: 'http://sentry-test.io/foo',
},
level: 'info',
});
});

sentryTest('captures Breadcrumb for GET request with 4xx response code', async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

await page.route('**/foo', async route => {
await route.fulfill({
status: 404,
contentType: 'text/plain',
body: 'Not Found!',
});
});

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData.exception?.values).toHaveLength(1);

expect(eventData?.breadcrumbs?.length).toBe(1);
expect(eventData!.breadcrumbs![0]).toEqual({
timestamp: expect.any(Number),
category: 'xhr',
type: 'http',
data: {
method: 'GET',
status_code: 404,
url: 'http://sentry-test.io/foo',
},
level: 'warning',
});
});

sentryTest('captures Breadcrumb for GET request with 5xx response code', async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

await page.route('**/foo', async route => {
await route.fulfill({
status: 500,
contentType: 'text/plain',
body: 'Internal Server Error',
});
});

const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);

expect(eventData.exception?.values).toHaveLength(1);

expect(eventData?.breadcrumbs?.length).toBe(1);
expect(eventData!.breadcrumbs![0]).toEqual({
timestamp: expect.any(Number),
category: 'xhr',
type: 'http',
data: {
method: 'GET',
status_code: 500,
url: 'http://sentry-test.io/foo',
},
level: 'error',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
status_code: 200,
url: 'http://sentry-test.io/foo',
},
level: 'info',
});
});

0 comments on commit a71e07e

Please sign in to comment.