exec.extra-argins.test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Module dependencies
  3. */
  4. var util = require('util');
  5. var assert = require('assert');
  6. var Machine = require('../');
  7. // ███████╗██╗ ██╗███████╗ ██████╗ ██╗██╗
  8. // ██╔════╝╚██╗██╔╝██╔════╝██╔════╝██╔╝╚██╗
  9. // █████╗ ╚███╔╝ █████╗ ██║ ██║ ██║
  10. // ██╔══╝ ██╔██╗ ██╔══╝ ██║ ██║ ██║
  11. // ██╗███████╗██╔╝ ██╗███████╗╚██████╗╚██╗██╔╝
  12. // ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝╚═╝
  13. //
  14. describe('Machine.prototype.exec()', function (){
  15. // ██╗ ██╗██╗████████╗██╗ ██╗ ███████╗██╗ ██╗████████╗██████╗ █████╗
  16. // ██║ ██║██║╚══██╔══╝██║ ██║ ██╔════╝╚██╗██╔╝╚══██╔══╝██╔══██╗██╔══██╗
  17. // ██║ █╗ ██║██║ ██║ ███████║ █████╗ ╚███╔╝ ██║ ██████╔╝███████║
  18. // ██║███╗██║██║ ██║ ██╔══██║ ██╔══╝ ██╔██╗ ██║ ██╔══██╗██╔══██║
  19. // ╚███╔███╔╝██║ ██║ ██║ ██║ ███████╗██╔╝ ██╗ ██║ ██║ ██║██║ ██║
  20. // ╚══╝╚══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝
  21. //
  22. // █████╗ ██████╗ ██████╗ ██╗███╗ ██╗███████╗
  23. // ██╔══██╗██╔══██╗██╔════╝ ██║████╗ ██║██╔════╝
  24. // ███████║██████╔╝██║ ███╗██║██╔██╗ ██║███████╗
  25. // ██╔══██║██╔══██╗██║ ██║██║██║╚██╗██║╚════██║
  26. // ██║ ██║██║ ██║╚██████╔╝██║██║ ╚████║███████║
  27. // ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝╚══════╝
  28. //
  29. // ██████╗ ██████╗ ██████╗ ██╗ ██╗██╗██████╗ ███████╗██████╗
  30. // ██╔══██╗██╔══██╗██╔═══██╗██║ ██║██║██╔══██╗██╔════╝██╔══██╗
  31. // ██████╔╝██████╔╝██║ ██║██║ ██║██║██║ ██║█████╗ ██║ ██║
  32. // ██╔═══╝ ██╔══██╗██║ ██║╚██╗ ██╔╝██║██║ ██║██╔══╝ ██║ ██║
  33. // ██║ ██║ ██║╚██████╔╝ ╚████╔╝ ██║██████╔╝███████╗██████╔╝
  34. // ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝╚═════╝ ╚══════╝╚═════╝
  35. //
  36. //
  37. describe('when extra configured argins are provided', function () {
  38. var NM_DEF_FIXTURE = {
  39. inputs: {
  40. foo: { example: 'wat', required: true }
  41. },
  42. fn: function (inputs, exits){
  43. exits.success();
  44. }
  45. };
  46. it('should throw a predictable error', function (){
  47. var m = Machine.build(NM_DEF_FIXTURE);
  48. try {
  49. m({ foo: 'bar', owl: 'hoot' }).exec(console.log);
  50. } catch (e) {
  51. if (e.code === 'E_USAGE') {
  52. return;
  53. }
  54. else { throw e; }
  55. }//</catch>
  56. });
  57. });//</describe :: when extra configured argins are provided>
  58. describe('when extra argins are provided with undefined values', function () {
  59. var NM_DEF_FIXTURE = {
  60. inputs: {
  61. foo: { example: 'wat', required: true }
  62. },
  63. fn: function (inputs, exits){
  64. exits.success('ok!');
  65. }
  66. };
  67. it('should throw a predictable error', function (){
  68. var m = Machine.build(NM_DEF_FIXTURE);
  69. var result;
  70. m({ foo: 'bar', owl: undefined }).exec(function(err, result){
  71. if (err) {throw new Error('Expected a successful run, but got: ' + util.inspect(err, {depth: null}));}
  72. assert.equal(result, 'ok!');
  73. });
  74. });
  75. });//</describe :: when extra configured argins are provided>
  76. });//</describe :: Machine.prototype.exec()>