maxRecursion.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Module dependencies
  3. */
  4. var Machine = require('../');
  5. xdescribe('maxRecursion', function (){
  6. describe('by default', function (){
  7. var machineInstance;
  8. before(function (){
  9. machineInstance = Machine.build(function horribleEndlesslyRecursingMachine(inputs, exits, env){
  10. var recursiveMachine = env.thisMachine();
  11. // console.log('Calling self. Max recursion:', recursiveMachine.maxRecursion);
  12. // console.log('Current recursion depth:', recursiveMachine._recursiveDepth);
  13. recursiveMachine.exec({
  14. error: function (err){
  15. return exits.error(err);
  16. },
  17. success: function (){
  18. return exits.success();
  19. }
  20. });
  21. });
  22. });
  23. it('should prevent "maximum call stack exceeded" errors by default', function (done){
  24. machineInstance().exec({
  25. error: function (err) {
  26. if (err.code === 'E_MAX_RECURSION') {
  27. return done();
  28. }
  29. return done(new Error('Expecting Error instance w/ `code` === "E_MAX_RECURSION", but instead got this error (code:'+err.code+'): '+err.stack));
  30. },
  31. success: function (){
  32. return done(new Error('wtf'));
  33. }
  34. });
  35. });
  36. });
  37. });