node/test/parallel/test-http2-connect.js
Ruben Bridgewater caee112e52
test: remove assert.doesNotThrow()
There is actually no reason to use `assert.doesNotThrow()` in the
tests. If a test throws, just let the error bubble up right away
instead of first catching it and then rethrowing it.

PR-URL: https://github.com/nodejs/node/pull/18669
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-02-16 16:53:47 +01:00

51 lines
1.3 KiB
JavaScript

'use strict';
const { mustCall, hasCrypto, skip, expectsError } = require('../common');
if (!hasCrypto)
skip('missing crypto');
const { createServer, connect } = require('http2');
{
const server = createServer();
server.listen(0, mustCall(() => {
const authority = `http://localhost:${server.address().port}`;
const options = {};
const listener = () => mustCall();
const clients = new Set();
// Should not throw.
clients.add(connect(authority));
clients.add(connect(authority, options));
clients.add(connect(authority, options, listener()));
clients.add(connect(authority, listener()));
for (const client of clients) {
client.once('connect', mustCall((headers) => {
client.close();
clients.delete(client);
if (clients.size === 0) {
server.close();
}
}));
}
}));
}
// check for https as protocol
{
const authority = 'https://localhost';
// A socket error may or may not be reported, keep this as a non-op
// instead of a mustCall or mustNotCall
connect(authority).on('error', () => {});
}
// check for error for an invalid protocol (not http or https)
{
const authority = 'ssh://localhost';
expectsError(() => {
connect(authority);
}, {
code: 'ERR_HTTP2_UNSUPPORTED_PROTOCOL',
type: Error
});
}