blob: fc7c8b3fc697eadd3878670ccd37848ba008deb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
'use strict';
require('../common');
const assert = require('assert');
const path = require('path');
const { createRequire, createRequireFromPath } = require('module');
const p = path.resolve(__dirname, '..', 'fixtures', 'fake.js');
const u = new URL(`file://${p}`);
const req = createRequireFromPath(p);
assert.strictEqual(req('./baz'), 'perhaps I work');
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 {}'
});
|