-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Add e2e tests for server push events #36879
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 all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
df2fc5d
Add e2e tests for server-sent events
silverwind 39aa8a0
Make event tests transport-agnostic and faster
silverwind fbbb46f
Rename test describe from "Events" to "events"
silverwind 0a8a248
Reduce test timeout from 120s to 90s
silverwind ec92948
Improve e2e event tests and utilities
silverwind 5d5322c
Generate random test user password instead of hardcoding
silverwind 0f8db2a
Use JSDoc comment for testUserPassword
silverwind 6775064
Merge branch 'main' into e2eevents
silverwind d39768b
Merge branch 'main' into e2eevents
silverwind 096b8a5
Merge branch 'main' into e2eevents
silverwind b55ed83
Merge branch 'main' into e2eevents
silverwind 81df3c6
Merge branch 'main' into e2eevents
silverwind 5faae40
Improve e2e event tests: reduce timeouts, parallelize cleanup
silverwind a16e119
Add frontend dep to test-e2e, parallelize repo creation and login
silverwind f79c8ea
Move frontend asset dependency to EXECUTABLE_E2E target
silverwind 2b1a90b
Merge branch 'main' into e2eevents
silverwind 1d950fa
refactor legacy shared worker code
wxiaoguang a5c9ee2
rename
wxiaoguang e603380
use UserEventsSharedWorker class directly
wxiaoguang 9b6a738
add comment for the delayed logout redirecting behavior
wxiaoguang a1b6af6
fine tune comment
wxiaoguang 732961d
fix shared worker debug name
wxiaoguang b6b1cb6
fix comment
wxiaoguang 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
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,83 @@ | ||
| import {test, expect} from '@playwright/test'; | ||
| import {loginUser, baseUrl, apiUserHeaders, apiCreateUser, apiDeleteUser, apiCreateRepo, apiCreateIssue, apiStartStopwatch} from './utils.ts'; | ||
|
|
||
| // These tests rely on a short EVENT_SOURCE_UPDATE_TIME in the e2e server config. | ||
| test.describe('events', () => { | ||
| test('notification count', async ({page, request}) => { | ||
| const id = `ev-notif-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`; | ||
| const owner = `${id}-owner`; | ||
| const commenter = `${id}-commenter`; | ||
| const repoName = id; | ||
|
|
||
| await Promise.all([apiCreateUser(request, owner), apiCreateUser(request, commenter)]); | ||
|
|
||
| // Create repo and login in parallel — repo is needed for the issue, login for the event stream | ||
| await Promise.all([ | ||
| apiCreateRepo(request, {name: repoName, headers: apiUserHeaders(owner)}), | ||
| loginUser(page, owner), | ||
| ]); | ||
| const badge = page.locator('a.not-mobile .notification_count'); | ||
| await expect(badge).toBeHidden(); | ||
|
|
||
| // Create issue as another user — this generates a notification delivered via server push | ||
| await apiCreateIssue(request, owner, repoName, {title: 'events notification test', headers: apiUserHeaders(commenter)}); | ||
|
|
||
| // Wait for the notification badge to appear via server event | ||
| await expect(badge).toBeVisible({timeout: 15000}); | ||
|
|
||
| // Cleanup | ||
| await Promise.all([apiDeleteUser(request, commenter), apiDeleteUser(request, owner)]); | ||
| }); | ||
|
|
||
| test('stopwatch', async ({page, request}) => { | ||
| const name = `ev-sw-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`; | ||
| const headers = apiUserHeaders(name); | ||
|
|
||
| await apiCreateUser(request, name); | ||
|
|
||
| // Create repo, issue, and start stopwatch before login | ||
| await apiCreateRepo(request, {name, headers}); | ||
| await apiCreateIssue(request, name, name, {title: 'events stopwatch test', headers}); | ||
| await apiStartStopwatch(request, name, name, 1, {headers}); | ||
|
|
||
| // Login — page renders with the active stopwatch element | ||
| await loginUser(page, name); | ||
|
|
||
| // Verify stopwatch is visible and links to the correct issue | ||
| const stopwatch = page.locator('.active-stopwatch.not-mobile'); | ||
| await expect(stopwatch).toBeVisible(); | ||
|
|
||
| // Cleanup | ||
| await apiDeleteUser(request, name); | ||
| }); | ||
|
|
||
| test('logout propagation', async ({browser, request}) => { | ||
| const name = `ev-logout-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`; | ||
|
|
||
| await apiCreateUser(request, name); | ||
|
|
||
| // Use a single context so both pages share the same session and SharedWorker | ||
| const context = await browser.newContext({baseURL: baseUrl()}); | ||
| const page1 = await context.newPage(); | ||
| const page2 = await context.newPage(); | ||
|
|
||
| await loginUser(page1, name); | ||
|
|
||
| // Navigate page2 so it connects to the shared event stream | ||
| await page2.goto('/'); | ||
|
|
||
| // Verify page2 is logged in | ||
| await expect(page2.getByRole('link', {name: 'Sign In'})).toBeHidden(); | ||
|
|
||
| // Logout from page1 — this sends a logout event to all tabs | ||
| await page1.goto('/user/logout'); | ||
|
|
||
| // page2 should be redirected via the logout event | ||
| await expect(page2.getByRole('link', {name: 'Sign In'})).toBeVisible(); | ||
|
|
||
| await context.close(); | ||
|
|
||
| // Cleanup | ||
| await apiDeleteUser(request, name); | ||
| }); | ||
| }); | ||
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.