task_base.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. let assert = require('assert');
  2. let h = require('./helpers');
  3. let exec = require('child_process').execSync;
  4. const PROJECT_DIR = process.env.PROJECT_DIR;
  5. const JAKE_CMD = `${PROJECT_DIR}/bin/cli.js`;
  6. suite('taskBase', function () {
  7. this.timeout(7000);
  8. test('default task', function () {
  9. let out;
  10. out = exec(`${JAKE_CMD} -q`).toString().trim();
  11. assert.equal(out, 'default task');
  12. out = exec(`${JAKE_CMD} -q default`).toString().trim();
  13. assert.equal(out, 'default task');
  14. });
  15. test('task with no action', function () {
  16. let out = exec(`${JAKE_CMD} -q noAction`).toString().trim();
  17. assert.equal(out, 'default task');
  18. });
  19. test('a task with no action and no prereqs', function () {
  20. exec(`${JAKE_CMD} noActionNoPrereqs`);
  21. });
  22. test('a task that exists at the top-level, and not in the specified namespace, should error', function () {
  23. let res = require('child_process').spawnSync(`${JAKE_CMD}`,
  24. ['asdfasdfasdf:zerbofrangazoomy']);
  25. let err = res.stderr.toString();
  26. assert.ok(err.indexOf('Unknown task' > -1));
  27. });
  28. test('passing args to a task', function () {
  29. let out = exec(`${JAKE_CMD} -q argsEnvVars[foo,bar]`).toString().trim();
  30. let parsed = h.parse(out);
  31. let args = parsed.args;
  32. assert.equal(args[0], 'foo');
  33. assert.equal(args[1], 'bar');
  34. });
  35. test('a task with environment vars', function () {
  36. let out = exec(`${JAKE_CMD} -q argsEnvVars foo=bar baz=qux`).toString().trim();
  37. let parsed = h.parse(out);
  38. let env = parsed.env;
  39. assert.equal(env.foo, 'bar');
  40. assert.equal(env.baz, 'qux');
  41. });
  42. test('passing args and using environment vars', function () {
  43. let out = exec(`${JAKE_CMD} -q argsEnvVars[foo,bar] foo=bar baz=qux`).toString().trim();
  44. let parsed = h.parse(out);
  45. let args = parsed.args;
  46. let env = parsed.env;
  47. assert.equal(args[0], 'foo');
  48. assert.equal(args[1], 'bar');
  49. assert.equal(env.foo, 'bar');
  50. assert.equal(env.baz, 'qux');
  51. });
  52. test('a simple prereq', function () {
  53. let out = exec(`${JAKE_CMD} -q foo:baz`).toString().trim();
  54. assert.equal(out, 'foo:bar task\nfoo:baz task');
  55. });
  56. test('a duplicate prereq only runs once', function () {
  57. let out = exec(`${JAKE_CMD} -q foo:asdf`).toString().trim();
  58. assert.equal(out, 'foo:bar task\nfoo:baz task\nfoo:asdf task');
  59. });
  60. test('a prereq with command-line args', function () {
  61. let out = exec(`${JAKE_CMD} -q foo:qux`).toString().trim();
  62. assert.equal(out, 'foo:bar[asdf,qwer] task\nfoo:qux task');
  63. });
  64. test('a prereq with args via invoke', function () {
  65. let out = exec(`${JAKE_CMD} -q foo:frang[zxcv,uiop]`).toString().trim();
  66. assert.equal(out, 'foo:bar[zxcv,uiop] task\nfoo:frang task');
  67. });
  68. test('a prereq with args via execute', function () {
  69. let out = exec(`${JAKE_CMD} -q foo:zerb[zxcv,uiop]`).toString().trim();
  70. assert.equal(out, 'foo:bar[zxcv,uiop] task\nfoo:zerb task');
  71. });
  72. test('repeating the task via execute', function () {
  73. let out = exec(`${JAKE_CMD} -q foo:voom`).toString().trim();
  74. assert.equal(out, 'foo:bar task\nfoo:bar task\ncomplete\ncomplete');
  75. });
  76. test('prereq execution-order', function () {
  77. let out = exec(`${JAKE_CMD} -q hoge:fuga`).toString().trim();
  78. assert.equal(out, 'hoge:hoge task\nhoge:piyo task\nhoge:fuga task');
  79. });
  80. test('basic async task', function () {
  81. let out = exec(`${JAKE_CMD} -q bar:bar`).toString().trim();
  82. assert.equal(out, 'bar:foo task\nbar:bar task');
  83. });
  84. test('promise async task', function () {
  85. let out = exec(`${JAKE_CMD} -q bar:dependOnpromise`).toString().trim();
  86. assert.equal(out, 'bar:promise task\nbar:dependOnpromise task saw value 123654');
  87. });
  88. test('failing promise async task', function () {
  89. try {
  90. exec(`${JAKE_CMD} -q bar:brokenPromise`);
  91. }
  92. catch(e) {
  93. assert(e.message.indexOf('Command failed') > -1);
  94. }
  95. });
  96. test('that current-prereq index gets reset', function () {
  97. let out = exec(`${JAKE_CMD} -q hoge:kira`).toString().trim();
  98. assert.equal(out, 'hoge:hoge task\nhoge:piyo task\nhoge:fuga task\n' +
  99. 'hoge:charan task\nhoge:gero task\nhoge:kira task');
  100. });
  101. test('modifying a task by adding prereq during execution', function () {
  102. let out = exec(`${JAKE_CMD} -q voom`).toString().trim();
  103. assert.equal(out, 2);
  104. });
  105. test('listening for task error-event', function () {
  106. try {
  107. exec(`${JAKE_CMD} -q vronk:groo`).toString().trim();
  108. }
  109. catch(e) {
  110. assert(e.message.indexOf('OMFGZONG') > -1);
  111. }
  112. });
  113. test('listening for jake error-event', function () {
  114. let out = exec(`${JAKE_CMD} -q throwy`).toString().trim();
  115. assert(out.indexOf('Emitted\nError: I am bad') > -1);
  116. });
  117. test('listening for jake unhandledRejection-event', function () {
  118. let out = exec(`${JAKE_CMD} -q promiseRejecter`).toString().trim();
  119. assert.equal(out, '<promise rejected on purpose>');
  120. });
  121. test('large number of same prereqs', function () {
  122. let out = exec(`${JAKE_CMD} -q large:same`).toString().trim();
  123. assert.equal(out, 'large:leaf\nlarge:same');
  124. });
  125. test('large number of different prereqs', function () {
  126. let out = exec(`${JAKE_CMD} -q large:different`).toString().trim();
  127. assert.equal(out, 'leaf-12\nleaf-123\nlarge:different');
  128. });
  129. test('large number of different prereqs', function () {
  130. let out = exec(`${JAKE_CMD} -q usingRequire:test`).toString().trim();
  131. assert.equal(out, 'howdy test');
  132. });
  133. test('modifying a namespace by adding a new task', function () {
  134. let out = exec(`${JAKE_CMD} -q one:two`).toString().trim();
  135. assert.equal('one:one\none:two', out);
  136. });
  137. });