Skip to content

Commit

Permalink
test: add delayed pipe() test
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Oct 2, 2024
1 parent 4cdef35 commit 6eb4c95
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('core', () => {
assert.equal(p.cmd, "echo $'#bar' --t 1")
})

test.only('stdio() works', async () => {
test('stdio() works', async () => {
let p = $`printf foo`
await p
// assert.throws(() => p.stdin)
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('core', () => {
'foo\n'
)

let r = $({ stdio: 'pipe' })`cat`
let r = $`cat`
fs.createReadStream('/tmp/output.txt').pipe(r.stdin)
assert.equal((await r).stdout, 'foo\n')
} finally {
Expand Down Expand Up @@ -384,20 +384,18 @@ describe('core', () => {
assert.equal(stdout, 'HELLO WORLD\n')
})

test.skip('throws if already resolved', async (t) => {
let ok = true
let p = $`echo "Hello"`
await p
try {
await p.pipe($`less`)
ok = false
} catch (err) {
assert.equal(
err.message,
`The pipe() method shouldn't be called after promise is already resolved!`
)
}
assert.ok(ok, 'Expected failure!')
it('supports multipiping', async () => {
const result = $`echo 1; sleep 1; echo 2; sleep 1; echo 3`
const piped1 = result.pipe`cat`
let piped2

setTimeout(() => {
piped2 = result.pipe`cat`
}, 1500)

await piped1
assert.equal((await piped1).toString(), '1\n2\n3\n')
assert.equal((await piped2).toString(), '1\n2\n3\n')
})

test('propagates rejection', async () => {
Expand Down

0 comments on commit 6eb4c95

Please sign in to comment.