mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
test: improve error message for policy failures
PR-URL: https://github.com/nodejs/node/pull/35633 Fixes: https://github.com/nodejs/node/issues/35600 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
caa5a0516e
commit
5b95f01284
10 files changed
+28
No files matched your search
@@ -378,6 +378,11 @@ const { spawn } = require('child_process');
|
||||
spawn(...common.pwdCommand, { stdio: ['pipe'] });
|
||||
```
|
||||
|
||||
### `requireNoPackageJSONAbove()`
|
||||
|
||||
Throws an `AssertionError` if a `package.json` file is in any ancestor
|
||||
directory. Such files may interfere with proper test functionality.
|
||||
|
||||
### `runWithInvalidFD(func)`
|
||||
|
||||
* `func` [<Function>][]
|
||||
|
||||
@@ -697,6 +697,20 @@ function gcUntil(name, condition) {
|
||||
});
|
||||
}
|
||||
|
||||
function requireNoPackageJSONAbove() {
|
||||
let possiblePackage = path.join(__dirname, '..', 'package.json');
|
||||
let lastPackage = null;
|
||||
while (possiblePackage !== lastPackage) {
|
||||
if (fs.existsSync(possiblePackage)) {
|
||||
assert.fail(
|
||||
'This test shouldn\'t load properties from a package.json above ' +
|
||||
`its file location. Found package.json at ${possiblePackage}.`);
|
||||
}
|
||||
lastPackage = possiblePackage;
|
||||
possiblePackage = path.join(possiblePackage, '..', '..', 'package.json');
|
||||
}
|
||||
}
|
||||
|
||||
const common = {
|
||||
allowGlobals,
|
||||
buildType,
|
||||
@@ -736,6 +750,7 @@ const common = {
|
||||
platformTimeout,
|
||||
printSkipMessage,
|
||||
pwdCommand,
|
||||
requireNoPackageJSONAbove,
|
||||
runWithInvalidFD,
|
||||
skip,
|
||||
skipIf32Bits,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
const common = require('../common');
|
||||
|
||||
if (!common.hasCrypto) common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const Manifest = require('internal/policy/manifest').Manifest;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto) common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
const assert = require('assert');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
const common = require('../common');
|
||||
|
||||
if (!common.hasCrypto) common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const Manifest = require('internal/policy/manifest').Manifest;
|
||||
const assert = require('assert');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
const common = require('../common');
|
||||
|
||||
if (!common.hasCrypto) common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const Manifest = require('internal/policy/manifest').Manifest;
|
||||
const assert = require('assert');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto) common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const { debuglog } = require('util');
|
||||
const debug = debuglog('test');
|
||||
|
||||
Reference in new issue
Block a user