Skip to content

ref(tests): Simplify integration test helpers. #4385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions packages/integration-tests/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const envelopeRequestParser = (request: Request | null): Event => {
return envelope.split('\n').map(line => JSON.parse(line))[2];
};

type SentryRequestType = 'event' | 'transaction';

/**
* Run script at the given path inside the test environment.
*
Expand All @@ -26,16 +24,6 @@ async function runScriptInSandbox(page: Page, path: string): Promise<void> {
await page.addScriptTag({ path });
}

/**
* Wait and get Sentry's request sending the event.
*
* @param {Page} page
* @returns {*} {Promise<Request>}
*/
async function waitForSentryRequest(page: Page, requestType: SentryRequestType = 'event'): Promise<Request> {
return page.waitForRequest(requestType === 'event' ? storeUrlRegex : envelopeUrlRegex);
}

/**
* Wait and get Sentry's request sending the event at the given URL, or the current page
*
Expand All @@ -44,9 +32,7 @@ async function waitForSentryRequest(page: Page, requestType: SentryRequestType =
* @return {*} {Promise<Event>}
*/
async function getSentryRequest(page: Page, url?: string): Promise<Event> {
const request = (await Promise.all([url ? page.goto(url) : Promise.resolve(null), waitForSentryRequest(page)]))[1];

return storeRequestParser(request);
return (await getMultipleSentryRequests(page, 1, url))[0];
}

/**
Expand All @@ -57,15 +43,7 @@ async function getSentryRequest(page: Page, url?: string): Promise<Event> {
* @return {*} {Promise<Event>}
*/
async function getSentryTransactionRequest(page: Page, url?: string): Promise<Event> {
const request = (
await Promise.all([url ? page.goto(url) : Promise.resolve(null), waitForSentryRequest(page, 'transaction')])
)[1];

try {
return envelopeRequestParser(request);
} catch (err) {
return Promise.reject(err);
}
return (await getMultipleSentryTransactionRequests(page, 1, url))[0];
}

/**
Expand Down Expand Up @@ -170,7 +148,6 @@ async function injectScriptAndGetEvents(page: Page, url: string, scriptPath: str

export {
runScriptInSandbox,
waitForSentryRequest,
getMultipleSentryRequests,
getMultipleSentryTransactionRequests,
getSentryRequest,
Expand Down