node/test/parallel/test-require-enoent-dir.js
Bradley Farias ccd81e8717
module: ensure relative requires work from deleted directories
PR-URL: https://github.com/nodejs/node/pull/42384
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-10-31 19:53:58 +00:00

31 lines
738 B
JavaScript

'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
tmpdir.refresh();
const fooPath = path.join(tmpdir.path, 'foo.cjs');
fs.writeFileSync(fooPath, '');
const dirPath = path.join(tmpdir.path, 'delete_me');
fs.mkdirSync(dirPath, {
recursive: true
});
const barPath = path.join(dirPath, 'bar.cjs');
fs.writeFileSync(barPath, `
module.exports = () => require('../foo.cjs').call()
`);
const foo = require(fooPath);
const unique = Symbol('unique');
foo.call = common.mustCall(() => unique);
const bar = require(barPath);
fs.rmSync(dirPath, { recursive: true });
assert.strict.equal(bar(), unique);