mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 20:06:58 +00:00

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>
25 lines
928 B
JavaScript
25 lines
928 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const zlib = require('zlib');
|
|
const { inspect, promisify } = require('util');
|
|
const assert = require('assert');
|
|
const emptyBuffer = Buffer.alloc(0);
|
|
|
|
(async function() {
|
|
for (const [ compress, decompress, method ] of [
|
|
[ zlib.deflateRawSync, zlib.inflateRawSync, 'raw sync' ],
|
|
[ zlib.deflateSync, zlib.inflateSync, 'deflate sync' ],
|
|
[ zlib.gzipSync, zlib.gunzipSync, 'gzip sync' ],
|
|
[ promisify(zlib.deflateRaw), promisify(zlib.inflateRaw), 'raw' ],
|
|
[ promisify(zlib.deflate), promisify(zlib.inflate), 'deflate' ],
|
|
[ promisify(zlib.gzip), promisify(zlib.gunzip), 'gzip' ]
|
|
]) {
|
|
const compressed = await compress(emptyBuffer);
|
|
const decompressed = await decompress(compressed);
|
|
assert.deepStrictEqual(
|
|
emptyBuffer, decompressed,
|
|
`Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` +
|
|
`to match for ${method}`);
|
|
}
|
|
})();
|