Skip to content

Commit b5752ee

Browse files
TirielMylesBorins
authored andcommitted
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. Bacport-PR-URL: #18077 PR-URL: #17848 Fixes: #17148 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d89f310 commit b5752ee

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
// Newly added deps that do not have a deprecation wrapper around it would
9+
// throw an error, but no warning would be emitted.
10+
const deps = [
11+
'acorn/dist/acorn',
12+
'acorn/dist/walk'
13+
];
14+
15+
// Instead of checking require, check that resolve isn't pointing toward a
16+
// built-in module, as user might already have node installed with acorn in
17+
// require.resolve range.
18+
// Ref: https://github.com/nodejs/node/issues/17148
19+
for (const m of deps) {
20+
let path;
21+
try {
22+
path = require.resolve(m);
23+
} catch (err) {
24+
assert.ok(err.toString().startsWith('Error: Cannot find module '));
25+
continue;
26+
}
27+
assert.notStrictEqual(path, m);
28+
}

0 commit comments

Comments
 (0)