Skip to content

Commit

Permalink
test: fix require-deps-deprecation for installed deps
Browse files Browse the repository at this point in the history
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 <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>
  • Loading branch information
Tiriel authored and MylesBorins committed Feb 20, 2018
1 parent d89f310 commit b5752ee
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/parallel/test-require-deps-deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const common = require('../common');
const assert = require('assert');
// The v8 modules when imported leak globals. Disable global check.
common.globalCheck = false;

// Newly added deps that do not have a deprecation wrapper around it would
// throw an error, but no warning would be emitted.
const deps = [
'acorn/dist/acorn',
'acorn/dist/walk'
];

// Instead of checking require, check that resolve isn't pointing toward a
// built-in module, as user might already have node installed with acorn in
// require.resolve range.
// Ref: https://github.com/nodejs/node/issues/17148
for (const m of deps) {
let path;
try {
path = require.resolve(m);
} catch (err) {
assert.ok(err.toString().startsWith('Error: Cannot find module '));
continue;
}
assert.notStrictEqual(path, m);
}

0 comments on commit b5752ee

Please sign in to comment.