1import { spawnPromisified } from '../common/index.mjs'; 2import assert from 'node:assert'; 3import { execPath } from 'node:process'; 4 5await Promise.all([ 6 // Using importAssertions in the resolve hook should warn but still work. 7 `data:text/javascript,export ${encodeURIComponent(function resolve() { 8 return { shortCircuit: true, url: 'data:application/json,1', importAssertions: { type: 'json' } }; 9 })}`, 10 // Setting importAssertions on the context object of the load hook should warn but still work. 11 `data:text/javascript,export ${encodeURIComponent(function load(u, c, n) { 12 c.importAssertions = { type: 'json' }; 13 return n('data:application/json,1', c); 14 })}`, 15 // Creating a new context object with importAssertions in the load hook should warn but still work. 16 `data:text/javascript,export ${encodeURIComponent(function load(u, c, n) { 17 return n('data:application/json,1', { importAssertions: { type: 'json' } }); 18 })}`, 19].map(async (loaderURL) => { 20 const { stdout, stderr, code } = await spawnPromisified(execPath, [ 21 '--input-type=module', 22 '--eval', ` 23 import assert from 'node:assert'; 24 import { register } from 'node:module'; 25 26 register(${JSON.stringify(loaderURL)}); 27 28 assert.deepStrictEqual( 29 { ...await import('data:') }, 30 { default: 1 } 31 );`, 32 ]); 33 34 assert.match(stderr, /Use `importAttributes` instead of `importAssertions`/); 35 assert.strictEqual(stdout, ''); 36 assert.strictEqual(code, 0); 37})); 38