Skip to content

Commit 27d7588

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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0e88ae7 commit 27d7588

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
@@ -370,10 +370,12 @@ const { spawn } = require('child_process');
370370
spawn(...common.pwdCommand, { stdio: ['pipe'] });
371371
```
372372

373-
### `requireNoPackageJSONAbove()`
373+
### `requireNoPackageJSONAbove([dir])`
374374

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

378380
### `runWithInvalidFD(func)`
379381

test/common/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,8 @@ function gcUntil(name, condition) {
708708
});
709709
}
710710

711-
function requireNoPackageJSONAbove() {
712-
let possiblePackage = path.join(__dirname, '..', 'package.json');
711+
function requireNoPackageJSONAbove(dir = __dirname) {
712+
let possiblePackage = path.join(dir, '..', 'package.json');
713713
let lastPackage = null;
714714
while (possiblePackage !== lastPackage) {
715715
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)