Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
eaa911a6
Commit
eaa911a6
authored
Nov 28, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
easy way to mock socket connection loss
parent
26da4b3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
11 deletions
+2
-11
socketServer.ts
playwright/fixtures/socketServer.ts
+1
-10
BlocksContent.pw.tsx
ui/blocks/BlocksContent.pw.tsx
+1
-1
No files found.
playwright/fixtures/socketServer.ts
View file @
eaa911a6
import
type
{
TestFixture
,
Page
}
from
'
@playwright/test
'
;
import
type
{
TestFixture
}
from
'
@playwright/test
'
;
import
type
{
WebSocket
}
from
'
ws
'
;
import
type
{
WebSocket
}
from
'
ws
'
;
import
{
WebSocketServer
}
from
'
ws
'
;
import
{
WebSocketServer
}
from
'
ws
'
;
...
@@ -63,12 +63,3 @@ export function sendMessage(socket: WebSocket, channel: Channel, msg: string, pa
...
@@ -63,12 +63,3 @@ export function sendMessage(socket: WebSocket, channel: Channel, msg: string, pa
payload
,
payload
,
]));
]));
}
}
// we massively rely here on phoenix socket lib implementation where page hide event causes socket disconnect
// i was not able to find better way to simulate connection loss state, feel free to improve it
// see more here https://github.com/phoenixframework/phoenix/blob/3cf1f1065ce11a906bd04b7841814cdced3f0df2/assets/js/phoenix/socket.js#L113
export
async
function
simulateConnectionLoss
(
page
:
Page
)
{
await
page
.
evaluate
(()
=>
{
window
.
dispatchEvent
(
new
Event
(
'
pagehide
'
));
});
}
ui/blocks/BlocksContent.pw.tsx
View file @
eaa911a6
...
@@ -73,7 +73,7 @@ test('socket error', async({ mount, page, createSocket }) => {
...
@@ -73,7 +73,7 @@ test('socket error', async({ mount, page, createSocket }) => {
const
socket
=
await
createSocket
();
const
socket
=
await
createSocket
();
await
socketServer
.
joinChannel
(
socket
,
'
blocks:new_block
'
);
await
socketServer
.
joinChannel
(
socket
,
'
blocks:new_block
'
);
await
socketServer
.
simulateConnectionLoss
(
page
);
socket
.
close
(
);
await
expect
(
component
).
toHaveScreenshot
();
await
expect
(
component
).
toHaveScreenshot
();
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment