Skip to content

Commit

Permalink
fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Dec 21, 2023
1 parent 8e9ff8f commit 3a3bf53
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 38 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@
</head>
<body>
<button id="button1" type="button">Button 1</button>

<script>
async function run() {
await Sentry.startSpan({ name: 'parent_span', op: 'test' }, async () => {
Promise.reject('Async Promise Rejection');
});
}

const button = document.getElementById('button1');
button.addEventListener('click', async () => {
await run();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ sentryTest(
const url = await getLocalTestPath({ testDir: __dirname });
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);

const gotoPromise = page.goto(url);
const clickPromise = page.getByText('Button 1').click();
await page.goto(url);

const [_, events] = await Promise.all([gotoPromise, envelopePromise, clickPromise]);
const clickPromise = page.getByText('Button 1').click();

const [, events] = await Promise.all([clickPromise, envelopePromise]);
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]];

expect(txn).toMatchObject({ transaction: 'parent_span' });

expect(err?.exception?.values?.[0]?.value).toBe('[object Promise]');
expect(err?.exception?.values?.[0]?.value).toBe(
'Non-Error promise rejection captured with value: Async Promise Rejection',
);
},
);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@
</head>
<body>
<button id="button1" type="button">Button 1</button>

<script>
async function run() {
await Sentry.startSpan({ name: 'parent_span', op: 'test' }, async () => {
throw new Error('Async Thrown Error');
});
}

const button = document.getElementById('button1');
button.addEventListener('click', async () => {
await run();
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@ sentryTest('should capture a thrown error within an async startSpan callback', a
if (shouldSkipTracingTest()) {
sentryTest.skip();
}

page.on('pageerror', err => console.log('pageerror', err));
page.on('console', msg => console.log('console', msg.text()));
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);

const url = await getLocalTestPath({ testDir: __dirname });
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
await page.goto(url);

const gotoPromise = page.goto(url);
const clickPromise = page.getByText('Button 1').click();

console.log('before wait');

const [_, events] = await Promise.all([gotoPromise, envelopePromise, clickPromise]);

console.log('after wait');

// awaiting both events simultaneously to avoid race conditions
const [, events] = await Promise.all([clickPromise, envelopePromise]);
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]];

expect(txn).toMatchObject({ transaction: 'parent_span' });

expect(err?.exception?.values?.[0]?.value).toBe('[object Promise]');
expect(err?.exception?.values?.[0]?.value).toBe('Async Thrown Error');
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import * as _ from '@sentry/tracing';
window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
// dsn: 'https://public@dsn.ingest.sentry.io/1337',
dsn: 'https://a5e7debbbe074daa916887a3adcd0df5@o447951.ingest.sentry.io/4503942526795776',
tracesSampleRate: 1.0,
normalizeDepth: 10,
debug: true,
beforeSend(event) {
console.log('beforeSend', event);
return event;
},
});

0 comments on commit 3a3bf53

Please sign in to comment.