Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test: improve error message for policy failures
PR-URL: #35633
Fixes: #35600
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
bmeck authored and BethGriggs committed Dec 15, 2020
1 parent 0a944a4 commit 002005f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/common/README.md
Expand Up @@ -377,6 +377,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` [&lt;Function>][]
Expand Down
15 changes: 15 additions & 0 deletions test/common/index.js
Expand Up @@ -699,6 +699,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,
Expand Down Expand Up @@ -737,6 +751,7 @@ const common = {
platformTimeout,
printSkipMessage,
pwdCommand,
requireNoPackageJSONAbove,
runWithInvalidFD,
skip,
skipIf32Bits,
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-dependencies.js
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
common.requireNoPackageJSONAbove();

const fixtures = require('../common/fixtures');

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-dependency-conditions.js
Expand Up @@ -4,6 +4,7 @@
const common = require('../common');

if (!common.hasCrypto) common.skip('missing crypto');
common.requireNoPackageJSONAbove();

const Manifest = require('internal/policy/manifest').Manifest;

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-integrity-flag.js
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
common.requireNoPackageJSONAbove();

const fixtures = require('../common/fixtures');

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-parse-integrity.js
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-scopes-dependencies.js
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-scopes-integrity.js
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-scopes.js
Expand Up @@ -3,6 +3,7 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
common.requireNoPackageJSONAbove();

const fixtures = require('../common/fixtures');

Expand Down
1 change: 1 addition & 0 deletions test/pummel/test-policy-integrity.js
Expand Up @@ -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');
Expand Down

0 comments on commit 002005f

Please sign in to comment.