11cb0ef41Sopenharmony_ciimport { spawnPromisified } from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport assert from 'node:assert';
31cb0ef41Sopenharmony_ciimport { execPath } from 'node:process';
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciawait Promise.all([
61cb0ef41Sopenharmony_ci  // Using importAssertions in the resolve hook should warn but still work.
71cb0ef41Sopenharmony_ci  `data:text/javascript,export ${encodeURIComponent(function resolve() {
81cb0ef41Sopenharmony_ci    return { shortCircuit: true, url: 'data:application/json,1', importAssertions: { type: 'json' } };
91cb0ef41Sopenharmony_ci  })}`,
101cb0ef41Sopenharmony_ci  // Setting importAssertions on the context object of the load hook should warn but still work.
111cb0ef41Sopenharmony_ci  `data:text/javascript,export ${encodeURIComponent(function load(u, c, n) {
121cb0ef41Sopenharmony_ci    c.importAssertions = { type: 'json' };
131cb0ef41Sopenharmony_ci    return n('data:application/json,1', c);
141cb0ef41Sopenharmony_ci  })}`,
151cb0ef41Sopenharmony_ci  // Creating a new context object with importAssertions in the load hook should warn but still work.
161cb0ef41Sopenharmony_ci  `data:text/javascript,export ${encodeURIComponent(function load(u, c, n) {
171cb0ef41Sopenharmony_ci    return n('data:application/json,1', { importAssertions: { type: 'json' } });
181cb0ef41Sopenharmony_ci  })}`,
191cb0ef41Sopenharmony_ci].map(async (loaderURL) => {
201cb0ef41Sopenharmony_ci  const { stdout, stderr, code } = await spawnPromisified(execPath, [
211cb0ef41Sopenharmony_ci    '--input-type=module',
221cb0ef41Sopenharmony_ci    '--eval', `
231cb0ef41Sopenharmony_ci    import assert from 'node:assert';
241cb0ef41Sopenharmony_ci    import { register } from 'node:module';
251cb0ef41Sopenharmony_ci    
261cb0ef41Sopenharmony_ci    register(${JSON.stringify(loaderURL)});
271cb0ef41Sopenharmony_ci    
281cb0ef41Sopenharmony_ci    assert.deepStrictEqual(
291cb0ef41Sopenharmony_ci      { ...await import('data:') },
301cb0ef41Sopenharmony_ci      { default: 1 }
311cb0ef41Sopenharmony_ci      );`,
321cb0ef41Sopenharmony_ci  ]);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  assert.match(stderr, /Use `importAttributes` instead of `importAssertions`/);
351cb0ef41Sopenharmony_ci  assert.strictEqual(stdout, '');
361cb0ef41Sopenharmony_ci  assert.strictEqual(code, 0);
371cb0ef41Sopenharmony_ci}));
38