Skip to content

Commit

Permalink
Switch to Promise.all
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Apr 22, 2024
1 parent 9a1daee commit 532b1f7
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ sentryTest(

await page.goto(url);

runScriptInSandbox(page, {
content: `
const [, eventData] = await Promise.all([
runScriptInSandbox(page, {
content: `
throw {
type: 'Error',
otherKey: 'otherValue',
};
`,
});

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

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ sentryTest(

await page.goto(url);

runScriptInSandbox(page, {
content: `
try {
foo();
} catch (e) {
Sentry.captureException(e);
throw e;
}
`,
});

const events = await getMultipleSentryEnvelopeRequests<Event>(page, 1);
const [, events] = await Promise.all([
runScriptInSandbox(page, {
content: `
try {
foo();
} catch (e) {
Sentry.captureException(e);
throw e;
}
`,
}),
getMultipleSentryEnvelopeRequests<Event>(page, 1),
]);

expect(events[0].exception?.values).toHaveLength(1);
expect(events[0].exception?.values?.[0]).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ sentryTest('should catch syntax errors', async ({ getLocalTestPath, page }) => {

await page.goto(url);

runScriptInSandbox(page, {
content: `
const [, eventData] = await Promise.all([
runScriptInSandbox(page, {
content: `
foo{}; // SyntaxError
`,
});

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

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ sentryTest('should catch thrown errors', async ({ getLocalTestPath, page }) => {

await page.goto(url);

runScriptInSandbox(page, {
content: `
const [, eventData] = await Promise.all([
runScriptInSandbox(page, {
content: `
throw new Error('realError');
`,
});

const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
`,
}),
getFirstSentryEnvelopeRequest<Event>(page),
]);

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ sentryTest('should catch thrown objects', async ({ getLocalTestPath, page }) =>

await page.goto(url);

runScriptInSandbox(page, {
content: `
throw {
error: 'stuff is broken',
somekey: 'ok'
};`,
});

const eventData = await getFirstSentryEnvelopeRequest<Event>(page);
const [, eventData] = await Promise.all([
runScriptInSandbox(page, {
content: `
throw {
error: 'stuff is broken',
somekey: 'ok'
};`,
}),
getFirstSentryEnvelopeRequest<Event>(page),
]);

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ sentryTest('should catch thrown strings', async ({ getLocalTestPath, page }) =>

await page.goto(url);

runScriptInSandbox(page, {
content: `
const [, eventData] = await Promise.all([
runScriptInSandbox(page, {
content: `
throw 'stringError';
`,
});

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

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ sentryTest('should capture an error within a sync startSpan callback', async ({
const url = await getLocalTestPath({ testDir: __dirname });
await page.goto(url);

runScriptInSandbox(page, {
content: `
const [, events] = await Promise.all([
runScriptInSandbox(page, {
content: `
function run() {
Sentry.startSpan({ name: 'parent_span' }, () => {
throw new Error('Sync Error');
Expand All @@ -26,9 +27,9 @@ sentryTest('should capture an error within a sync startSpan callback', async ({
setTimeout(run);
`,
});

const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2);
}),
getMultipleSentryEnvelopeRequests<Event>(page, 2),
]);

const txn = events.find(event => event.type === 'transaction');
const err = events.find(event => !event.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ sentryTest(

await page.goto(url);

runScriptInSandbox(page, {
content: `
throw new Error('Error during pageload');
`,
});

const [e1, e2] = await getMultipleSentryEnvelopeRequests<Event>(page, 2);
const [, [e1, e2]] = await Promise.all([
runScriptInSandbox(page, {
content: `
throw new Error('Error during pageload');
`,
}),
getMultipleSentryEnvelopeRequests<Event>(page, 2),
]);

const pageloadTxnEvent = e1.type === 'transaction' ? e1 : e2;
const errorEvent = e1.type === 'transaction' ? e2 : e1;
Expand Down
12 changes: 10 additions & 2 deletions dev-packages/browser-integration-tests/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const countEnvelopes = async (
};

/**
* Run script at the given path inside the test environment.
* Run script inside the test environment.
*
* @param {Page} page
* @param {{ path?: string; content?: string }} impl
Expand All @@ -151,7 +151,15 @@ async function runScriptInSandbox(
content?: string;
},
): Promise<void> {
await page.addScriptTag({ path: impl.path, content: impl.content });
try {
await page.addScriptTag({ path: impl.path, content: impl.content });
} catch (e) {
// no-op
}
}

/**
*
}
/**
Expand Down

0 comments on commit 532b1f7

Please sign in to comment.