| 11 | let loadCalls = 0; |
| 12 | |
| 13 | export async function resolve(specifier, context, next) { |
| 14 | resolveCalls++; |
| 15 | let url; |
| 16 | |
| 17 | if (resolveCalls === 1) { |
| 18 | url = new URL(specifier).href; |
| 19 | assert.match(specifier, /json-modules\.mjs$/); |
| 20 | |
| 21 | if (!(/\[eval\d*\]$/).test(context.parentURL)) { |
| 22 | assert.strictEqual(context.parentURL, undefined); |
| 23 | } |
| 24 | |
| 25 | assert.deepStrictEqual(context.importAttributes, {}); |
| 26 | } else if (resolveCalls === 2) { |
| 27 | url = new URL(specifier, context.parentURL).href; |
| 28 | assert.match(specifier, /experimental\.json$/); |
| 29 | assert.match(context.parentURL, /json-modules\.mjs$/); |
| 30 | assert.deepStrictEqual(context.importAttributes, { |
| 31 | type: 'json', |
| 32 | }); |
| 33 | } else { |
| 34 | throw new Error(`Unexpected resolve call: ${specifier}`); |
| 35 | } |
| 36 | |
| 37 | // Ensure `context` has all and only the properties it's supposed to |
| 38 | assert.deepStrictEqual(Reflect.ownKeys(context), [ |
| 39 | 'conditions', |
| 40 | 'importAttributes', |
| 41 | 'parentURL', |
| 42 | 'importAssertions', |
| 43 | ]); |
| 44 | assert.ok(Array.isArray(context.conditions)); |
| 45 | assert.strictEqual(typeof next, 'function'); |
| 46 | |
| 47 | const returnValue = { |
| 48 | url, |
| 49 | format: 'test', |
| 50 | shortCircuit: true, |
| 51 | } |
| 52 | |
| 53 | writeSync(1, JSON.stringify(returnValue) + '\n'); // For the test to validate when it parses stdout |
| 54 | |
| 55 | return returnValue; |
| 56 | } |
| 57 | |
| 58 | export async function load(url, context, next) { |
| 59 | loadCalls++; |