pedronauck / micro-router

:station: A tiny and functional router for Zeit's Micro

Home Page:https://www.npmjs.com/microrouter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The test of sending of stream, is badly constructed

11ume opened this issue · comments

Hi, this test line does not make sense, really what you are doing, is to test the behavior of microjs against a stream of data, not microrouter, the correct test would be like this:

test('route which sends a Stream', async (t) => {
    const readable = new Readable()
    const { methods, handler } = createRouter()
    const { post } = methods

    readable._read = () => {}
    readable.push('foo')
    readable.push(null)

    post('/stream', (req, res) => {
        let data = ''
        req.on('data', (chunk) => data += chunk)
        req.on('end', () => send(res, 200, data))
    })

    const url = await server(handler)
    // using node-fetch support ArrayBuffer | ArrayBufferView | NodeJS.ReadableStream, etc
    const response = await fetch(`${url}/stream`, {
        method: 'POST'
        , body: readable
    })

    t.is(await response.text(), 'foo')
  })` 

I realized this because I'm making my own routing system, based on yours.
Regards.