mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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: https://github.com/nodejs/node/pull/38285 Refs: https://github.com/nodejs/node/issues/38088 Refs: https://github.com/nodejs/node/issues/35600 Refs: https://github.com/nodejs/node/pull/35633 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
4f11b8b8ae
commit
f9e07e432b
3 files changed
+8
-5
No files matched your search
@@ -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` [<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)`
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -76,6 +76,7 @@ function newTestId() {
|
||||
return nextTestId++;
|
||||
}
|
||||
tmpdir.refresh();
|
||||
common.requireNoPackageJSONAbove(tmpdir.path);
|
||||
|
||||
let spawned = 0;
|
||||
const toSpawn = [];
|
||||
|
||||
Reference in new issue
Block a user