Skip to content

Commit

Permalink
test: add ancestor package.json checks for tmpdir
Browse files Browse the repository at this point in the history
Policy tests can fail if a `package.json` exists in any of the parent
directories above the test. The existing checks are done for the
ancestors of the test directory but some tests execute from the tmpdir.

PR-URL: #38285
Refs: #38088
Refs: #35600
Refs: #35633
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
richardlau authored and targos committed Apr 29, 2021
1 parent 0e88ae7 commit 27d7588
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ const { spawn } = require('child_process');
spawn(...common.pwdCommand, { stdio: ['pipe'] });
```

### `requireNoPackageJSONAbove()`
### `requireNoPackageJSONAbove([dir])`

Throws an `AssertionError` if a `package.json` file is in any ancestor
directory. Such files may interfere with proper test functionality.
* `dir` [&lt;string>][] default = \_\_dirname

Throws an `AssertionError` if a `package.json` file exists in any ancestor
directory above `dir`. Such files may interfere with proper test functionality.

### `runWithInvalidFD(func)`

Expand Down
4 changes: 2 additions & 2 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ function gcUntil(name, condition) {
});
}

function requireNoPackageJSONAbove() {
let possiblePackage = path.join(__dirname, '..', 'package.json');
function requireNoPackageJSONAbove(dir = __dirname) {
let possiblePackage = path.join(dir, '..', 'package.json');
let lastPackage = null;
while (possiblePackage !== lastPackage) {
if (fs.existsSync(possiblePackage)) {
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 @@ -76,6 +76,7 @@ function newTestId() {
return nextTestId++;
}
tmpdir.refresh();
common.requireNoPackageJSONAbove(tmpdir.path);

let spawned = 0;
const toSpawn = [];
Expand Down

0 comments on commit 27d7588

Please sign in to comment.