Skip to content

Commit

Permalink
[test] Increase code coverage
Browse files Browse the repository at this point in the history
lpinca committed Mar 20, 2019

Verified

This commit was signed with the committer’s verified signature.
lann Lann
1 parent 3a5a20a commit bcab373
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 28 additions & 1 deletion test/receiver.test.js
Original file line number Diff line number Diff line change
@@ -709,7 +709,7 @@ describe('Receiver', () => {
);
});

it('emits an error if a text frame contains invalid UTF-8 data', (done) => {
it('emits an error if a text frame contains invalid UTF-8 data (1/2)', (done) => {
const receiver = new Receiver();

receiver.on('error', (err) => {
@@ -725,6 +725,33 @@ describe('Receiver', () => {
receiver.write(Buffer.from([0x81, 0x04, 0xce, 0xba, 0xe1, 0xbd]));
});

it('emits an error if a text frame contains invalid UTF-8 data (2/2)', (done) => {
const perMessageDeflate = new PerMessageDeflate();
perMessageDeflate.accept([{}]);

const receiver = new Receiver(undefined, {
'permessage-deflate': perMessageDeflate
});
const buf = Buffer.from([0xce, 0xba, 0xe1, 0xbd]);

receiver.on('error', (err) => {
assert.ok(err instanceof Error);
assert.strictEqual(
err.message,
'Invalid WebSocket frame: invalid UTF-8 sequence'
);
assert.strictEqual(err[kStatusCode], 1007);
done();
});

perMessageDeflate.compress(buf, true, (err, data) => {
if (err) return done(err);

receiver.write(Buffer.from([0xc1, data.length]));
receiver.write(data);
});
});

it('emits an error if a close frame has a payload of 1 B', (done) => {
const receiver = new Receiver();

6 changes: 2 additions & 4 deletions test/websocket.test.js
Original file line number Diff line number Diff line change
@@ -1870,9 +1870,7 @@ describe('WebSocket', () => {
const ws = new WebSocket(`ws://${auth}@localhost`, { agent });
});

it('adds the authorization header if the url has userinfo (2/2)', function(done) {
if (!url.URL) return this.skip();

it('adds the authorization header if the url has userinfo (2/2)', (done) => {
const agent = new CustomAgent();
const auth = 'test:testpass';

@@ -1884,7 +1882,7 @@ describe('WebSocket', () => {
done();
};

const ws = new WebSocket(new url.URL(`ws://${auth}@localhost`), {
const ws = new WebSocket(url.parse(`ws://${auth}@localhost`), {
agent
});
});

0 comments on commit bcab373

Please sign in to comment.