jimhigson / oboe.js

A streaming approach to JSON. Oboe.js speeds up web applications by providing parsed objects before the response completes.
http://jimhigson.github.io/oboe.js-website/index.html
Other
4.79k stars 208 forks source link

Issues testing stream #178

Open rfestag opened 6 years ago

rfestag commented 6 years ago

Oboe seems to not behave the same way in Jest when testEnvironment = node. I created a mock Readable class, which works fine when I simply run a test script with it. However, when I try to use it in a test, Oboe never seems to emit node events. You can find my test repo here:

https://github.com/rfestag/oboe-bug-template

To verify:

  1. Clone the repo and run npm install
  2. Try running the index.js: node index.js. It should produce the following lines: a. DATA . This is the result of the on('data') callback, so we know the mock is being read b. The array [1]. This is the payload we expect
  3. Try running the test npm test. It will block for 5 seconds and fail because done() wasn't called. You should see: a. The same DATA line as above, because the callback is exectued b. Note that the on('node') callback never seems to be executed, which causes it to fail.

Any idea why Oboe would behave differently in Jest running with the node testEnvironment? Is there a better way to mock this behavior so it is testable?

Aigeec commented 6 years ago

There is a know issue with Jest https://github.com/facebook/jest/issues/2549 where Jest clobber nodes globals. This causes as issue with Oboes duck typing of the node stream. I thought I raised an issue for it. Will take a look again if not. Really it's a problem with Jest.

A

On Fri 3 Aug 2018, 22:00 Ryan Festag, notifications@github.com wrote:

Oboe seems to not behave the same way in Jest when testEnvironment = node. I created a mock Readable class, which works fine when I simply run a test script with it. However, when I try to use it in a test, Oboe never seems to emit node events. You can find my test repo here:

https://github.com/rfestag/oboe-bug-template

To verify:

  1. Clone the repo and run npm install
  2. Try running the index.js: node index.js. It should produce the following lines: a. DATA . This is the result of the on('data') callback, so we know the mock is being read b. The array [1]. This is the payload we expect
  3. Try running the test npm test. It will block for 5 seconds and fail because done() wasn't called. You should see: a. The same DATA line as above, because the callback is exectued b. Note that the on('node') callback never seems to be executed, which causes it to fail.

Any idea why Oboe would behave differently in Jest running with the node testEnvironment? Is there a better way to mock this behavior so it is testable?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jimhigson/oboe.js/issues/178, or mute the thread https://github.com/notifications/unsubscribe-auth/AE207qRNaeTCIPMVpOXbaAG9NzMdFBqaks5uNLoFgaJpZM4Vum_M .