Skip to content

Commit

Permalink
test: improve error message for policy failures
Browse files Browse the repository at this point in the history
PR-URL: #35633
Fixes: #35600
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bmeck authored and danielleadams committed Nov 9, 2020
1 parent 36c20d9 commit f73b8d8
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
Original file line number Diff line number Diff line change
Expand Up @@ -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` [&lt;Function>][]
Expand Down
15 changes: 15 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -736,6 +750,7 @@ const common = {
platformTimeout,
printSkipMessage,
pwdCommand,
requireNoPackageJSONAbove,
runWithInvalidFD,
skip,
skipIf32Bits,
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-policy-dependencies.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 f73b8d8

Please sign in to comment.