node/test/parallel/test-internal-module-wrap.js
Gus Caplan 3e8af961b3 test: formalize exposure of internal bindings
moves exposed internalBindings to a single location with short
guidelines on how to expose them and a warning for users should they
come across it

PR-URL: https://github.com/nodejs/node/pull/18698
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-02-10 14:50:43 -06:00

30 lines
846 B
JavaScript

'use strict';
// Flags: --expose-internals
const common = require('../common');
common.crashOnUnhandledRejection();
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(), 6);
assert.strictEqual(foo.namespace().five, 5);
})();