Add test for TextStream.ts

This commit is contained in:
Jerko Steiner 2019-10-31 15:14:02 -04:00
parent fe14691ac6
commit fc9d3b5b87
3 changed files with 40 additions and 11 deletions

View File

@ -0,0 +1,27 @@
import { TextStream } from './TextStream'
describe('TextStream', () => {
it('creates a text stream', async () => {
const stream = new TextStream('test')
const data = await new Promise((resolve, reject) => {
let text = ''
stream.on('error', reject)
stream.on('data', data => {
text += data.toString()
})
stream.on('end', () => {
resolve(text)
})
})
expect(data).toBe('test')
})
describe('_read', () => {
it('does nothing', () => {
const stream = new TextStream('test')
expect(stream._read()).toBe(undefined)
})
})
})

View File

@ -0,0 +1,11 @@
import { Readable } from 'stream'
export class TextStream extends Readable {
constructor(text: string) {
super()
this.push(text)
this.push(null)
}
_read() {/* noop */}
}

View File

@ -1,7 +1,7 @@
import { Request, Response } from 'express'
import { Readable } from 'stream'
import { run, ReadableProcess, ReadableWritable, Command } from './run'
import SVGCaptcha from 'svg-captcha'
import { Command, ReadableProcess, ReadableWritable, run } from './run'
import { TextStream } from './TextStream'
export interface AudioConfig {
commands: Command[]
@ -44,15 +44,6 @@ export async function speak(
return last
}
class TextStream extends Readable {
constructor(text: string) {
super()
this.push(text)
this.push(null)
}
_read() {/* noop */}
}
function createTextStream(text: string): ReadableProcess {
return {
stdout: new TextStream(text),