Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve error message for policy failures #35633

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/common/README.md
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` [<Function>][]
Expand Down
15 changes: 15 additions & 0 deletions test/common/index.js
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
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