Skip to content

Commit c341f93

Browse files
committed
test: fix require-deps-deprecation for installed deps
Test test-require-deps-deprecation.js was failing when user already had node installed with acorn in require.resolve range. Modified test to acknowledge the possibility and throw only if acorn is found in the deps directory. Also changed the deprecation test for v9.x: common.expectWarning was failing because the required deps now throw ReferenceErrors when not properly called internally in the right order. PR-URL: nodejs#17848 Fixes: nodejs#17148 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3831d87 commit c341f93

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
// The v8 modules when imported leak globals. Disable global check.
6+
common.globalCheck = false;
7+
8+
const deprecatedModules = [
9+
'node-inspect/lib/_inspect',
10+
'node-inspect/lib/internal/inspect_client',
11+
'node-inspect/lib/internal/inspect_repl',
12+
'v8/tools/SourceMap',
13+
'v8/tools/codemap',
14+
'v8/tools/consarray',
15+
'v8/tools/csvparser',
16+
'v8/tools/logreader',
17+
'v8/tools/profile',
18+
'v8/tools/profile_view',
19+
'v8/tools/splaytree',
20+
'v8/tools/tickprocessor',
21+
'v8/tools/tickprocessor-driver'
22+
];
23+
24+
// Newly added deps that do not have a deprecation wrapper around it would
25+
// throw an error, but no warning would be emitted.
26+
const deps = [
27+
'acorn/dist/acorn',
28+
'acorn/dist/walk'
29+
];
30+
31+
const throwingModules = () => {
32+
for (const m of deprecatedModules) {
33+
require(m);
34+
}
35+
};
36+
37+
assert.throws(throwingModules, ReferenceError);
38+
39+
// Instead of checking require, check that resolve isn't pointing toward a
40+
// built-in module, as user might already have node installed with acorn in
41+
// require.resolve range.
42+
// Ref: https://github.com/nodejs/node/issues/17148
43+
for (const m of deps) {
44+
let path;
45+
try {
46+
path = require.resolve(m);
47+
} catch (err) {
48+
assert.ok(err.toString().startsWith('Error: Cannot find module '));
49+
continue;
50+
}
51+
assert.notStrictEqual(path, m);
52+
}

0 commit comments

Comments
 (0)