-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
test(e2e): Add behaviour test for Transactions in standard React E2E tests application #5912
Merged
lforst
merged 10 commits into
master
from
lforst-standard-react-application-transaction-session-tests
Oct 11, 2022
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
02b87eb
test(e2e): Add behaviour test for Errors in standard React E2E tests …
lforst 6eaff53
Remove playwright test examples
lforst 34501b1
test(e2e): Add E2E tests for transactions in React test app
lforst ffcb4b9
Merge remote-tracking branch 'origin/master' into lforst-standard-rea…
lforst 69927d1
Remove Sentry deps from yarn.lock
lforst 4f9df9f
Fix merge mistakes
lforst 2855530
Remove type assertion
lforst 12300cf
Use axios poll helper
lforst 3f837cb
Increase timeout
lforst 37723d3
Throw on non-404 responses
lforst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,6 @@ yarn-error.log* | |
/playwright/.cache/ | ||
|
||
!*.d.ts | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,94 @@ test('Sends an exception to Sentry', async ({ page }) => { | |
} | ||
} | ||
}); | ||
|
||
test('Sends a pageload transaction to Sentry', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const recordedTransactionsHandle = await page.waitForFunction(() => { | ||
if (window.recordedTransactions && window.recordedTransactions?.length >= 1) { | ||
return window.recordedTransactions; | ||
} else { | ||
return undefined; | ||
} | ||
}); | ||
const recordedTransactionEventIds = (await recordedTransactionsHandle.jsonValue()) as string[]; | ||
|
||
const timeout = setTimeout(() => { | ||
throw new Error('Timeout reached while polling events.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: let’s make this a util that (timeout + fetch):
We can also do this in a follow up PR, since we are consolidating with the errors tests. |
||
}, EVENT_POLLING_TIMEOUT); | ||
|
||
let hadPageLoadTransaction = false; | ||
|
||
await Promise.all( | ||
recordedTransactionEventIds.map(async (transactionEventId, i) => { | ||
while (true) { | ||
try { | ||
const response = await axios.get( | ||
`https://sentry.io/api/0/projects/${SENTRY_TEST_ORG_SLUG}/${SENTRY_TEST_PROJECT}/events/${transactionEventId}/`, | ||
{ headers: { Authorization: `Bearer ${authToken}` } }, | ||
); | ||
expect(response?.status).toBe(200); | ||
if (response.data.contexts.trace.op === 'pageload') { | ||
hadPageLoadTransaction = true; | ||
} | ||
break; | ||
} catch (e) { | ||
await new Promise(resolve => setTimeout(resolve, EVENT_POLLING_RETRY_INTERVAL)); | ||
} | ||
} | ||
}), | ||
); | ||
|
||
clearTimeout(timeout); | ||
|
||
expect(hadPageLoadTransaction).toBe(true); | ||
}); | ||
|
||
test.only('Sends a navigation transaction to Sentry', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
// Give pageload transaction time to finish | ||
page.waitForTimeout(4000); | ||
|
||
const linkElement = page.locator('id=navigation'); | ||
await linkElement.click(); | ||
|
||
const recordedTransactionsHandle = await page.waitForFunction(() => { | ||
if (window.recordedTransactions && window.recordedTransactions?.length >= 2) { | ||
return window.recordedTransactions; | ||
} else { | ||
return undefined; | ||
} | ||
}); | ||
const recordedTransactionEventIds = (await recordedTransactionsHandle.jsonValue()) as string[]; | ||
|
||
const timeout = setTimeout(() => { | ||
throw new Error('Timeout reached while polling events.'); | ||
}, EVENT_POLLING_TIMEOUT); | ||
|
||
let hadPageNavigationTransaction = false; | ||
|
||
await Promise.all( | ||
recordedTransactionEventIds.map(async (transactionEventId, i) => { | ||
while (true) { | ||
try { | ||
const response = await axios.get( | ||
`https://sentry.io/api/0/projects/${SENTRY_TEST_ORG_SLUG}/${SENTRY_TEST_PROJECT}/events/${transactionEventId}/`, | ||
{ headers: { Authorization: `Bearer ${authToken}` } }, | ||
); | ||
expect(response?.status).toBe(200); | ||
if (response.data.contexts.trace.op === 'pageload') { | ||
hadPageNavigationTransaction = true; | ||
} | ||
break; | ||
} catch (e) { | ||
await new Promise(resolve => setTimeout(resolve, EVENT_POLLING_RETRY_INTERVAL)); | ||
} | ||
} | ||
}), | ||
); | ||
|
||
clearTimeout(timeout); | ||
expect(hadPageNavigationTransaction).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable no-console */ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
if (!process.env.E2E_TEST_AUTH_TOKEN) { | ||
const authTokenPath = path.resolve(__dirname, 'auth-token.json'); | ||
AbhiPrasad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const authTokenHint = "Put your auth token with scope 'project:read' here!"; | ||
|
||
if (!fs.existsSync(authTokenPath)) { | ||
fs.writeFileSync(authTokenPath, JSON.stringify({ authToken: authTokenHint }, null, 2)); | ||
console.log( | ||
'No auth token configured for E2E tests! Please set the E2E_TEST_AUTH_TOKEN environment variable or put your auth token in "auth-token.json"!', | ||
); | ||
|
||
process.exit(1); | ||
} | ||
|
||
let authTokenJson; | ||
try { | ||
authTokenJson = require(authTokenPath); | ||
} catch (e) { | ||
console.log('Failed to read auth-token.json!'); | ||
process.exit(1); | ||
} | ||
|
||
const { authToken } = authTokenJson; | ||
|
||
if (!authToken || authToken === authTokenHint) { | ||
console.log('No auth token configured in auth-token.json!'); | ||
process.exit(1); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Why is the type assertion needed? Shouldn’t we handled the other case here?