test('@taskr/prettier (defaults)', t => { t.plan(3); create({ *foo(f) { const tmp = tmpDir('tmp-1'); yield f.source(`${dir}/*.js`).prettier().target(tmp); const str = yield f.$.read(`${tmp}/foo.js`, 'utf8'); t.false(/\s\s/.test(str), 'truncated extra spaces'); t.false(/'/.test(str), 'converted single quotes'); t.true(/;/.test(str), 'added semicolons'); yield f.clear(tmp); } }).start('foo'); });
test("cli.list", t => { const file = require(taskpath) const rgx1 = /Available tasks/i const rgx2 = /task(A|B|C)/gm const rgx3 = /task-(a|b|c)/gm const out1 = log(() => cli.list(file)) const out2 = log(() => cli.list(file, true)) t.true(rgx1.test(out1), "includes spacing when `bare` is `false`") t.false(rgx1.test(out2), "minimizes output when `bare` is `true`") const arr1 = out1.match(rgx2) const arr2 = out2.match(rgx2) const arr3 = out1.match(rgx3) const arr4 = out2.match(rgx3) t.true(arr1 && arr2 && arr1.length === arr2.length, "lists all tasks, always") t.true(arr3 && arr4 && arr3.length === arr4.length, `lists all tasks" descriptions, always`) t.end() })
test("fn.isEmptyObj", t => { const fn = $.isEmptyObj const o1 = {} const o2 = {} // enumerable: false ~~> default Object.defineProperty(o1, "key", {value: "any"}) Object.defineProperty(o2, "key", { enumerable: true, value: "any" }) t.true(fn({}), `true: {}`) t.true(fn(new Object()), `true: new Object()`) t.false(fn({a: 1}), `false: {a: 1}`) t.false(fn([]), `false: []`) t.false(fn(new Function()), `false: new Function()`) t.false(fn(new Date()), `false: new Date()`) t.true(fn(o1), "true: valued object with `{enumerable: false}`") t.false(fn(o2), "false: valued object with `{enumerable: true}`") t.end() })
test("fn.isObject", t => { const fn = $.isObject t.true(fn({}), `true: {}`) t.true(fn({a: "a"}), `true: {a: "a"}`) t.true(fn(new Object()), `true: new Object`) t.true(fn(Object.assign({})), `true: Object.assign({})`) t.false(fn(), `false: blank`) t.false(fn([]), `false: []`) t.false(fn(null), `false: null`) t.false(fn(undefined), `false: undefined`) t.false(fn(15), `false: 15`) t.false(fn("Array"), `false: "Array"`) t.false(fn("Object"), `false: "Object"`) t.false(fn(function () {}), `false: function () {}`) t.false(fn(new Function()), `false: new Function`) t.false(fn(new Date()), `false: new Date`) t.false(fn(true), `false: true`) t.false(fn(false), `false: false`) t.end() })
test('@taskr/rev (rev)', t => { t.plan(4); create({ *foo(f) { const tmp = tmpDir('tmp-1'); yield f.source(glob).rev().target(tmp); t.false(yield f.$.find(`${tmp}/a.js`), 'rename the file'); t.true(yield f.$.find(`${tmp}/a-${hash1}.js`), 'generate content-based hash'); t.true(yield f.$.find(`${tmp}/b.svg`), 'ignore matching `opts.ignore` file types'); t.true(yield f.$.find(`${tmp}/sub/c-${hash2}.js`), 'rename sub-level files'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/unflow (defaults)', t => { t.plan(3); create({ *foo(f) { const tmp = tmpDir('tmp-1'); yield f.source(`${dir}/*.js`).unflow().target(tmp); // totals const arr = yield f.$.expand(`${tmp}/*.js`); t.equal(arr.length, 2, 'send all files to target'); // contents const str1 = yield f.$.read(`${tmp}/foo.js`, 'utf8'); const str2 = yield f.$.read(`${tmp}/bar.js`, 'utf8'); t.false(hasFlow(str1), 'remove flow evidence from `foo.js`'); t.false(hasFlow(str2), 'remove flow evidence from `bar.js`'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/unflow (all:false)', t => { t.plan(2); create({ *foo(f) { const tmp = tmpDir('tmp-2'); yield f.source(`${dir}/*.js`).unflow({ all:false }).target(tmp); const str1 = yield f.$.read(`${tmp}/foo.js`, 'utf8'); const str2 = yield f.$.read(`${tmp}/bar.js`, 'utf8'); t.false(hasFlow(str1), 'remove flow evidence from `foo.js`'); t.true(hasFlow(str2), 'keeps flow evidence within `bar.js`'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/prettier (defaults)', t => { t.plan(3); create({ *foo(f) { const tmp = tmpDir('tmp-1'); yield f.source(`${dir}/*.js`).prettier().target(tmp); const str = yield f.$.read(`${tmp}/foo.js`, 'utf8'); t.false(/\s\s/.test(str), 'truncated extra spaces'); t.false(/'/.test(str), 'converted single quotes'); t.true(/;/.test(str), 'added semicolons'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/rev (rev)', t => { t.plan(4); create({ *foo(f) { const tmp = tmpDir('tmp-1'); yield f.source(glob).rev().target(tmp); t.false(yield f.$.find(`${tmp}/a.js`), 'rename the file'); t.true(yield f.$.find(`${tmp}/a-${hash1}.js`), 'generate content-based hash'); t.true(yield f.$.find(`${tmp}/b.svg`), 'ignore matching `opts.ignore` file types'); t.true(yield f.$.find(`${tmp}/sub/c-${hash2}.js`), 'rename sub-level files'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/unflow (all:false)', t => { t.plan(2); create({ *foo(f) { const tmp = tmpDir('tmp-2'); yield f.source(`${dir}/*.js`).unflow({ all:false }).target(tmp); const str1 = yield f.$.read(`${tmp}/foo.js`, 'utf8'); const str2 = yield f.$.read(`${tmp}/bar.js`, 'utf8'); t.false(hasFlow(str1), 'remove flow evidence from `foo.js`'); t.true(hasFlow(str2), 'keeps flow evidence within `bar.js`'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/prettier (options)', t => { t.plan(3); create({ *foo(f) { const tmp = tmpDir('tmp-2'); yield f.source(`${dir}/*.js`).prettier({ singleQuote: true, semi: false }).target(tmp); const str = yield f.$.read(`${tmp}/foo.js`, 'utf8'); t.false(/\s\s/.test(str), 'truncated extra spaces'); t.false(/;/.test(str), 'turned off semicolons'); t.true(/'/.test(str), 'kept single quotes'); yield f.clear(tmp); } }).start('foo'); });
test("cli.list", t => { const file = require(taskpath) const rgx1 = /Available tasks/i const rgx2 = /task(A|B|C)/gm const rgx3 = /task-(a|b|c)/gm const out1 = log(() => cli.list(file)) const out2 = log(() => cli.list(file, true)) t.true(rgx1.test(out1), "includes spacing when `bare` is `false`") t.false(rgx1.test(out2), "minimizes output when `bare` is `true`") const arr1 = out1.match(rgx2) const arr2 = out2.match(rgx2) const arr3 = out1.match(rgx3) const arr4 = out2.match(rgx3) t.true(arr1 && arr2 && arr1.length === arr2.length, "lists all tasks, always") t.true(arr3 && arr4 && arr3.length === arr4.length, `lists all tasks" descriptions, always`) t.end() })
test("fn.isEmptyObj", t => { const fn = $.isEmptyObj const o1 = {} const o2 = {} // enumerable: false ~~> default Object.defineProperty(o1, "key", {value: "any"}) Object.defineProperty(o2, "key", { enumerable: true, value: "any" }) t.true(fn({}), `true: {}`) t.true(fn(new Object()), `true: new Object()`) t.false(fn({a: 1}), `false: {a: 1}`) t.false(fn([]), `false: []`) t.false(fn(new Function()), `false: new Function()`) t.false(fn(new Date()), `false: new Date()`) t.true(fn(o1), "true: valued object with `{enumerable: false}`") t.false(fn(o2), "false: valued object with `{enumerable: true}`") t.end() })
test('@taskr/prettier (options)', t => { t.plan(3); create({ *foo(f) { const tmp = tmpDir('tmp-2'); yield f.source(`${dir}/*.js`).prettier({ singleQuote: true, semi: false }).target(tmp); const str = yield f.$.read(`${tmp}/foo.js`, 'utf8'); t.false(/\s\s/.test(str), 'truncated extra spaces'); t.false(/;/.test(str), 'turned off semicolons'); t.true(/'/.test(str), 'kept single quotes'); yield f.clear(tmp); } }).start('foo'); });
test('@taskr/unflow (defaults)', t => { t.plan(3); create({ *foo(f) { const tmp = tmpDir('tmp-1'); yield f.source(`${dir}/*.js`).unflow().target(tmp); // totals const arr = yield f.$.expand(`${tmp}/*.js`); t.equal(arr.length, 2, 'send all files to target'); // contents const str1 = yield f.$.read(`${tmp}/foo.js`, 'utf8'); const str2 = yield f.$.read(`${tmp}/bar.js`, 'utf8'); t.false(hasFlow(str1), 'remove flow evidence from `foo.js`'); t.false(hasFlow(str2), 'remove flow evidence from `bar.js`'); yield f.clear(tmp); } }).start('foo'); });