forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-require-node-modules-warning.js
More file actions
71 lines (64 loc) · 1.76 KB
/
test-require-node-modules-warning.js
File metadata and controls
71 lines (64 loc) · 1.76 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
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
// This checks the warning and the stack trace emitted by
// --trace-require-module=no-node-modules.
require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');
const warningRE = /Support for loading ES Module in require\(\)/;
// The fixtures are placed in a directory that includes "node_modules" in its name
// to check false negatives.
// require() in non-node_modules -> esm in node_modules should warn.
spawnSyncAndAssert(
process.execPath,
[
'--trace-require-module=no-node-modules',
fixtures.path('es-modules', 'test_node_modules', 'require-esm.js'),
],
{
trim: true,
stderr: warningRE,
stdout: 'world',
}
);
// require() in non-node_modules -> require() in node_modules -> esm in node_modules
// should not warn.
spawnSyncAndAssert(
process.execPath,
[
'--trace-require-module=no-node-modules',
fixtures.path('es-modules', 'test_node_modules', 'require-require-esm.js'),
],
{
trim: true,
stderr: '',
stdout: 'world',
}
);
// Import in non-node_modules -> require() in node_modules -> esm in node_modules
// should not warn.
spawnSyncAndAssert(
process.execPath,
[
'--trace-require-module=no-node-modules',
fixtures.path('es-modules', 'test_node_modules', 'import-require-esm.mjs'),
],
{
trim: true,
stderr: '',
stdout: 'world',
}
);
// Import in non-node_modules -> import in node_modules ->
// require() in node_modules -> esm in node_modules should not warn.
spawnSyncAndAssert(
process.execPath,
[
'--trace-require-module=no-node-modules',
fixtures.path('es-modules', 'test_node_modules', 'import-import-require-esm.mjs'),
],
{
trim: true,
stderr: '',
stdout: 'world',
}
);