11cb0ef41Sopenharmony_ciimport { spawnPromisified } from '../common/index.mjs';
21cb0ef41Sopenharmony_ciimport tmpdir from '../common/tmpdir.js';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciimport assert from 'node:assert';
51cb0ef41Sopenharmony_ciimport fs from 'node:fs/promises';
61cb0ef41Sopenharmony_ciimport { execPath } from 'node:process';
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_citmpdir.refresh();
91cb0ef41Sopenharmony_ciconst target = tmpdir.fileURL(`${Math.random()}.mjs`);
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciawait assert.rejects(import(target), { code: 'ERR_MODULE_NOT_FOUND' });
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciawait fs.writeFile(target, 'export default "actual target"\n');
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst moduleRecord = await import(target);
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciawait fs.rm(target);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciassert.strictEqual(await import(target), moduleRecord);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Add the file back, it should be deleted by the subprocess.
221cb0ef41Sopenharmony_ciawait fs.writeFile(target, 'export default "actual target"\n');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciassert.deepStrictEqual(
251cb0ef41Sopenharmony_ci  await spawnPromisified(execPath, [
261cb0ef41Sopenharmony_ci    '--input-type=module',
271cb0ef41Sopenharmony_ci    '--eval',
281cb0ef41Sopenharmony_ci    [`import * as d from${JSON.stringify(target)};`,
291cb0ef41Sopenharmony_ci     'import{rm}from"node:fs/promises";',
301cb0ef41Sopenharmony_ci     `await rm(new URL(${JSON.stringify(target)}));`,
311cb0ef41Sopenharmony_ci     'import{strictEqual}from"node:assert";',
321cb0ef41Sopenharmony_ci     `strictEqual(JSON.stringify(await import(${JSON.stringify(target)})),JSON.stringify(d));`].join(''),
331cb0ef41Sopenharmony_ci  ]),
341cb0ef41Sopenharmony_ci  {
351cb0ef41Sopenharmony_ci    code: 0,
361cb0ef41Sopenharmony_ci    signal: null,
371cb0ef41Sopenharmony_ci    stderr: '',
381cb0ef41Sopenharmony_ci    stdout: '',
391cb0ef41Sopenharmony_ci  });
40