• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import '../common/index.mjs';
2import * as fixtures from '../common/fixtures.mjs';
3import { register } from 'node:module';
4import assert from 'node:assert';
5
6async function resolve(referrer, context, next) {
7  const result = await next(referrer, context);
8  const url = new URL(result.url);
9  url.searchParams.set('randomSeed', Math.random());
10  result.url = url.href;
11  return result;
12}
13
14function load(url, context, next) {
15  if (context.importAttributes.type === 'json') {
16    return {
17      shortCircuit: true,
18      format: 'json',
19      source: JSON.stringify({ data: Math.random() }),
20    };
21  }
22  return next(url, context);
23}
24
25register(`data:text/javascript,export ${encodeURIComponent(resolve)};export ${encodeURIComponent(load)}`);
26
27assert.notDeepStrictEqual(
28  await import(fixtures.fileURL('empty.json'), { with: { type: 'json' } }),
29  await import(fixtures.fileURL('empty.json'), { with: { type: 'json' } }),
30);
31