mirror of
https://github.com/nodejs/node.git
synced 2025-05-14 15:26:29 +00:00

fixup: add support for `Object.create(null)` fixup: extend to any 1-argument Object.create call fixup: add tests PR-URL: https://github.com/nodejs/node/pull/46083 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
95 lines
2.9 KiB
JavaScript
95 lines
2.9 KiB
JavaScript
'use strict';
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/4778
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const Module = require('module');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const file = path.join(tmpdir.path, 'test-extensions.foo.bar');
|
|
const dotfile = path.join(tmpdir.path, '.bar');
|
|
const dotfileWithExtension = path.join(tmpdir.path, '.foo.bar');
|
|
|
|
tmpdir.refresh();
|
|
fs.writeFileSync(file, 'console.log(__filename);', 'utf8');
|
|
fs.writeFileSync(dotfile, 'console.log(__filename);', 'utf8');
|
|
fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8');
|
|
|
|
{
|
|
require.extensions['.bar'] = common.mustNotCall();
|
|
require.extensions['.foo.bar'] = common.mustCall();
|
|
const modulePath = path.join(tmpdir.path, 'test-extensions');
|
|
require(modulePath);
|
|
require(file);
|
|
delete require.cache[file];
|
|
delete require.extensions['.bar'];
|
|
delete require.extensions['.foo.bar'];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|
|
|
|
{
|
|
require.extensions['.foo.bar'] = common.mustCall();
|
|
const modulePath = path.join(tmpdir.path, 'test-extensions');
|
|
require(modulePath);
|
|
assert.throws(
|
|
() => require(`${modulePath}.foo`),
|
|
(err) => err.message.startsWith(`Cannot find module '${modulePath}.foo'`)
|
|
);
|
|
require(`${modulePath}.foo.bar`);
|
|
delete require.cache[file];
|
|
delete require.extensions['.foo.bar'];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|
|
|
|
{
|
|
const modulePath = path.join(tmpdir.path, 'test-extensions');
|
|
assert.throws(
|
|
() => require(modulePath),
|
|
(err) => err.message.startsWith(`Cannot find module '${modulePath}'`)
|
|
);
|
|
delete require.cache[file];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|
|
|
|
{
|
|
require.extensions['.bar'] = common.mustNotCall();
|
|
require.extensions['.foo.bar'] = common.mustCall();
|
|
const modulePath = path.join(tmpdir.path, 'test-extensions.foo');
|
|
require(modulePath);
|
|
delete require.cache[file];
|
|
delete require.extensions['.bar'];
|
|
delete require.extensions['.foo.bar'];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|
|
|
|
{
|
|
require.extensions['.foo.bar'] = common.mustNotCall();
|
|
const modulePath = path.join(tmpdir.path, 'test-extensions.foo');
|
|
assert.throws(
|
|
() => require(modulePath),
|
|
(err) => err.message.startsWith(`Cannot find module '${modulePath}'`)
|
|
);
|
|
delete require.extensions['.foo.bar'];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|
|
|
|
{
|
|
require.extensions['.bar'] = common.mustNotCall();
|
|
require(dotfile);
|
|
delete require.cache[dotfile];
|
|
delete require.extensions['.bar'];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|
|
|
|
{
|
|
require.extensions['.bar'] = common.mustCall();
|
|
require.extensions['.foo.bar'] = common.mustNotCall();
|
|
require(dotfileWithExtension);
|
|
delete require.cache[dotfileWithExtension];
|
|
delete require.extensions['.bar'];
|
|
delete require.extensions['.foo.bar'];
|
|
Module._pathCache = { __proto__: null };
|
|
}
|