Skip to content

Commit 7138b05

Browse files
authored
fix: handle .nothrow() option in ProcessProcess[AsyncIterator] (#1217)
closes #1216
1 parent bd0ce19 commit 7138b05

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

.size-limit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
{
4646
"name": "all",
4747
"path": ["build/*", "man/*", "README.md", "LICENSE"],
48-
"limit": "872.6 kB",
48+
"limit": "872.65 kB",
4949
"brotli": false,
5050
"gzip": false
5151
}

build/core.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
806806
}
807807
}
808808
if (memo[0]) yield memo[0];
809+
if (this.isNothrow()) return;
809810
if ((yield new __await(this.exitCode)) !== 0) throw this._output;
810811
});
811812
}

src/core.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ export class ProcessPromise extends Promise<ProcessOutput> {
647647

648648
if (memo[0]) yield memo[0]
649649

650+
if (this.isNothrow()) return
651+
650652
if ((await this.exitCode) !== 0) throw this._output
651653
}
652654

test/core.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,14 @@ describe('core', () => {
10481048
'The process exit code should be 1'
10491049
)
10501050
})
1051+
1052+
it('handles .nothrow() correctly', async () => {
1053+
const data = []
1054+
for await (const line of $({ nothrow: true })`grep any test`) {
1055+
data.push(line)
1056+
}
1057+
assert.equal(data.length, 0, 'Should not yield any lines')
1058+
})
10511059
})
10521060

10531061
test('quiet() mode is working', async () => {
@@ -1083,8 +1091,10 @@ describe('core', () => {
10831091
})
10841092

10851093
test('nothrow() does not throw', async () => {
1086-
const { exitCode } = await $`exit 42`.nothrow()
1087-
assert.equal(exitCode, 42)
1094+
{
1095+
const { exitCode } = await $`exit 42`.nothrow()
1096+
assert.equal(exitCode, 42)
1097+
}
10881098
{
10891099
// Toggle
10901100
try {

0 commit comments

Comments
 (0)