mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
df08779e0d
This commit removes `common.crashOnUnhandledRejection()` and adds `common.disableCrashOnUnhandledRejection()`. To reduce the risk of mistakes and make writing tests that involve promises simpler, always install the unhandledRejection hook in tests and provide a way to disable it for the rare cases where it's needed. PR-URL: https://github.com/nodejs/node/pull/21849 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
33 lines
839 B
JavaScript
33 lines
839 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
const util = require('util');
|
|
|
|
const server = http2.createServer();
|
|
server.on('stream', common.mustCall((stream) => {
|
|
stream.respond();
|
|
stream.end('ok');
|
|
}));
|
|
server.listen(0, common.mustCall(() => {
|
|
const connect = util.promisify(http2.connect);
|
|
|
|
connect(`http://localhost:${server.address().port}`)
|
|
.then(common.mustCall((client) => {
|
|
assert(client);
|
|
const req = client.request();
|
|
let data = '';
|
|
req.setEncoding('utf8');
|
|
req.on('data', (chunk) => data += chunk);
|
|
req.on('end', common.mustCall(() => {
|
|
assert.strictEqual(data, 'ok');
|
|
client.close();
|
|
server.close();
|
|
}));
|
|
}));
|
|
}));
|