Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The test of sending of stream, is badly constructed #56

Open
11ume opened this issue Dec 13, 2018 · 0 comments
Open

The test of sending of stream, is badly constructed #56

11ume opened this issue Dec 13, 2018 · 0 comments

Comments

@11ume
Copy link

11ume commented Dec 13, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant