Skip to content

Commit

Permalink
[test] Increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Mar 20, 2019
1 parent 3a5a20a commit bcab373
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 28 additions & 1 deletion test/receiver.test.js
Expand Up @@ -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) => {
Expand All @@ -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();

Expand Down
6 changes: 2 additions & 4 deletions test/websocket.test.js
Expand Up @@ -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';

Expand All @@ -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
});
});
Expand Down

0 comments on commit bcab373

Please sign in to comment.