hiredis_parser.js 813 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. var Parser = require('../lib/parser/hiredis').Parser;
  2. var assert = require('assert');
  3. /*
  4. This test makes sure that exceptions thrown inside of "reply" event handlers
  5. are not trapped and mistakenly emitted as parse errors.
  6. */
  7. (function testExecuteDoesNotCatchReplyCallbackExceptions() {
  8. var parser = new Parser();
  9. var replies = [{}];
  10. parser.reader = {
  11. feed: function() {},
  12. get: function() {
  13. return replies.shift();
  14. }
  15. };
  16. var emittedError = false;
  17. var caughtException = false;
  18. parser
  19. .on('error', function() {
  20. emittedError = true;
  21. })
  22. .on('reply', function() {
  23. throw new Error('bad');
  24. });
  25. try {
  26. parser.execute();
  27. } catch (err) {
  28. caughtException = true;
  29. }
  30. assert.equal(caughtException, true);
  31. assert.equal(emittedError, false);
  32. })();