forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-require-module.js
More file actions
58 lines (50 loc) · 1.77 KB
/
test-require-module.js
File metadata and controls
58 lines (50 loc) · 1.77 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Flags: --experimental-require-module
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
// Only the first load will trigger the warning.
common.expectWarning(
'ExperimentalWarning',
`CommonJS module ${__filename} is loading ES Module ` +
`${path.resolve(__dirname, '../fixtures/es-module-loaders/module-named-exports.mjs')} using require().\n` +
'Support for loading ES Module in require() is an experimental feature ' +
'and might change at any time'
);
// Test named exports.
{
const mod = require('../fixtures/es-module-loaders/module-named-exports.mjs');
common.expectRequiredModule(mod, { foo: 'foo', bar: 'bar' });
}
// Test ESM that import ESM.
{
const mod = require('../fixtures/es-modules/import-esm.mjs');
common.expectRequiredModule(mod, { hello: 'world' });
}
// Test ESM that import CJS.
{
const mod = require('../fixtures/es-modules/cjs-exports.mjs');
common.expectRequiredModule(mod, { });
}
// Test ESM that require() CJS.
{
const mjs = require('../common/index.mjs');
// Only comparing a few properties because the ESM version of test/common doesn't
// re-export everything from the CJS version.
assert.strictEqual(common.mustCall, mjs.mustCall);
assert.strictEqual(common.localIPv6Hosts, mjs.localIPv6Hosts);
}
// Test "type": "module" and "main" field in package.json.
// Also, test default export.
{
const mod = require('../fixtures/es-modules/package-type-module');
common.expectRequiredModule(mod, { default: 'package-type-module' });
}
// Test data: import.
{
const mod = require('../fixtures/es-modules/data-import.mjs');
common.expectRequiredModule(mod, {
data: { hello: 'world' },
id: 'data:text/javascript,export default %7B%20hello%3A%20%22world%22%20%7D'
});
}