Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f73b8d8

Browse filesBrowse files
bmeckdanielleadams
authored andcommitted
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>
1 parent 36c20d9 commit f73b8d8
Copy full SHA for f73b8d8
Expand file treeCollapse file tree

10 files changed

+28
-0
lines changed
Open diff view settings
Collapse file

‎test/common/README.md‎

Copy file name to clipboardExpand all lines: test/common/README.md
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ const { spawn } = require('child_process');
378378
spawn(...common.pwdCommand, { stdio: ['pipe'] });
379379
```
380380

381+
### `requireNoPackageJSONAbove()`
382+
383+
Throws an `AssertionError` if a `package.json` file is in any ancestor
384+
directory. Such files may interfere with proper test functionality.
385+
381386
### `runWithInvalidFD(func)`
382387

383388
* `func` [&lt;Function>][]
Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,20 @@ function gcUntil(name, condition) {
697697
});
698698
}
699699

700+
function requireNoPackageJSONAbove() {
701+
let possiblePackage = path.join(__dirname, '..', 'package.json');
702+
let lastPackage = null;
703+
while (possiblePackage !== lastPackage) {
704+
if (fs.existsSync(possiblePackage)) {
705+
assert.fail(
706+
'This test shouldn\'t load properties from a package.json above ' +
707+
`its file location. Found package.json at ${possiblePackage}.`);
708+
}
709+
lastPackage = possiblePackage;
710+
possiblePackage = path.join(possiblePackage, '..', '..', 'package.json');
711+
}
712+
}
713+
700714
const common = {
701715
allowGlobals,
702716
buildType,
@@ -736,6 +750,7 @@ const common = {
736750
platformTimeout,
737751
printSkipMessage,
738752
pwdCommand,
753+
requireNoPackageJSONAbove,
739754
runWithInvalidFD,
740755
skip,
741756
skipIf32Bits,
Collapse file

‎test/parallel/test-policy-dependencies.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-dependencies.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6+
common.requireNoPackageJSONAbove();
67

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

Collapse file

‎test/parallel/test-policy-dependency-conditions.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-dependency-conditions.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const common = require('../common');
55

66
if (!common.hasCrypto) common.skip('missing crypto');
7+
common.requireNoPackageJSONAbove();
78

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

Collapse file

‎test/parallel/test-policy-integrity-flag.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-integrity-flag.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6+
common.requireNoPackageJSONAbove();
67

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

Collapse file

‎test/parallel/test-policy-parse-integrity.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-parse-integrity.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const common = require('../common');
44
if (!common.hasCrypto) common.skip('missing crypto');
5+
common.requireNoPackageJSONAbove();
56

67
const tmpdir = require('../common/tmpdir');
78
const assert = require('assert');
Collapse file

‎test/parallel/test-policy-scopes-dependencies.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-scopes-dependencies.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const common = require('../common');
55

66
if (!common.hasCrypto) common.skip('missing crypto');
7+
common.requireNoPackageJSONAbove();
78

89
const Manifest = require('internal/policy/manifest').Manifest;
910
const assert = require('assert');
Collapse file

‎test/parallel/test-policy-scopes-integrity.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-scopes-integrity.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const common = require('../common');
55

66
if (!common.hasCrypto) common.skip('missing crypto');
7+
common.requireNoPackageJSONAbove();
78

89
const Manifest = require('internal/policy/manifest').Manifest;
910
const assert = require('assert');
Collapse file

‎test/parallel/test-policy-scopes.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-policy-scopes.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const common = require('../common');
44
if (!common.hasCrypto)
55
common.skip('missing crypto');
6+
common.requireNoPackageJSONAbove();
67

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

Collapse file

‎test/pummel/test-policy-integrity.js‎

Copy file name to clipboardExpand all lines: test/pummel/test-policy-integrity.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const common = require('../common');
44
if (!common.hasCrypto) common.skip('missing crypto');
5+
common.requireNoPackageJSONAbove();
56

67
const { debuglog } = require('util');
78
const debug = debuglog('test');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.