Skip to content

Add v3 protocol test suite - #45

Closed
sleeyax wants to merge 4 commits into
socketio:v3from
sleeyax:v3-testsuite
Closed

Add v3 protocol test suite#45
sleeyax wants to merge 4 commits into
socketio:v3from
sleeyax:v3-testsuite

Conversation

@sleeyax

@sleeyax sleeyax commented Jun 29, 2023

Copy link
Copy Markdown

Closes socketio/socket.io-protocol#30.

TODO (help welcome):

  • Add test for a payload with binary data (not base64 encoded)

Let me know if something else is missing or should be updated.

darrachequesne pushed a commit that referenced this pull request Jul 2, 2023
@darrachequesne

Copy link
Copy Markdown
Member

Awesome, thanks! Merged as 723c7ba.

I have added a test with binary:

it("sends and receives a payload containing plain text and binary packets (binary)", async () => {
const sid = await initLongPollingSession(true);
const pushResponse = await fetch(
`${URL}/engine.io/?EIO=3&transport=polling&sid=${sid}`,
{
method: "post",
body: "6:4hello10:b4AQIDBA==",
}
);
expect(pushResponse.status).to.eql(200);
const postContent = await pushResponse.text();
expect(postContent).to.eql("ok");
const pollResponse = await fetch(
`${URL}/engine.io/?EIO=3&transport=polling&sid=${sid}`
);
expect(pollResponse.status).to.eql(200);
const buffer = await pollResponse.arrayBuffer();
// 0 => string
// 6 => byte length
// 255 => delimiter
// 52 => 4 (MESSAGE packet type)
// 104 101 108 108 111 => "hello"
// 1 => binary
// 5 => byte length
// 255 => delimiter
// 4 => 4 (MESSAGE packet type)
// 1 2 3 4 => binary message
expect(buffer).to.eql(Uint8Array.from([0, 6, 255, 52, 104, 101, 108, 108, 111, 1, 5, 255, 4, 1, 2, 3, 4]).buffer);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants