Skip to content

Commit

Permalink
feat: define Symbol.toStringTag for ProcessOutput and `ProcessPro…
Browse files Browse the repository at this point in the history
…mise`

relates #1028
  • Loading branch information
antongolub committed Feb 23, 2025
1 parent 5f48c73 commit 147104a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
8 changes: 8 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this._stage
}

get [Symbol.toStringTag]() {
return 'ProcessPromise'
}

// Configurators
stdio(
stdin: IOType,
Expand Down Expand Up @@ -724,6 +728,10 @@ export class ProcessOutput extends Error {
return this._dto.duration
}

get [Symbol.toStringTag]() {
return 'ProcessOutput'
}

toString(): string {
return this.stdall
}
Expand Down
28 changes: 6 additions & 22 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ describe('core', () => {
assert.ok(p.exitCode instanceof Promise)
assert.ok(p.signal instanceof AbortSignal)
assert.equal(p.output, null)
assert.equal(Object.prototype.toString.call(p), '[object ProcessPromise]')

await p
assert.ok(p.output instanceof ProcessOutput)
Expand Down Expand Up @@ -907,10 +908,7 @@ describe('core', () => {
lines.push(line)
}

assert.equal(lines.length, 3, 'Should have 3 lines')
assert.equal(lines[0], 'Line1', 'First line should be "Line1"')
assert.equal(lines[1], 'Line2', 'Second line should be "Line2"')
assert.equal(lines[2], 'Line3', 'Third line should be "Line3"')
assert.deepEqual(lines, ['Line1', 'Line2', 'Line3'])
})

it('should handle partial lines correctly', async () => {
Expand All @@ -920,18 +918,7 @@ describe('core', () => {
lines.push(line)
}

assert.equal(lines.length, 3, 'Should have 3 lines')
assert.equal(
lines[0],
'PartialLine1',
'First line should be "PartialLine1"'
)
assert.equal(lines[1], 'Line2', 'Second line should be "Line2"')
assert.equal(
lines[2],
'PartialLine3',
'Third line should be "PartialLine3"'
)
assert.deepEqual(lines, ['PartialLine1', 'Line2', 'PartialLine3'])
})

it('should handle empty stdout', async () => {
Expand All @@ -951,12 +938,7 @@ describe('core', () => {
lines.push(line)
}

assert.equal(
lines.length,
1,
'Should have 1 line for single line without trailing newline'
)
assert.equal(lines[0], 'SingleLine', 'The line should be "SingleLine"')
assert.deepEqual(lines, ['SingleLine'])
})

it('should yield all buffered and new chunks when iterated after a delay', async () => {
Expand Down Expand Up @@ -1118,6 +1100,7 @@ describe('core', () => {
assert.equal(o.signal, 'SIGTERM')
assert.equal(o.exitCode, -1)
assert.equal(o.duration, 20)
assert.equal(Object.prototype.toString.call(o), '[object ProcessOutput]')
})

test('toString()', async () => {
Expand Down Expand Up @@ -1175,6 +1158,7 @@ describe('core', () => {
}
assert.deepEqual(lines, expected)
assert.deepEqual(o.lines(), expected)
assert.deepEqual([...o], expected) // isConcatSpreadable
})

describe('static', () => {
Expand Down

0 comments on commit 147104a

Please sign in to comment.