forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-esm-virtual-json.mjs
More file actions
30 lines (26 loc) · 927 Bytes
/
test-esm-virtual-json.mjs
File metadata and controls
30 lines (26 loc) · 927 Bytes
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
30
import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { register } from 'node:module';
import assert from 'node:assert';
async function resolve(referrer, context, next) {
const result = await next(referrer, context);
const url = new URL(result.url);
url.searchParams.set('randomSeed', Math.random());
result.url = url.href;
return result;
}
function load(url, context, next) {
if (context.importAssertions.type === 'json') {
return {
shortCircuit: true,
format: 'json',
source: JSON.stringify({ data: Math.random() }),
};
}
return next(url, context);
}
register(`data:text/javascript,export ${encodeURIComponent(resolve)};export ${encodeURIComponent(load)}`);
assert.notDeepStrictEqual(
await import(fixtures.fileURL('empty.json'), { assert: { type: 'json' } }),
await import(fixtures.fileURL('empty.json'), { assert: { type: 'json' } }),
);