task_base.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. var assert = require('assert')
  2. , h = require('./helpers');
  3. var tests = {
  4. 'before': function () {
  5. process.chdir('./test');
  6. }
  7. , 'after': function () {
  8. process.chdir('../');
  9. }
  10. , 'test default task': function (next) {
  11. h.exec('../bin/cli.js', function (out) {
  12. assert.equal('default task', out);
  13. h.exec('../bin/cli.js default', function (out) {
  14. assert.equal('default task', out);
  15. next();
  16. });
  17. });
  18. }
  19. , 'test task with no action': function (next) {
  20. h.exec('../bin/cli.js noAction', function (out) {
  21. assert.equal('default task', out);
  22. next();
  23. });
  24. }
  25. , 'test a task with no action and no prereqs': function (next) {
  26. h.exec('../bin/cli.js noActionNoPrereqs', function () {
  27. next();
  28. });
  29. }
  30. , 'test passing args to a task': function (next) {
  31. h.exec('../bin/cli.js argsEnvVars[foo,bar]', function (out) {
  32. var parsed = h.parse(out)
  33. , args = parsed.args;
  34. assert.equal(args[0], 'foo');
  35. assert.equal(args[1], 'bar');
  36. next();
  37. });
  38. }
  39. , 'test a task with environment vars': function (next) {
  40. h.exec('../bin/cli.js argsEnvVars foo=bar baz=qux', function (out) {
  41. var parsed = h.parse(out)
  42. , env = parsed.env;
  43. assert.equal(env.foo, 'bar');
  44. assert.equal(env.baz, 'qux');
  45. next();
  46. });
  47. }
  48. , 'test passing args and using environment vars': function (next) {
  49. h.exec('../bin/cli.js argsEnvVars[foo,bar] foo=bar baz=qux', function (out) {
  50. var parsed = h.parse(out)
  51. , args = parsed.args
  52. , env = parsed.env;
  53. assert.equal(args[0], 'foo');
  54. assert.equal(args[1], 'bar');
  55. assert.equal(env.foo, 'bar');
  56. assert.equal(env.baz, 'qux');
  57. next();
  58. });
  59. }
  60. , 'test a simple prereq': function (next) {
  61. h.exec('../bin/cli.js foo:baz', function (out) {
  62. assert.equal('foo:bar task\nfoo:baz task', out);
  63. next();
  64. });
  65. }
  66. , 'test a duplicate prereq only runs once': function (next) {
  67. h.exec('../bin/cli.js foo:asdf', function (out) {
  68. assert.equal('foo:bar task\nfoo:baz task\nfoo:asdf task', out);
  69. next();
  70. });
  71. }
  72. , 'test a prereq with command-line args': function (next) {
  73. h.exec('../bin/cli.js foo:qux', function (out) {
  74. assert.equal('foo:bar[asdf,qwer] task\nfoo:qux task', out);
  75. next();
  76. });
  77. }
  78. , 'test a prereq with args via invoke': function (next) {
  79. h.exec('../bin/cli.js foo:frang[zxcv,uiop]', function (out) {
  80. assert.equal('foo:bar[zxcv,uiop] task\nfoo:frang task', out);
  81. next();
  82. });
  83. }
  84. , 'test a prereq with args via execute': function (next) {
  85. h.exec('../bin/cli.js foo:zerb[zxcv,uiop]', function (out) {
  86. assert.equal('foo:bar[zxcv,uiop] task\nfoo:zerb task', out);
  87. next();
  88. });
  89. }
  90. , 'test prereq execution-order': function (next) {
  91. h.exec('../bin/cli.js hoge:fuga', function (out) {
  92. assert.equal('hoge:hoge task\nhoge:piyo task\nhoge:fuga task', out);
  93. next();
  94. });
  95. }
  96. , 'test basic async task': function (next) {
  97. h.exec('../bin/cli.js bar:bar', function (out) {
  98. assert.equal('bar:foo task\nbar:bar task', out);
  99. next();
  100. });
  101. }
  102. , 'test promise async task': function (next) {
  103. h.exec('node ../bin/cli.js bar:dependOnpromise', function (out) {
  104. assert.equal('bar:promise task\nbar:dependOnpromise task saw value 123654', out);
  105. next();
  106. });
  107. }
  108. , 'test failing promise async task': function (next) {
  109. h.exec('node ../bin/cli.js bar:brokenPromise', {breakOnError:false}, function (out) {
  110. assert.equal(1, out.code);
  111. next();
  112. });
  113. }
  114. , 'test that current-prereq index gets reset': function (next) {
  115. h.exec('../bin/cli.js hoge:kira', function (out) {
  116. assert.equal('hoge:hoge task\nhoge:piyo task\nhoge:fuga task\n' +
  117. 'hoge:charan task\nhoge:gero task\nhoge:kira task', out);
  118. next();
  119. });
  120. }
  121. , 'test modifying a task by adding prereq during execution': function (next) {
  122. h.exec('../bin/cli.js voom', function (out) {
  123. assert.equal(2, out);
  124. next();
  125. });
  126. }
  127. , 'test listening for task error-event': function (next) {
  128. h.exec('../bin/cli.js vronk:groo', function (out) {
  129. assert.equal('OMFGZONG', out);
  130. next();
  131. });
  132. }
  133. , 'test listening for jake error-event': function (next) {
  134. h.exec('../bin/cli.js throwy', function (out) {
  135. assert.equal(out, 'Emitted: Error: I am bad');
  136. next();
  137. });
  138. }
  139. };
  140. module.exports = tests;