• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { spawnPromisified } from '../common/index.mjs';
2import tmpdir from '../common/tmpdir.js';
3
4import assert from 'node:assert';
5import fs from 'node:fs/promises';
6import { execPath } from 'node:process';
7
8tmpdir.refresh();
9const target = tmpdir.fileURL(`${Math.random()}.mjs`);
10
11await assert.rejects(import(target), { code: 'ERR_MODULE_NOT_FOUND' });
12
13await fs.writeFile(target, 'export default "actual target"\n');
14
15const moduleRecord = await import(target);
16
17await fs.rm(target);
18
19assert.strictEqual(await import(target), moduleRecord);
20
21// Add the file back, it should be deleted by the subprocess.
22await fs.writeFile(target, 'export default "actual target"\n');
23
24assert.deepStrictEqual(
25  await spawnPromisified(execPath, [
26    '--input-type=module',
27    '--eval',
28    [`import * as d from${JSON.stringify(target)};`,
29     'import{rm}from"node:fs/promises";',
30     `await rm(new URL(${JSON.stringify(target)}));`,
31     'import{strictEqual}from"node:assert";',
32     `strictEqual(JSON.stringify(await import(${JSON.stringify(target)})),JSON.stringify(d));`].join(''),
33  ]),
34  {
35    code: 0,
36    signal: null,
37    stderr: '',
38    stdout: '',
39  });
40