Skip to content

Commit b220ff2

Browse files
committed
Change event waiting pattern.
1 parent b1b2d04 commit b220ff2

File tree

10 files changed

+58
-60
lines changed

10 files changed

+58
-60
lines changed

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/init.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ window.Sentry = Sentry;
44

55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
7+
debug: true,
78
});

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/non-string-arg/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ sentryTest(
1111

1212
await page.goto(url);
1313

14-
const [, eventData] = await Promise.all([
15-
runScriptInSandbox(page, {
16-
content: `
14+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
15+
16+
runScriptInSandbox(page, {
17+
content: `
1718
throw {
1819
type: 'Error',
1920
otherKey: 'otherValue',
2021
};
2122
`,
22-
}),
23-
getFirstSentryEnvelopeRequest<Event>(page),
24-
]);
23+
});
24+
25+
const eventData = await errorEventPromise;
2526

2627
expect(eventData.exception?.values).toHaveLength(1);
2728
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ sentryTest(
1111

1212
await page.goto(url);
1313

14-
const [, events] = await Promise.all([
15-
runScriptInSandbox(page, {
16-
content: `
14+
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 1);
15+
16+
runScriptInSandbox(page, {
17+
content: `
1718
try {
1819
foo();
1920
} catch (e) {
2021
Sentry.captureException(e);
2122
throw e;
2223
}
2324
`,
24-
}),
25-
getMultipleSentryEnvelopeRequests<Event>(page, 1),
26-
]);
25+
});
26+
27+
const events = await errorEventsPromise;
2728

2829
expect(events[0].exception?.values).toHaveLength(1);
2930
expect(events[0].exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/syntax-errors/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ sentryTest('should catch syntax errors', async ({ getLocalTestPath, page }) => {
99

1010
await page.goto(url);
1111

12-
const [, eventData] = await Promise.all([
13-
runScriptInSandbox(page, {
14-
content: `
12+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
13+
14+
runScriptInSandbox(page, {
15+
content: `
1516
foo{}; // SyntaxError
1617
`,
17-
}),
18-
getFirstSentryEnvelopeRequest<Event>(page),
19-
]);
18+
});
19+
20+
const eventData = await errorEventPromise;
2021

2122
expect(eventData.exception?.values).toHaveLength(1);
2223
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-errors/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ sentryTest('should catch thrown errors', async ({ getLocalTestPath, page }) => {
99

1010
await page.goto(url);
1111

12-
const [, eventData] = await Promise.all([
13-
runScriptInSandbox(page, {
14-
content: `
12+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
13+
14+
runScriptInSandbox(page, {
15+
content: `
1516
throw new Error('realError');
1617
`,
17-
}),
18-
getFirstSentryEnvelopeRequest<Event>(page),
19-
]);
18+
});
19+
20+
const eventData = await errorEventPromise;
2021

2122
expect(eventData.exception?.values).toHaveLength(1);
2223
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-objects/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ sentryTest('should catch thrown objects', async ({ getLocalTestPath, page }) =>
99

1010
await page.goto(url);
1111

12-
const [, eventData] = await Promise.all([
13-
runScriptInSandbox(page, {
14-
content: `
12+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
13+
14+
await runScriptInSandbox(page, {
15+
content: `
1516
throw {
1617
error: 'stuff is broken',
1718
somekey: 'ok'
1819
};`,
19-
}),
20-
getFirstSentryEnvelopeRequest<Event>(page),
21-
]);
20+
});
21+
22+
const eventData = await errorEventPromise;
2223

2324
expect(eventData.exception?.values).toHaveLength(1);
2425
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ sentryTest('should catch thrown strings', async ({ getLocalTestPath, page }) =>
99

1010
await page.goto(url);
1111

12-
const [, eventData] = await Promise.all([
13-
runScriptInSandbox(page, {
14-
content: `
12+
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
13+
14+
runScriptInSandbox(page, {
15+
content: `
1516
throw 'stringError';
1617
`,
17-
}),
18-
getFirstSentryEnvelopeRequest<Event>(page),
19-
]);
18+
});
19+
20+
const eventData = await errorEventPromise;
2021

2122
expect(eventData.exception?.values).toHaveLength(1);
2223
expect(eventData.exception?.values?.[0]).toMatchObject({

dev-packages/browser-integration-tests/suites/public-api/startSpan/error-sync/test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ sentryTest('should capture an error within a sync startSpan callback', async ({
1414
}
1515

1616
const url = await getLocalTestPath({ testDir: __dirname });
17+
1718
await page.goto(url);
1819

19-
const [, events] = await Promise.all([
20-
runScriptInSandbox(page, {
21-
content: `
20+
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
21+
22+
runScriptInSandbox(page, {
23+
content: `
2224
function run() {
2325
Sentry.startSpan({ name: 'parent_span' }, () => {
2426
throw new Error('Sync Error');
@@ -27,9 +29,9 @@ sentryTest('should capture an error within a sync startSpan callback', async ({
2729
2830
setTimeout(run);
2931
`,
30-
}),
31-
getMultipleSentryEnvelopeRequests<Event>(page, 2),
32-
]);
32+
});
33+
34+
const events = await errorEventsPromise;
3335

3436
const txn = events.find(event => event.type === 'transaction');
3537
const err = events.find(event => !event.type);

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/error/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ sentryTest(
1818

1919
await page.goto(url);
2020

21-
const [, [e1, e2]] = await Promise.all([
22-
runScriptInSandbox(page, {
23-
content: `
21+
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
22+
23+
runScriptInSandbox(page, {
24+
content: `
2425
throw new Error('Error during pageload');
2526
`,
26-
}),
27-
getMultipleSentryEnvelopeRequests<Event>(page, 2),
28-
]);
27+
});
28+
29+
const [e1, e2] = await errorEventsPromise;
2930

3031
const pageloadTxnEvent = e1.type === 'transaction' ? e1 : e2;
3132
const errorEvent = e1.type === 'transaction' ? e2 : e1;

dev-packages/browser-integration-tests/utils/helpers.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ async function runScriptInSandbox(
158158
}
159159
}
160160

161-
/**
162-
*
163-
}
164-
165161
/**
166162
* Get Sentry events at the given URL, or the current page.
167163
*
@@ -346,12 +342,4 @@ async function getFirstSentryEnvelopeRequest<T>(
346342
return (await getMultipleSentryEnvelopeRequests<T>(page, 1, { url }, requestParser))[0];
347343
}
348344

349-
/**
350-
* Trigger an error in the page context.
351-
* This function is useful to test error handling in the page.
352-
*
353-
* @param {Page} page
354-
* @param {unknown} error
355-
*/
356-
357345
export { runScriptInSandbox, getMultipleSentryEnvelopeRequests, getFirstSentryEnvelopeRequest, getSentryEvents };

0 commit comments

Comments
 (0)