Skip to content
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

feat: add ProcessPromise .verbose() for symmetry with.quiet() #820

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
private _stdio?: StdioOptions
private _nothrow?: boolean
private _quiet?: boolean
private _verbose?: boolean
private _timeout?: number
private _timeoutSignal = 'SIGTERM'
private _resolved = false
Expand Down Expand Up @@ -487,8 +488,13 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this
}

quiet(): ProcessPromise {
this._quiet = true
quiet(v = true): ProcessPromise {
this._quiet = v
return this
}

verbose(v = true): ProcessPromise {
this._verbose = v
return this
}

Expand All @@ -497,7 +503,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
}

isVerbose(): boolean {
return this._snapshot.verbose && !this.isQuiet()
return (this._verbose ?? this._snapshot.verbose) && !this.isQuiet()
}

timeout(d: Duration, signal = 'SIGTERM'): ProcessPromise {
Expand Down
11 changes: 11 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ describe('core', () => {
}
})

test('verbose() mode is working', async () => {
const p = $`echo 'test'`
assert.equal(p.isVerbose(), false)

p.verbose()
assert.equal(p.isVerbose(), true)

p.verbose(false)
assert.equal(p.isVerbose(), false)
})

test('nothrow() do not throw', async () => {
let { exitCode } = await $`exit 42`.nothrow()
assert.equal(exitCode, 42)
Expand Down