test('@taskr/clear: directory', co(function * (t) { t.plan(1); yield create({ * a(f) { const src = `${dir1}/foo`; yield f.$.write(src); yield f.clear(dir1); t.false(exists(src), 'directory was deleted'); } }).start('a'); }));
co(function * (o) { o = o || {}; const args = []; args.push.apply(args, arguments) && args.shift(); // grab alias to chosen source type const arr = this._[opts.files ? 'files' : 'globs']; // wrapper pass all arguments to plugin func const run = s => co(func).apply(this, [s, o].concat(args)); // loop thru EACH if `every`, else send full source array yield (opts.every ? Promise.all(arr.map(run)) : run(arr)); // send back instance allow chain return this; })
test("plugins.getDependencies", co(function* (t) { const out1 = plugs.getDependencies() t.true(Array.isArray(out1) && out1.length === 0, "via `null`; input returns an empty array") const pkg = yield plugs.getPackage(altDir) const out2 = plugs.getDependencies(pkg.data) t.true(Array.isArray(out2), "via dir; returns an array") t.equal(out2.length, 9, "via dir; find all the available dependencies") const out3 = plugs.getDependencies({}) t.true(Array.isArray(out3) && out3.length === 0, "via `{}`; returns an empty array") t.end() }))
co(function * (opts, func) { return yield wrapp(opts, func).call(this); })
test("Task.constructor (basic)", co(function * (t) { const taskr = new Taskr() const task = new Task(taskr) t.true($.isObject(task), "returns an object") protos.forEach(str => { t.true(task.hasOwnProperty(str), `Task.prototype.${str} is defined`) }) t.end() }))
test("plugins.getPackage", co(function* (t) { const out1 = yield plugs.getPackage(altDir) t.true($.isObject(out1), "returns an object") t.true("file" in out1 && "data" in out1, "object has `file` and `data` keys") t.equal(out1.file, pkgfile, "finds the correct `package.json` file") t.true($.isObject(out1.data), "the `object.data` is also an object") t.true("dependencies" in out1.data, "the `object.data` contains all `package.json` contents") // "fly" > "pkg" tests const subDir = join(altDir, "sub") const out2 = yield plugs.getPackage(subDir) t.equal(out2.file, pkgfile, "read `taskr.pkg` config to find alternate `package.json` file") t.end() }))
test("utils.read", co(function* (t) { const file = join(fixtures, "a.js") const out1 = yield $.read(file) const out2 = yield $.read(file, "utf8") const out3 = yield $.read(file, { encoding: "utf8" }) const out4 = yield $.read(fixtures) t.true(out1 instanceof Buffer, "returns a Buffer by default") t.equal(typeof out2, "string", "accepts `encoding` string as options") t.equal(typeof out3, "string", "accepts object as options") t.equal(out3, "const pi = 3.14\n", `reads file"s contents correctly`) t.true(out4 === null, "does not attempt to read directory paths") t.end() }))
test("plugins.load", co(function* (t) { // const out1 = yield plugs.load(join("/fake123", "taskfile.js")) // t.true(Array.isArray(out1) && out1.length === 0, "via invalid file returns an empty array") // ^^ logs error message to test disrupts formatting const out = yield plugs.load(taskfile) t.ok(Array.isArray(out), "returns an array") t.equal(out.length, 7, "filters down to fly|taskr plugins only") t.equal(typeof out[0], "function", "is an array of functions") t.equal(out[2], undefined, "returns `undefined` for faulty plugins") t.end() }))
test("utils.find", co(function* (t) { const file = "taskfile.js" const full = join(fixtures, file) const out1 = yield $.find(file, fixtures) t.true(out1.length && typeof out1 === "string", "if found returns a string") t.equal(out1, full, `via directory path finds the correct taskfile`) const out2 = yield $.find(full) t.equal(out2, full, `via file path finds the correct taskfile`) const out4 = yield $.find(file, "/fakedir123") t.equal(out4, null, "if not found returns `null`") t.end() }))
test('@taskr/clear: filepath array', co(function * (t) { t.plan(2); yield create({ * a(f) { const src1 = `${dir1}/foo`; const src2 = `${dir1}/bar`; yield f.$.write(src1); yield f.$.write(src2); yield f.clear([src1, src2]); t.false(exists(src1), 'file1 was deleted'); t.false(exists(src2), 'file2 was deleted'); } }).start('a'); }));
test("Task.constructor (plugins)", co(function * (t) { const taskr = new Taskr({ tasks: { *a(){} }, plugins: [{ name: "foo", *func(){} }] }) const task = new Task(taskr) t.true(task.hasOwnProperty("foo"), "inherits the `foo()` plugin") t.equal(typeof task.foo, "function", "mounts correctly as a function") t.end() }))
test("utils.write (options)", co(function * (t) { t.plan(1) const tmp = join(fixtures, ".tmp") const file = join(tmp, "bar.txt") yield $.write(file, "hello", {mode: 0o755}) const isExe = yield isMode(file, 755) t.true(isExe, "wrote an executable file") yield del(tmp) }))
test('@taskr/clear: filepath (task)', co(function * (t) { t.plan(2); yield create({ * a(f) { const src = `${dir1}/foo`; yield f.$.write(src); t.true('clear' in f, 'attach `clear` to task instance'); yield f.clear(src); t.false(exists(src), 'file was deleted'); } }).start('a'); }));
co(function * (o) { o = o || {}; const args = []; args.push.apply(args, arguments) && args.shift(); // grab alias to chosen source type const arr = this._[opts.files ? 'files' : 'globs']; // wrapper pass all arguments to plugin func const run = s => co(func).apply(this, [s, o].concat(args)); // loop thru EACH if `every`, else send full source array yield (opts.every ? Promise.all(arr.map(run)) : run(arr)); // send back instance allow chain return this; })