Skip to content

Commit

Permalink
further integration test and doc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Jul 31, 2023
1 parent 1182786 commit 55531d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
import { envelopeRequestParser, getFirstSentryEnvelopeRequest, waitForErrorRequestOnUrl } from '../../../utils/helpers';

sentryTest(
'should add source context lines around stack frames from errors in Html inline JS',
async ({ getLocalTestPath, page }) => {
async ({ getLocalTestPath, page, browserName }) => {
if (browserName === 'webkit') {
// The error we're throwing in this test is thrown as "Script error." in Webkit.
// We filter "Script error." out by default in `InboundFilters`.
// I don't think there's much value to disable InboundFilters defaults for this test,
// given that most of our users won't do that either.
// Let's skip it instead for Webkit.
sentryTest.skip();
}

const url = await getLocalTestPath({ testDir: __dirname });

const eventPromise = getFirstSentryEnvelopeRequest<Event>(page, url);
const eventReqPromise = waitForErrorRequestOnUrl(page, url);

const clickPromise = page.click('#inline-error-btn');

const [eventData] = await Promise.all([eventPromise, clickPromise]);
const [req] = await Promise.all([eventReqPromise, clickPromise]);

const eventData = envelopeRequestParser(req);

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

Expand Down Expand Up @@ -41,11 +52,14 @@ sentryTest(
sentryTest('should not add source context lines to errors from script files', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventPromise = getFirstSentryEnvelopeRequest<Event>(page, url);
const eventReqPromise = waitForErrorRequestOnUrl(page, url);

const clickPromise = page.click('#script-error-btn');

const [req] = await Promise.all([eventReqPromise, clickPromise]);

await page.click('#script-error-btn');
const eventData = envelopeRequestParser(req);

const eventData = await eventPromise;
const exception = eventData.exception?.values?.[0];
const frames = exception?.stacktrace?.frames;
expect(frames).toHaveLength(1);
Expand Down
13 changes: 8 additions & 5 deletions packages/browser/src/integrations/contextlines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ interface ContextLinesOptions {
}

/**
* Collects source context lines around the line of a stackframe
* This integration only works for stack frames pointing to JS that's directly embedded
* in HTML files.
* It DOES NOT work for stack frames pointing to JS files that are loaded by the browser.
* For frames pointing to files, context lines are added during ingestino and symbolication
* Collects source context lines around the line of a stackframe pointing to JS embedded in
* the current page's HTML.
*
* Use this integration if you have inline JS code in HTML pages that can't be accessed
* by our backend (e.g. due to a login-protected page).
*
* This integratino DOES NOT work for stack frames pointing to JS files that are loaded by the browser.
* For frames pointing to files, context lines are added during ingestion and symbolication
* by attempting to download the JS files to the Sentry backend.
*/
export class ContextLines implements Integration {
Expand Down

0 comments on commit 55531d7

Please sign in to comment.