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