node/test/es-module/test-esm-dynamic-import-mutating-fs.js
2023-08-21 16:42:03 +00:00

23 lines
566 B
JavaScript

'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('node:assert');
const fs = require('node:fs/promises');
tmpdir.refresh();
const target = tmpdir.fileURL(`${Math.random()}.mjs`);
(async () => {
await assert.rejects(import(target), { code: 'ERR_MODULE_NOT_FOUND' });
await fs.writeFile(target, 'export default "actual target"\n');
const moduleRecord = await import(target);
await fs.rm(target);
assert.strictEqual(await import(target), moduleRecord);
})().then(common.mustCall());