-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(browser): Add integration tests for sessions. #4500
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,8 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '0.1', | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/integration-tests/suites/sessions/start-session/template.hbs
This file contains hidden or 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,11 @@ | ||
<html> | ||
<head> | ||
<meta charset='utf-8' /> | ||
<title></title> | ||
<script src='{{htmlWebpackPlugin.options.initialization}}'></script> | ||
</head> | ||
<body> | ||
<a id='navigate' href="foo">Navigate</button> | ||
<script src='{{htmlWebpackPlugin.options.subject}}'></script> | ||
</body> | ||
</html> |
37 changes: 37 additions & 0 deletions
37
packages/integration-tests/suites/sessions/start-session/test.ts
This file contains hidden or 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,37 @@ | ||
import { expect, Route } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getCurrentSession } from '../../../utils/helpers'; | ||
|
||
sentryTest('should start a new session on pageload.', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const session = await getCurrentSession(page, url); | ||
|
||
expect(session).toBeDefined(); | ||
expect(session.init).toBe(true); | ||
expect(session.errors).toBe(0); | ||
expect(session.status).toBe('ok'); | ||
}); | ||
|
||
sentryTest('should start a new session with navigation.', async ({ getLocalTestPath, page, browserName }) => { | ||
// Navigations get CORS error on Firefox and WebKit as we're using `file://` protocol. | ||
if (browserName !== 'chromium') { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.route('**/foo', (route: Route) => route.fulfill({ path: `${__dirname}/dist/index.html` })); | ||
|
||
const initSession = await getCurrentSession(page, url); | ||
|
||
await page.click('#navigate'); | ||
|
||
const newSession = await getCurrentSession(page); | ||
|
||
expect(newSession).toBeDefined(); | ||
expect(newSession.init).toBe(true); | ||
expect(newSession.errors).toBe(0); | ||
expect(newSession.status).toBe('ok'); | ||
expect(newSession.sid).toBeDefined(); | ||
expect(initSession.sid).not.toBe(newSession.sid); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/integration-tests/suites/sessions/update-session/subject.js
This file contains hidden or 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,7 @@ | ||
document.getElementById('throw-error').addEventListener('click', () => { | ||
throw new Error('test'); | ||
}); | ||
|
||
document.getElementById('capture-exception').addEventListener('click', () => { | ||
Sentry.captureException('test'); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/integration-tests/suites/sessions/update-session/template.hbs
This file contains hidden or 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,12 @@ | ||
<html> | ||
<head> | ||
<meta charset='utf-8' /> | ||
<title></title> | ||
<script src='{{htmlWebpackPlugin.options.initialization}}'></script> | ||
</head> | ||
<body> | ||
<button id='throw-error'>Throw Error</button> | ||
<button id='capture-exception'>Capture Exception</button> | ||
<script src='{{htmlWebpackPlugin.options.subject}}'></script> | ||
</body> | ||
</html> |
35 changes: 35 additions & 0 deletions
35
packages/integration-tests/suites/sessions/update-session/test.ts
This file contains hidden or 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,35 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { getCurrentSession } from '../../../utils/helpers'; | ||
|
||
sentryTest('should update session when an error is thrown.', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
const pageloadSession = await getCurrentSession(page, url); | ||
const updatedSession = (await Promise.all([page.click('#throw-error'), getCurrentSession(page)]))[1]; | ||
|
||
expect(pageloadSession).toBeDefined(); | ||
expect(pageloadSession.init).toBe(true); | ||
expect(pageloadSession.errors).toBe(0); | ||
expect(updatedSession).toBeDefined(); | ||
expect(updatedSession.init).toBe(false); | ||
expect(updatedSession.errors).toBe(1); | ||
expect(updatedSession.status).toBe('ok'); | ||
expect(pageloadSession.sid).toBe(updatedSession.sid); | ||
}); | ||
|
||
sentryTest('should update session when an exception is captured.', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const pageloadSession = await getCurrentSession(page, url); | ||
const updatedSession = (await Promise.all([page.click('#capture-exception'), getCurrentSession(page)]))[1]; | ||
|
||
expect(pageloadSession).toBeDefined(); | ||
expect(pageloadSession.init).toBe(true); | ||
expect(pageloadSession.errors).toBe(0); | ||
expect(updatedSession).toBeDefined(); | ||
expect(updatedSession.init).toBe(false); | ||
expect(updatedSession.errors).toBe(1); | ||
expect(updatedSession.status).toBe('ok'); | ||
expect(pageloadSession.sid).toBe(updatedSession.sid); | ||
}); |
This file contains hidden or 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
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.
Technically this is not guaranteed to be a session right?
I think we should rename
getMultipleSentryTransactionRequests
->getMultipleSentryEnvelopeRequests
and directly call that in the tests. The tests can just handle picking the right request and asserting on it (they can even assert on the total amount of requests sent if needed).Maybe we use
getMultipleSentryEnvelopeRequests
just for this PR, and then migrate the other test files in another PR.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.
Yes, and #4527 seems to solve the confusion. I'll update the PR with proper types after that gets merged, unless this one is urgent?
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.
Nothing using those types internally yet, I would just make the changes here and we can come back and update this after.