forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-module-loadmodule.js
More file actions
36 lines (30 loc) · 1.05 KB
/
Copy pathtest-module-loadmodule.js
File metadata and controls
36 lines (30 loc) · 1.05 KB
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 test = require('node:test');
const assert = require('node:assert');
const { pathToFileURL } = require('node:url');
const fixtures = require('../common/fixtures');
const { loadModule, kModuleFormats } = require('node:module');
const parentURL = pathToFileURL(__filename);
test('kModuleFormats is a frozen object', () => {
assert.ok(typeof kModuleFormats === 'object');
assert.ok(Object.isFrozen(kModuleFormats));
});
test('should throw if the module is not found', async () => {
await assert.rejects(
async () => {
await loadModule('nonexistent-module', parentURL);
},
{
code: 'ERR_MODULE_NOT_FOUND',
}
);
});
test('should load a module', async () => {
const fileUrl = fixtures.fileURL('es-modules/cjs.js');
const { url, format, source } = await loadModule(fileUrl, parentURL);
assert.strictEqual(format, kModuleFormats.commonjs);
assert.strictEqual(url, fileUrl.href);
// `source` is null and the final builtin loader will read the file.
assert.strictEqual(source, null);
});