-
Notifications
You must be signed in to change notification settings - Fork 12
Align behavior of inheriting shell with Node.js' child_process API
#2447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc67328
Create an "assumptions" test suite
ericcornelissen aab14d9
Inherit `shell` value from `options` prototype on older Node.js versions
ericcornelissen ea779bf
Update compatibility test targets and developer documentation
ericcornelissen a90aa20
Update the Security Policy
ericcornelissen 70577a0
Update the changelog
ericcornelissen 2513f8e
minor
ericcornelissen 83d5e84
Disable ESLint rule `logical-assignment-operators`
ericcornelissen f5b7196
Merge branch 'main' into test-assumptions
ericcornelissen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,9 +143,12 @@ | |
| "test:integration": "npm run transpile && ava test/integration/**/*.test.js --timeout 2m", | ||
| "test:e2e": "node script/busybox-sh.js && node script/double-link-sh.js && ava test/e2e/**/*.test.js --timeout 1m", | ||
| "test:compat": "npm-run-all test:compat:*", | ||
| "test:compat:assumptions": "node test/compat/assumptions/runner.js", | ||
| "test:compat:assumptions:all": "nve 14.18.0,16.13.0,18.0.0,19.0.0,20.0.0,22.0.0,24.0.0,25.0.0 npm run test:compat:assumptions", | ||
| "test:compat:runtime": "node test/compat/runtime/runner.js", | ||
| "test:compat:runtime:all": "nve 14.18.0,16.13.0,18.0.0,19.0.0,20.0.0,22.0.0 npm run test:compat", | ||
| "test:compat:runtime:all": "nve 14.18.0,16.13.0,18.0.0,19.0.0,20.0.0,22.0.0,24.0.0,25.0.0 npm run test:compat:runtime", | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| "test:compat:regexp": "node --enable-experimental-regexp-engine test/compat/regexp-engine/runner.js", | ||
| "test:compat:regexp:all": "nve 16.13.0,18.0.0,19.0.0,20.0.0,22.0.0,24.0.0,25.0.0 npm run test:compat:regexp", | ||
| "test:breakage": "ava test/breakage/**/*.test.js", | ||
| "transpile": "npm-run-all transpile:*", | ||
| "transpile:cjs": "rollup --config config/rollup.js", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * @overview Contains tests for assumptions this library makes about the Node.js | ||
| * builtin module `node:child_process`. | ||
| * @license MIT | ||
| */ | ||
|
|
||
| import * as cp from "node:child_process"; | ||
| import * as process from "node:process"; | ||
|
|
||
| const nodeMajorVersion = process.versions.node.split(".")[0]; | ||
ericcornelissen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Test if the 'shell' value from the options prototype is used. | ||
ericcornelissen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @throws {Error} If the test fails. | ||
| */ | ||
| export function testShellInheritance() { | ||
| const command = "echo 'Hello world!'"; | ||
| const options = { | ||
| shell: "this is definitely not a real shell", | ||
| }; | ||
|
|
||
| let errOwn = false; | ||
| try { | ||
| cp.execSync(command, options); | ||
| } catch { | ||
| errOwn = true; | ||
| } | ||
|
|
||
| let errProto = false; | ||
| try { | ||
| Object.prototype.shell = options.shell; // eslint-disable-line no-extend-native | ||
| cp.execSync(command, {}); | ||
| } catch { | ||
| errProto = true; | ||
| } finally { | ||
| delete Object.prototype.shell; | ||
| } | ||
ericcornelissen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ( | ||
| (nodeMajorVersion >= 22 && errOwn === errProto) || | ||
| (nodeMajorVersion < 22 && errOwn !== errProto) | ||
| ) { | ||
| throw new Error(`own shell error ${errOwn}, proto shell error ${errProto}`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* eslint-disable ava/no-import-test-files */ | ||
|
|
||
| /** | ||
| * @overview The test runner for assumption compatibility tests. | ||
| * @license MIT | ||
| * | ||
| * This test suite intentionally doesn't use a test framework since the tests | ||
| * are required to run on old Node.js versions - which may not be supported by | ||
| * the test framework used - and the tests are relatively simple anyway. | ||
| * Instead, this minimal test runner is used, where execution just terminates | ||
| * early with a non-zero exit code when a test fails. | ||
| * | ||
| * This may be migrated to the Node.js' builtin testing library when that is | ||
| * available on the lowest Node.js version supported by the library. | ||
| */ | ||
|
|
||
| import * as cp from "./child-process.test.js"; | ||
|
|
||
| cp.testShellInheritance(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.