2024-06-02 22:10:34 +00:00
|
|
|
import '../common/index.mjs';
|
2023-09-29 08:46:32 +00:00
|
|
|
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) {
|
2023-10-14 03:52:38 +00:00
|
|
|
if (context.importAttributes.type === 'json') {
|
2023-09-29 08:46:32 +00:00
|
|
|
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(
|
2023-10-14 03:52:38 +00:00
|
|
|
await import(fixtures.fileURL('empty.json'), { with: { type: 'json' } }),
|
|
|
|
await import(fixtures.fileURL('empty.json'), { with: { type: 'json' } }),
|
2023-09-29 08:46:32 +00:00
|
|
|
);
|