Add test for TextStream.ts
This commit is contained in:
parent
fe14691ac6
commit
fc9d3b5b87
27
packages/captcha/src/TextStream.test.ts
Normal file
27
packages/captcha/src/TextStream.test.ts
Normal 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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
11
packages/captcha/src/TextStream.ts
Normal file
11
packages/captcha/src/TextStream.ts
Normal 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 */}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import { Request, Response } from 'express'
|
import { Request, Response } from 'express'
|
||||||
import { Readable } from 'stream'
|
|
||||||
import { run, ReadableProcess, ReadableWritable, Command } from './run'
|
|
||||||
import SVGCaptcha from 'svg-captcha'
|
import SVGCaptcha from 'svg-captcha'
|
||||||
|
import { Command, ReadableProcess, ReadableWritable, run } from './run'
|
||||||
|
import { TextStream } from './TextStream'
|
||||||
|
|
||||||
export interface AudioConfig {
|
export interface AudioConfig {
|
||||||
commands: Command[]
|
commands: Command[]
|
||||||
@ -44,15 +44,6 @@ export async function speak(
|
|||||||
return last
|
return last
|
||||||
}
|
}
|
||||||
|
|
||||||
class TextStream extends Readable {
|
|
||||||
constructor(text: string) {
|
|
||||||
super()
|
|
||||||
this.push(text)
|
|
||||||
this.push(null)
|
|
||||||
}
|
|
||||||
_read() {/* noop */}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTextStream(text: string): ReadableProcess {
|
function createTextStream(text: string): ReadableProcess {
|
||||||
return {
|
return {
|
||||||
stdout: new TextStream(text),
|
stdout: new TextStream(text),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user