mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01: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>
29 lines
804 B
JavaScript
29 lines
804 B
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
|
|
const { ModuleWrap } = require('internal/test/binding');
|
|
const { getPromiseDetails, isPromise } = process.binding('util');
|
|
const setTimeoutAsync = require('util').promisify(setTimeout);
|
|
|
|
const foo = new ModuleWrap('export * from "bar"; 6;', 'foo');
|
|
const bar = new ModuleWrap('export const five = 5', 'bar');
|
|
|
|
(async () => {
|
|
const promises = foo.link(() => setTimeoutAsync(1000).then(() => bar));
|
|
assert.strictEqual(promises.length, 1);
|
|
assert(isPromise(promises[0]));
|
|
|
|
await Promise.all(promises);
|
|
|
|
assert.strictEqual(getPromiseDetails(promises[0])[1], bar);
|
|
|
|
foo.instantiate();
|
|
|
|
assert.strictEqual(await foo.evaluate(-1, false), 6);
|
|
assert.strictEqual(foo.namespace().five, 5);
|
|
})();
|