test('fQuery.fn.then() returns this, is chainable', () => { const x = fQuery(); const y = x.then(); const z = y.then(); assert.equal(x, y); assert.equal(y, z); });
test('fQuery.fn.isPending() false for new object', () => { let x = fQuery(); assert.equal(x.isPending(), false); x = fQuery('test/assets/files-abc/*'); assert.equal(x.isPending(), false); });
test('fQuery.fn.select() non blob select', () => { const v = {}; const x = fQuery().select(v); assert.deep_equal(x._stack, [[], []]); assert.deep_equal(to_arr(x), []); assert.equal(x.length, 0); });
test('modulejs.log() two definitions with deps', () => { const modjs = modulejs.create(); modjs.define('a', {}); modjs.define('b', ['a'], {}); assert.equal(modjs.log(), '\n a -> [ ]\n b -> [ a ]\n'); assert.equal(modjs.log(true), '\n a -> [ b ]\n b -> [ ]\n'); });
test('ghor insp works', () => { const defs = { /* eslint-disable no-unused-vars */ a: ({b, c} = {}) => null, b: ({c} = {}) => null, c: null /* eslint-enable */ }; const exp = [ ['req', 'a', ['a']], ['ini', 'a'], ['req', 'b', ['a', 'b']], ['ini', 'b'], ['req', 'c', ['a', 'b', 'c']], ['ini', 'c'], ['res', 'c'], ['res', 'b'], ['req', 'c', ['a', 'c']], ['res', 'c'], ['res', 'a'] ]; const fn = spy(); const resolve = ghor(defs, fn); assert.deepEqual(fn.calls, []); resolve('a'); assert.deepEqual(fn.calls.map(call => call.args), exp); });
test('fQuery.fn.select() blob select', () => { const b = fQuery.Blob.fromPath('test/assets/files-abc/a'); const x = fQuery().select(b); assert.deep_equal(x._stack, [[b], []]); assert.deep_equal(to_arr(x), [b]); assert.equal(x.length, 1); });
test('fQuery.fn.select() non blob array select', () => { const v = [{}, 1, true, null, undefined, 'text']; const x = fQuery().select(v); assert.deep_equal(x._stack, [[], []]); assert.deep_equal(to_arr(x), []); assert.equal(x.length, 0); });
return target.run().then(() => { assert.is_true(fn1.calledOnce); assert.is_true(fn2.calledOnce); assert.is_true(fn3.calledOnce); assert.is_true(fn1.calledBefore(fn2)); assert.is_true(fn2.calledBefore(fn3)); });
test('Suite constructor without argument', () => { const suite = new Suite(); assert.inst_of(suite, Suite); assert.deepEqual(suite._targets, {}); assert.deepEqual(suite._defaults, []); assert.deepEqual(suite.args, {}); });
test('Target constructor without arguments', () => { const target = new Target(); assert.equal(target.name, 'unnamed'); assert.deepEqual(target.dependencies, []); assert.deepEqual(target.description, ''); assert.deepEqual(target._tasks, []); });
test('Target task() with arguments', () => { const obj = {}; const obj2 = {}; const target = new Target(); assert.deepEqual(target._tasks, []); assert.equal(target.task([obj, obj2]), target); assert.deepEqual(target._tasks, [new Task([obj, obj2])]); });
return suite.run('a', reporter).catch(() => { assert.is_true(reporter.beforeSuite.calledOnce); assert.is_false(reporter.afterSuite.called); assert.is_false(reporter.onError.called); assert.is_true(fna.calledOnce); assert.is_true(reporter.beforeSuite.calledBefore(fna)); });
test('fQuery.fn.select() multi blob array select', () => { const b1 = fQuery.Blob.fromPath('test/assets/files-abc/a'); const b2 = fQuery.Blob.fromPath('test/assets/files-abc/b'); const b3 = fQuery.Blob.fromPath('test/assets/files-abc/c'); const x = fQuery().select([b1, b2, b3]).select([b1]).select(b3); assert.deep_equal(x._stack, [[b3], [b1], [b1, b2, b3], []]); assert.deep_equal(to_arr(x), [b3]); assert.equal(x.length, 1); });
test('modulejs.log() in order of definition', () => { const modjs = modulejs.create(); modjs.define('c', {}); modjs.define('a', {}); modjs.define('d', ['c', 'b'], {}); modjs.define('b', ['a'], {}); assert.equal(modjs.log(), '\n c -> [ ]\n a -> [ ]\n d -> [ c, a, b ]\n b -> [ a ]\n'); assert.equal(modjs.log(true), '\n c -> [ d ]\n a -> [ d, b ]\n d -> [ ]\n b -> [ d ]\n'); });
test(`util.forOwn(${insp(x)}, fn)`, () => { const keys = Object.keys(x); const fn = spy(); assert.equal(util.forOwn(x, fn), undefined); assert.equal(fn.calls.length, keys.length); fn.calls.forEach((call, idx) => { assert.equal(call.args[1], keys[idx]); assert.equal(call.args[0], x[keys[idx]]); }); });
test('ghor runs function defs only once', () => { const obj = {}; const fn = spy(obj); const defs = {a: fn}; const resolve = ghor(defs); assert.equal(fn.calls.length, 0); assert.equal(resolve('a'), obj); assert.equal(fn.calls.length, 1); assert.equal(resolve('a'), obj); assert.equal(fn.calls.length, 1); });
test('Target constructor with arguments', () => { const obj1 = {}; const obj2 = {}; const obj3 = {}; const target = new Target(obj1, obj2, obj3); assert.equal(target.name, obj1); assert.equal(target.dependencies, obj2); assert.equal(target.description, obj3); assert.deepEqual(target._tasks, []); });
test('Suite target() sets arguments correct', () => { const obj1 = {}; const obj2 = {}; const obj3 = {}; const suite = new Suite(); const target = suite.target(obj1, obj2, obj3); assert.equal(target.name, obj1); assert.equal(target.dependencies, obj2); assert.equal(target.description, obj3); assert.deepEqual(target._tasks, []); });
test('ghor injects _resolve', () => { const defs = { a: ({_resolve} = {}) => _resolve }; const resolve = ghor(defs); assert.equal(resolve('a'), resolve); });
test('Mkr has the right properties', () => { assert.deepEqual(Object.keys(Mkr).sort(), [ 'run', 'clp', 'cli' ].sort()); });
test('fQuery.fn.select() only one prefix pro group allowed', () => { assert.throws( () => { fQuery().select('test/assets/files-abc: a, test: b'); } ); });
test('proc - file.nd', () => { const env = { PATH_TRANSLATED: 'test/assets/d.nd' }; const expected = readr('test/assets/d.txt'); assert.equal(proc(env), expected); });
test('Mkr clp() .clp(' + insp(arg) + ')', () => { if (Array.isArray(arg)) { arg.unshift('PRG'); arg.unshift('NODE'); } const res = Mkr.clp(arg); assert.deepEqual(res, exp); });
return new Promise(resolve => { const x = fQuery(); const after_then = () => { assert.equal(x.isPending(), false); resolve(); }; assert.equal(x.isPending(), false); x.then(() => { assert.equal(x.isPending(), true); setTimeout(after_then, 0); assert.equal(x.isPending(), true); }); assert.equal(x.isPending(), true); });
test('ghor resolves function definitions', () => { const obj = {}; const defs = { a: () => obj }; const resolve = ghor(defs); assert.equal(resolve('a'), obj); });
test('ghor resolves transitive', () => { const obj = {}; const defs = { a: ({b} = {}) => b, b: obj }; const resolve = ghor(defs); assert.equal(resolve('a'), obj); });
test('Suite run() throws on circular dependencies', () => { const fna = sinon.spy(); const fnb = sinon.spy(); const suite = new Suite(); suite.target('a', ['b']).task(fna); suite.target('b', ['a']).task(fnb); assert.throws(() => { return suite.run('b'); }, /circular dependencies/); });
test('ghor throws when no Proxy', () => { const bak = global.Proxy; global.Proxy = null; try { ghor({}); global.Proxy = bak; throw new Error('no error thrown'); } catch (err) { global.Proxy = bak; assert.equal(err.message, 'ghor-no-proxy'); } });
test('ghor throws for circular deps', () => { const defs = { /* eslint-disable no-unused-vars */ a: ({b} = {}) => null, b: ({a} = {}) => null /* eslint-enable */ }; const resolve = ghor(defs); assert.throws(() => { resolve('a'); }, /ghor-cycle: a > b > a/); });
test('core.format', () => { assert.equal(typeof format, 'object'); assert.deepEqual(Object.keys(format).sort(), ['setDefaultMetric', 'formatSize', 'setDefaultDateFormat', 'formatDate'].sort()); assert.equal(typeof format.setDefaultMetric, 'function'); assert.equal(typeof format.formatSize, 'function'); assert.equal(typeof format.setDefaultDateFormat, 'function'); assert.equal(typeof format.formatDate, 'function'); });