mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

PR-URL: https://github.com/nodejs/node/pull/37201 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
34 lines
783 B
JavaScript
34 lines
783 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
|
|
const { createRequire } = require('module');
|
|
|
|
const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js');
|
|
const u = new URL(`file://${p}`);
|
|
|
|
const reqToo = createRequire(u);
|
|
assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });
|
|
|
|
assert.throws(() => {
|
|
createRequire('https://github.com/nodejs/node/pull/27405/');
|
|
}, {
|
|
code: 'ERR_INVALID_ARG_VALUE'
|
|
});
|
|
|
|
assert.throws(() => {
|
|
createRequire('../');
|
|
}, {
|
|
code: 'ERR_INVALID_ARG_VALUE'
|
|
});
|
|
|
|
assert.throws(() => {
|
|
createRequire({});
|
|
}, {
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
message: 'The argument \'filename\' must be a file URL object, file URL ' +
|
|
'string, or absolute path string. Received {}'
|
|
});
|