Commit d717b2a
Changed files (2)
src
test
src/core.ts
@@ -192,6 +192,25 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
type Resolve = (out: ProcessOutput) => void
+export interface ProcessPromise extends Promise<ProcessOutput> {
+ then<R = ProcessOutput, E = ProcessOutput>(
+ onfulfilled?:
+ | ((value: ProcessOutput) => PromiseLike<R> | R)
+ | undefined
+ | null,
+ onrejected?:
+ | ((reason: ProcessOutput) => PromiseLike<E> | E)
+ | undefined
+ | null
+ ): Promise<R | E>
+ catch<T = ProcessOutput>(
+ onrejected?:
+ | ((reason: ProcessOutput) => PromiseLike<T> | T)
+ | undefined
+ | null
+ ): Promise<ProcessOutput | T>
+}
+
export class ProcessPromise extends Promise<ProcessOutput> {
private _command = ''
private _from = ''
@@ -520,32 +539,6 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this._nothrow ?? this._snapshot.nothrow
}
- // Promise API
- then<R = ProcessOutput, E = ProcessOutput>(
- onfulfilled?:
- | ((value: ProcessOutput) => PromiseLike<R> | R)
- | undefined
- | null,
- onrejected?:
- | ((reason: ProcessOutput) => PromiseLike<E> | E)
- | undefined
- | null
- ): Promise<R | E> {
- if (this.isHalted() && !this.child) {
- throw new Error('The process is halted!')
- }
- return super.then(onfulfilled, onrejected)
- }
-
- catch<T = ProcessOutput>(
- onrejected?:
- | ((reason: ProcessOutput) => PromiseLike<T> | T)
- | undefined
- | null
- ): Promise<ProcessOutput | T> {
- return super.catch(onrejected)
- }
-
// Stream-like API
private writable = true
private emit(event: string, ...args: any[]) {
test/core.test.js
@@ -633,18 +633,6 @@ describe('core', () => {
assert.ok(fs.existsSync(filepath), 'The cmd should have been called')
})
- test('await on halted throws', async () => {
- const p = $({ halt: true })`sleep 1`
- let ok = true
- try {
- await p
- ok = false
- } catch (err) {
- assert.equal(err.message, 'The process is halted!')
- }
- assert.ok(ok, 'Expected failure!')
- })
-
test('sync process ignores halt option', () => {
const p = $.sync({ halt: true })`echo foo`
assert.equal(p.stdout, 'foo\n')