summaryrefslogtreecommitdiff
path: root/test/parallel/test-internal-module-wrap.js
blob: 66a17a0f344701c37de89c90bdd81e17538a5805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'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);
})();