Skip to content

Commit a9ff9c0

Browse files
richardlautargos
authored andcommitted
test: add ancestor package.json checks for tmpdir
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 <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2d96da8 commit a9ff9c0

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

test/common/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,12 @@ const { spawn } = require('child_process');
377377
spawn(...common.pwdCommand, { stdio: ['pipe'] });
378378
```
379379

380-
### `requireNoPackageJSONAbove()`
380+
### `requireNoPackageJSONAbove([dir])`
381381

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

385387
### `runWithInvalidFD(func)`
386388

test/common/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,8 @@ function gcUntil(name, condition) {
699699
});
700700
}
701701

702-
function requireNoPackageJSONAbove() {
703-
let possiblePackage = path.join(__dirname, '..', 'package.json');
702+
function requireNoPackageJSONAbove(dir = __dirname) {
703+
let possiblePackage = path.join(dir, '..', 'package.json');
704704
let lastPackage = null;
705705
while (possiblePackage !== lastPackage) {
706706
if (fs.existsSync(possiblePackage)) {

test/pummel/test-policy-integrity.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function newTestId() {
7676
return nextTestId++;
7777
}
7878
tmpdir.refresh();
79+
common.requireNoPackageJSONAbove(tmpdir.path);
7980

8081
let spawned = 0;
8182
const toSpawn = [];

0 commit comments

Comments
 (0)