• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4const assert = require('assert');
5
6const { internalBinding } = require('internal/test/binding');
7const { ModuleWrap } = internalBinding('module_wrap');
8const { getPromiseDetails, isPromise } = internalBinding('util');
9const setTimeoutAsync = require('util').promisify(setTimeout);
10
11const foo = new ModuleWrap('foo', undefined, 'export * from "bar";', 0, 0);
12const bar = new ModuleWrap('bar', undefined, 'export const five = 5', 0, 0);
13
14(async () => {
15  const promises = foo.link(() => setTimeoutAsync(1000).then(() => bar));
16  assert.strictEqual(promises.length, 1);
17  assert(isPromise(promises[0]));
18
19  await Promise.all(promises);
20
21  assert.strictEqual(getPromiseDetails(promises[0])[1], bar);
22
23  foo.instantiate();
24
25  assert.strictEqual(await foo.evaluate(-1, false), undefined);
26  assert.strictEqual(foo.getNamespace().five, 5);
27})().then(common.mustCall());
28