This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f8faa3
commit f7b8a12
Showing
5 changed files
with
136 additions
and
26 deletions.
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
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
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,30 @@ | ||
|
||
import * as underTest from '../src/stream' | ||
import { expect } from 'aegir/chai' | ||
import { Uint8ArrayList } from 'uint8arraylist' | ||
|
||
const setup = (cb: { send: (bytes: Uint8Array) => void }, maxMsgSize?: number): underTest.WebRTCStream => { | ||
const datachannel = { | ||
readyState: 'open', | ||
send: cb.send | ||
|
||
} | ||
return new underTest.WebRTCStream({ channel: datachannel as RTCDataChannel, stat: underTest.defaultStat('outbound'), maxMsgSize }) | ||
} | ||
|
||
describe('MessageProcessor', () => { | ||
it('handles unconstrained message', () => { | ||
const sent: Uint8Array[] = [] | ||
const webrtcStream = setup({ send: (bytes) => sent.push(bytes) }) | ||
webrtcStream.messageProcessor.send(new Uint8ArrayList(new Uint8Array(1))) | ||
expect(sent).to.deep.equals([new Uint8Array(1)]) | ||
}) | ||
|
||
it('handles bounded by message size', () => { | ||
const sent: Uint8Array[] = [] | ||
const maxMsgSize = 1 | ||
const webrtcStream = setup({ send: (bytes) => sent.push(bytes) }, maxMsgSize) | ||
webrtcStream.messageProcessor.send(new Uint8ArrayList(new Uint8Array(2))) | ||
expect(sent).to.deep.equals([new Uint8Array(1), new Uint8Array(1)]) | ||
}) | ||
}) |