()
| 26 | } |
| 27 | |
| 28 | async function test() { |
| 29 | const foo = new SourceTextModule('export const a = 1;'); |
| 30 | await foo.link(common.mustNotCall()); |
| 31 | await foo.evaluate(); |
| 32 | |
| 33 | { |
| 34 | const s = new Script('import("foo")', { |
| 35 | importModuleDynamically: common.mustCall((specifier, wrap) => { |
| 36 | assert.strictEqual(specifier, 'foo'); |
| 37 | assert.strictEqual(wrap, s); |
| 38 | return foo; |
| 39 | }), |
| 40 | }); |
| 41 | |
| 42 | const result = s.runInThisContext(); |
| 43 | assert.strictEqual(await result, foo.namespace); |
| 44 | } |
| 45 | |
| 46 | { |
| 47 | const m = new SourceTextModule('globalThis.fooResult = import("foo")', { |
| 48 | importModuleDynamically: common.mustCall((specifier, wrap) => { |
| 49 | assert.strictEqual(specifier, 'foo'); |
| 50 | assert.strictEqual(wrap, m); |
| 51 | return foo; |
| 52 | }), |
| 53 | }); |
| 54 | await m.link(common.mustNotCall()); |
| 55 | await m.evaluate(); |
| 56 | assert.strictEqual(await globalThis.fooResult, foo.namespace); |
| 57 | delete globalThis.fooResult; |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | const s = new Script('import("foo", { with: { key: "value" } })', { |
| 62 | importModuleDynamically: common.mustCall((specifier, wrap, attributes, phase) => { |
| 63 | assert.strictEqual(specifier, 'foo'); |
| 64 | assert.strictEqual(wrap, s); |
| 65 | assert.deepStrictEqual(attributes, { __proto__: null, key: 'value' }); |
| 66 | assert.strictEqual(phase, 'evaluation'); |
| 67 | return foo; |
| 68 | }), |
| 69 | }); |
| 70 | |
| 71 | const result = s.runInThisContext(); |
| 72 | assert.strictEqual(await result, foo.namespace); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | async function testInvalid() { |
| 77 | const m = new SourceTextModule('globalThis.fooResult = import("foo")', { |
no test coverage detected
searching dependent graphs…