2023-10-14 03:52:38 +00:00
|
|
|
import { spawnPromisified } from '../common/index.mjs';
|
|
|
|
import assert from 'node:assert';
|
|
|
|
import { execPath } from 'node:process';
|
2023-03-03 18:31:12 +00:00
|
|
|
|
2023-10-14 03:52:38 +00:00
|
|
|
await Promise.all([
|
|
|
|
// Using importAssertions in the resolve hook should warn but still work.
|
|
|
|
`data:text/javascript,export ${encodeURIComponent(function resolve() {
|
|
|
|
return { shortCircuit: true, url: 'data:application/json,1', importAssertions: { type: 'json' } };
|
|
|
|
})}`,
|
2024-10-15 19:02:07 +00:00
|
|
|
// Using importAssertions on the context object of the resolve hook should warn but still work.
|
|
|
|
`data:text/javascript,export ${encodeURIComponent(function resolve(s, c, n) {
|
|
|
|
const type = c.importAssertions.type;
|
|
|
|
return { shortCircuit: true, url: 'data:application/json,1', importAttributes: { type: type ?? 'json' } };
|
|
|
|
})}`,
|
2023-10-14 03:52:38 +00:00
|
|
|
// Setting importAssertions on the context object of the load hook should warn but still work.
|
|
|
|
`data:text/javascript,export ${encodeURIComponent(function load(u, c, n) {
|
|
|
|
c.importAssertions = { type: 'json' };
|
|
|
|
return n('data:application/json,1', c);
|
|
|
|
})}`,
|
|
|
|
// Creating a new context object with importAssertions in the load hook should warn but still work.
|
|
|
|
`data:text/javascript,export ${encodeURIComponent(function load(u, c, n) {
|
|
|
|
return n('data:application/json,1', { importAssertions: { type: 'json' } });
|
|
|
|
})}`,
|
|
|
|
].map(async (loaderURL) => {
|
|
|
|
const { stdout, stderr, code } = await spawnPromisified(execPath, [
|
|
|
|
'--input-type=module',
|
|
|
|
'--eval', `
|
|
|
|
import assert from 'node:assert';
|
|
|
|
import { register } from 'node:module';
|
2024-10-15 19:02:07 +00:00
|
|
|
|
2023-10-14 03:52:38 +00:00
|
|
|
register(${JSON.stringify(loaderURL)});
|
2024-10-15 19:02:07 +00:00
|
|
|
|
2023-10-14 03:52:38 +00:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
{ ...await import('data:') },
|
|
|
|
{ default: 1 }
|
|
|
|
);`,
|
|
|
|
]);
|
2023-03-03 18:31:12 +00:00
|
|
|
|
2023-10-14 03:52:38 +00:00
|
|
|
assert.match(stderr, /Use `importAttributes` instead of `importAssertions`/);
|
|
|
|
assert.strictEqual(stdout, '');
|
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
}));
|