Skip to content

Commit

Permalink
[test] Do not call the done callback prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Jan 6, 2022
1 parent d2c935a commit 4081a36
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions test/sender.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,22 @@ describe('Sender', () => {

describe('#send', () => {
it('compresses data if compress option is enabled', (done) => {
const chunks = [];
const perMessageDeflate = new PerMessageDeflate();
let count = 0;
const mockSocket = new MockSocket({
write: (data) => {
assert.strictEqual(data[0] & 0x40, 0x40);
if (++count === 3) done();
write: (chunk) => {
chunks.push(chunk);
if (chunks.length !== 6) return;

assert.strictEqual(chunks[0].length, 2);
assert.strictEqual(chunks[0][0] & 0x40, 0x40);

assert.strictEqual(chunks[2].length, 2);
assert.strictEqual(chunks[2][0] & 0x40, 0x40);

assert.strictEqual(chunks[4].length, 2);
assert.strictEqual(chunks[4][0] & 0x40, 0x40);
done();
}
});
const sender = new Sender(mockSocket, {
Expand All @@ -74,10 +84,16 @@ describe('Sender', () => {

describe('when context takeover is disabled', () => {
it('honors the compression threshold', (done) => {
const chunks = [];
const perMessageDeflate = new PerMessageDeflate();
const mockSocket = new MockSocket({
write: (data) => {
assert.notStrictEqual(data[0] & 0x40, 0x40);
write: (chunk) => {
chunks.push(chunk);
if (chunks.length !== 2) return;

assert.strictEqual(chunks[0].length, 2);
assert.notStrictEqual(chunk[0][0] & 0x40, 0x40);
assert.deepStrictEqual(chunks[1], Buffer.from('hi'));
done();
}
});
Expand Down

0 comments on commit 4081a36

Please sign in to comment.