50 Commits

Author SHA1 Message Date
Nate Fischer
3149e09d5f refactor: explicit handling for execa errors
This adds a dedicated if-condition to handle internal errors from execa
(timeout, maxBuffer, etc.) and to distinguish these from "regular"
errors (the command executed, but it failed with non-zero status).
2025-04-17 13:52:12 -07:00
Nate Fischer
29eba085f7 refactor: prefer promises over test.cb
This is a followup to PR #1211 to use promises everywhere and migrate
away from `test.cb()`. The `test.cb()` function is removed in a future
version of ava.

I made an attempt to convert the skipped shell.cmd() async test cases,
but async functionality isn't implemented so it's possible the test
conversion is not totally correct.
2025-04-07 23:52:01 -07:00
Nate Fischer
ffdd60b3b6 refactor: use expectations for t.throws
No change to logic. This is a small refactor to use stricter
"expectation" arguments for calls to t.throws().
2025-04-07 23:29:18 -07:00
Nate Fischer
1a31356343 refactor: use require instead of import
No change to logic. This swaps over tests to use require() since
everything is currently designed for the commonjs module system.
2025-04-07 22:44:24 -07:00
Nate Fischer
519308489c refactor: move exec-child logic into main function
No change to logic. This refactors the exec-child.js script to move all
of its main logic into a main() function. This function is only invoked
if the script is executed, not when it is imported.

Importing the script is now a NOOP instead of throwing an exception.
It's still not advisable to import the script, however this can be done
if absolutely necessary to trick JavaScript bundlers which try to prune
non-imported code files.

Partially related to issue #1160 and #1172.
2025-02-20 00:32:19 -08:00
Murph Murphy
85dd4729dd
test: make a test more forgiving for systems with non-standard bash and sh paths (#1144)
Made a test
more forgiving so it passes on systems that have non-standard `bash` and
`sh` binary paths.
2023-12-06 22:48:30 -08:00
Nate Fischer
39ebb71846 test: add coverage for exit function
This adds test coverage for the shell.exit() function. This also
refactors how we mock stdout/stderr and adds support for mocking
process.exit() (which was needed for this change).

While I was writing these tests, I realized there was an edge case I
missed in PR #1122. This change fixes that edge case.

Issue #1013
2023-11-11 18:27:54 -08:00
JessieFrance
79ae14d30d
remove file extension (#1033) 2021-06-02 16:23:58 -07:00
Wes Cossick
4e38240eda Add boolean fatal option to exec() function (#961)
This PR introduces a new boolean fatal option for the exec() function. Like the existing silent option, this new option allows you to override the global fatal configuration parameter on a per-command basis.
2019-10-01 23:43:54 -07:00
Nate Fischer
e606706855
fix(exec): consistent error message for maxBuffer (#919)
* fix(exec): consistent error message for maxBuffer

This explicitly checks for maxBuffer errors in exec-child.js and
provides a consistent error message. This modifies the test to verify
this.

This also supports the change in Node v10, which emits this as a
RangeError instead of a regular Error.

Although the error message is now explicit, this is not part of our API,
since it's just tacked onto the end of exec's stderr.

Fixes #915

* Remove debugging log, ignore uncovered lines
2018-12-02 21:52:54 -08:00
Nate Fischer
2b3b781bbc
fix: silent exec (#892)
Unconditionally apply `silent: true` when calling `common.error()` from
`exec()`. This is because errors are already printed to stderr, or are
intentionally silenced by `shell.config.silent`.

Based on #861 

Fixes #851
2018-10-27 13:51:36 -07:00
Brandon Freitag
9077f4171e
Remove separate "internal error" from exec (#802)
* Remove separate "internal error" from exec

* Fix unknown command error regex

* Add message about command not found regex

* Silence errors while reading files in exec

The stdout and stderr files may never be opened or written to in certain
circumstances. In particular, if the timeout is short enough, the child
node process does not have enough time to start, and the child script
does not execute, so the files are not written to. So, catch errors form
trying to read the files, and ignore them.

* Do not silence errors due to short timeouts

* Simplify test regex for missing command

* Default error code to 1 if not set
2018-01-29 12:28:02 -08:00
Nate Fischer
9e3f9abd2a refactor(exec): move child process to source file (#786)
This PR refactors `shell.exec()` by putting its child process in a separate code
file. This also slightly cleans up dead code.

There's more potential to clean this up (e.g. exit status), but this is a good
enough start.

Issue #782
2017-10-19 13:19:52 -07:00
Nate Fischer
df1460ff53 chore: clean up refs to unsupported node versions (#779)
Also removes unnecessary guard code leftover from old versions.
2017-10-12 23:23:23 -07:00
Brandon Freitag
dcead1be86 Add "encoding" option to exec (#763)
* Add 'encoding' option to shell.exec

* Add 'encoding' option to docs

* Add exec encoding option tests

* Clarify use of encoding with fs.readFileSync

* Add check for stderr buffer
2017-09-13 16:18:28 -07:00
Nate Fischer
2ee83ebf74 refactor(test): update AVA and refactor tests (#760)
This updates tests for `AVA` 19.0.0+.

`AVA` 0.18.0 has a breaking change which changes the current working directory
for tests. As a result, we need to change 'resources' -> 'test/resources' (and
 similar path changes).

`AVA` 0.19.0 has a breaking change that all tests must run at least one assert.
This breaking change was already resolved by #746, so no change was necessary in
this PR.

This updates to `AVA` 0.21.0, since there are no other breaking changes.
2017-08-11 11:03:13 -07:00
Nate Fischer
38b57c8942 chore: add skipOnWin and skipOnUnix test helpers (#746)
This adds `skipOnWin` and `skipOnUnix` to help us manage our platform-dependent
tests. These methods give a nice warning message when we skip tests. We may also
consider adding warnings when running platform-dependent tests.

Part of the motivation for this is if we ever update to AVA v0.19. This version
requires at least one assertion per test case. While this could be disabled with
an AVA setting, we instead benefit from warnings for any case when we
unintentionally skip assertions.

This adds chalk as a dev dependency to enable colored messages.
2017-06-18 11:51:01 -07:00
Nate Fischer
5823ab18bb test(exec): add tests for coverage (#744)
* test(exec): add tests for coverage

No logic change.

This adds one test to cover some missing lines, and adds some `istanbul ignore`
directives.

I see 100% line coverage for `src/exec.js` when running:

```sh
$ nyc --reporter=text --reporter=lcov ava --serial test/exec.js`
```

Fixes #742

* Fix lint
2017-06-17 19:09:01 -07:00
Nate Fischer
f74e783890 chore: remove v0.12 and iojs support (#648)
Fixes #647
2017-06-06 21:10:27 -07:00
Nate Fischer
d8ac4d3f02 refactor: remove unnecessary common.js imports (#703)
No change in logic.

This removes unnecessary imports of `common.js` in favor of the `shell`
package.
2017-04-15 00:51:29 -07:00
Nate Fischer
4c48631d74 refactor: create common.execPath (#636)
Switch to using common.execPath instead of process.execPath directly and warn
electron users if we were unable to find the correct path to NodeJS.
2017-01-08 13:52:39 -08:00
Brandon Freitag
7fa4b995bf Finalize moving to ava (#630)
* Move ava-test/ directory to test/

* Remove unnecessary run-tests.js script

* Run only ava during npm test script
2016-12-20 11:27:02 -08:00
Nate Fischer
6b15577541 test: refactor exec tests to AVA (#574)
* test: refactor exec tests to AVA

* change single quotes to double quotes for Win
2016-11-30 21:14:49 -08:00
Nate Fischer
2395214fee chore: switch to eslint (#504)
* chore: switch to eslint

* fix: works on older versions of NodeJS now

* chore: fix curly braces

* chore: fix indents and remove jshint references
2016-08-07 12:16:29 -07:00
Nate Fischer
db20acebfb Switch to process.execPath over 'node' 2016-03-10 17:06:32 -08:00
Nate Fischer
6ebc2d3db7 refactor(shellstring): return consistent objects
- fix(string): no longer overrides string prototype
 - exec() now returns a ShellString object
2016-02-19 14:54:30 -08:00
Jason McLaurin
6bf7d77ecf change config.fatal to throw an exception instead of terminating the node.js process 2016-02-16 11:19:25 -06:00
Ari Porad
7531d3a0ee Merge pull request #354 from shelljs/fix-exec-temp-files
fix(exec): temp files are now cleaned up
2016-02-14 08:49:57 -08:00
Nate Fischer
b63dde5d1a fix(exec): now actually supports shell option 2016-02-13 20:45:32 -08:00
Nate Fischer
fed412ff1b fix(exec): temp files are now cleaned up 2016-02-11 15:20:32 -08:00
Nate Fischer
dc79d7eff0 fix(touch): enhance parseOptions and fix touch's -r flag 2016-02-04 15:41:48 -08:00
Nate Fischer
058bb679b0 feat(exec): allow all exec options to pass through 2016-02-03 20:54:41 -08:00
Nate Fischer
8a7f7ceec4 add exec.stdout
Change `exec.output` to `exec.stdout` and deprecate `output`.
2016-01-12 17:14:13 -08:00
Nate Fischer
74f1ff8748 Commands that have multiple errors now produce cleaner log output. Errors are
echoed to stderr. exec() supports a new stderr field.
2016-01-12 17:02:19 -08:00
Artur Adib
21f721cb45 more stringent jshint; catch leaks/undefs 2013-09-21 10:12:28 -04:00
Nils Bunger
d97c34627c Make shell.exec() treat process error return codes as shelljs errors 2013-09-08 17:16:08 -07:00
Deepak Thukral
7b9ee5a41d Kept existing options and re-wrote the test case. 2013-03-11 13:10:05 +01:00
Deepak Thukral
a91aa8cc9a exec with callback failed with slient param was defined 2013-03-11 12:30:44 +01:00
Artur Adib
35211d0783 Merge pull request #42 from danielepolencic/master
Fix single/double quotes in exec
2012-12-01 11:09:17 -08:00
Artur Adib
e4d9dabe52 introducing config.silent, config.fatal
deprecates silent()
2012-12-01 09:48:23 -05:00
Daniele Polencic
0409bd7a27 new test for quotes escaping 2012-11-13 09:52:53 +00:00
Artur Adib
99b9b759fa closes #31 2012-09-28 15:45:34 -04:00
Artur Adib
38a0bde0a9 exec async now returns child proc obj 2012-05-24 22:10:21 -04:00
Artur Adib
5c4f3609f3 oops 2012-04-16 11:03:35 -04:00
Artur Adib
44d9625326 test/exec.js: avoid intermittent failures 2012-04-16 11:02:23 -04:00
Artur Adib
94caeb20fd trying to fix async tests for exec() 2012-03-27 20:21:35 -04:00
Artur Adib
2f3bce71d1 echo() overrides silent() 2012-03-27 18:51:02 -04:00
Artur Adib
687e19044c fix: exec()'s {silent} overrides global silent() 2012-03-27 18:16:15 -04:00
Artur Adib
11614fd516 Deprecated: verbose() and exists() 2012-03-15 14:20:10 -04:00
Artur Adib
534c05dc25 exec() 2012-03-02 11:17:05 -05:00