2024-05-08 02:20:48 +00:00
|
|
|
import { skipIfWorker } from '../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';
|
2024-05-08 02:20:48 +00:00
|
|
|
skipIfWorker();
|
2023-09-29 08:46:32 +00:00
|
|
|
|
|
|
|
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
|
|
|
);
|