diff --git a/README.md b/README.md index 95c516d..5c1add8 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ From the Irish ordú: [instruction](http://www.focloir.ie/en/dictionary/ei ## License -Copyright (c) 2014-2016, Seamus D'Arcy and other contributors. +Copyright (c) 2014-2020, Richard Rodger and other contributors. Licensed under [MIT][]. [MIT]: ./LICENSE diff --git a/package-lock.json b/package-lock.json index e7ca617..bb9966d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ordu", - "version": "1.7.1", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6125120..2744120 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ordu", - "version": "1.7.1", + "version": "2.0.0", "main": "dist/ordu.js", "browser": "dist/ordu.min.js", "types": "dist/ordu.d.ts", diff --git a/test-web/test-web.js b/test-web/test-web.js index 16647e3..fe58c2c 100644 --- a/test-web/test-web.js +++ b/test-web/test-web.js @@ -2230,181 +2230,173 @@ var describe = lab.describe var it = lab.it var expect = Code.expect -describe('ordu', function() { +describe('ordu', function () { it('sanity', async () => { var h0 = new Ordu() expect(h0).exists() }) - + it('happy', async () => { var h0 = new Ordu() var taskresult_log = [] var taskend_log = [] - h0.on('task-result', (tr)=>{ + h0.on('task-result', (tr) => { taskresult_log.push(tr) }) - h0.on('task-end', (ev)=>{ + h0.on('task-end', (ev) => { taskend_log.push(ev) }) - h0.add({ name: 'A', from: 'my-ref-01', meta: { - from: {foo:1} - } + from: { foo: 1 }, + }, }) h0.add({ name: 'B', - active: false + active: false, }) h0.add({ exec: (spec) => { - if(spec.ctx.err0) { + if (spec.ctx.err0) { throw new Error('err0') } - if(spec.ctx.err2) { - return {op:'not-an-op'} + if (spec.ctx.err2) { + return { op: 'not-an-op' } } return null - } + }, }) - h0.add({ id: '0', exec: () => ({ op: 'merge', out: { - x:2 + x: 2, }, - why: 'some-reason' - }) + why: 'some-reason', + }), }) h0.add({ if: { x: 4, - xx: 40 + xx: 40, }, exec: () => ({ op: 'merge', out: { - q: 1 - } - }) + q: 1, + }, + }), }) - h0.add({ name: 'a', - exec: async() => { - return new Promise((r)=>setTimeout(()=>{r({ - op: 'merge' - // out missing! - })},10)) - } + exec: async () => { + return new Promise((r) => + setTimeout(() => { + r({ + op: 'merge', + // out missing! + }) + }, 10) + ) + }, }) - h0.add( - function b() { - return { - op: 'merge', - out: { - x:4 - } - } + h0.add(function b() { + return { + op: 'merge', + out: { + x: 4, + }, } - ) + }) - h0.add( - function c() { - return { - op: 'lookup', - out: { - id:'001' - } - } + h0.add(function c() { + return { + op: 'lookup', + out: { + id: '001', + }, } - ) + }) - - h0 - .add({ - if: { - 'x': 4 + h0.add({ + if: { + x: 4, + }, + exec: () => ({ + op: 'merge', + out: { + qq: 2, }, - exec: () => ({ - op: 'merge', - out: { - qq: 2 - } - }) - }) - .add({ - exec: () => ({ - op: 'stop', - out: { - last: 99 - } - }) - }) - + }), + }).add({ + exec: () => ({ + op: 'stop', + out: { + last: 99, + }, + }), + }) h0.add({ exec: () => ({ op: 'merge', out: { - 'should-never-be-reached': true - } - }) + 'should-never-be-reached': true, + }, + }), }) + h0.add(() => {}) + + expect( + Object.keys(h0.task).map( + (tn) => tn + '~' + ('function' === typeof h0.task[tn].exec) + ) + ).equal([ + 'A~true', + 'B~true', + 'task0~true', + 'task1~true', + 'task2~true', + 'a~true', + 'b~true', + 'c~true', + 'task3~true', + 'task4~true', + 'task5~true', + 'task6~true', + ]) - h0.add(()=>{}) - - expect(Object.keys(h0.task) - .map(tn=>tn+'~'+('function'===typeof(h0.task[tn].exec)))) - .equal([ - 'A~true', - 'B~true', - 'task0~true', - 'task1~true', - 'task2~true', - 'a~true', - 'b~true', - 'c~true', - 'task3~true', - 'task4~true', - 'task5~true', - 'task6~true' - ]) - - h0.operator('lookup', async (tr, ctx, data) => { - if(ctx.err1) throw new Error('err1') + if (ctx.err1) throw new Error('err1') - return new Promise((r)=>{ - setTimeout(()=>{ + return new Promise((r) => { + setTimeout(() => { data.y = tr.out - r({stop:false}) - },10) + r({ stop: false }) + }, 10) }) }) - h0.operator(function does_nothing(tr, ctx, data) { - return {stop:false} + return { stop: false } }) - + //console.log(h0.tasks()) expect(h0.tasks().length).equal(12) - + var out = await h0.exec() expect(out.data).equal({ x: 4, y: { id: '001' }, qq: 2, last: 99 }) expect(out.task_count).equal(8) @@ -2413,51 +2405,53 @@ describe('ordu', function() { //console.dir(taskresult_log, {depth:null}) //console.dir(taskend_log, {depth:null}) - expect(taskresult_log.map(te=>te.name+'~'+te.op)).equal([ - 'A~next', - 'B~skip', - 'task0~next', - 'task1~merge', - 'task2~skip', - 'a~merge', - 'b~merge', - 'c~lookup', - 'task3~merge', - 'task4~stop' + expect(taskresult_log.map((te) => te.name + '~' + te.op)).equal([ + 'A~next', + 'B~skip', + 'task0~next', + 'task1~merge', + 'task2~skip', + 'a~merge', + 'b~merge', + 'c~lookup', + 'task3~merge', + 'task4~stop', ]) - expect(taskend_log.map(te=>te.name+'~'+te.op+'~'+te.operate.stop)).equal([ - 'A~next~false', - 'B~skip~false', - 'task0~next~false', - 'task1~merge~false', - 'task2~skip~false', - 'a~merge~false', - 'b~merge~false', - 'c~lookup~false', - 'task3~merge~false', - 'task4~stop~true' + expect( + taskend_log.map((te) => te.name + '~' + te.op + '~' + te.operate.stop) + ).equal([ + 'A~next~false', + 'B~skip~false', + 'task0~next~false', + 'task1~merge~false', + 'task2~skip~false', + 'a~merge~false', + 'b~merge~false', + 'c~lookup~false', + 'task3~merge~false', + 'task4~stop~true', ]) - - - - out = await h0.exec({},{z:1, y: null}) + out = await h0.exec({}, { z: 1, y: null }) expect(out.data).equal({ z: 1, x: 4, y: { id: '001' }, qq: 2, last: 99 }) expect(out.task_count).equal(8) expect(out.task_total).equal(12) - - out = await h0.exec({err0:true},{z:2}) + out = await h0.exec({ err0: true }, { z: 2 }) //console.log(out) expect(out.err.message).equal('err0') - var operators = h0.operators() expect(Object.keys(operators)).equal([ - 'next','skip','stop','merge','lookup', 'does_nothing' + 'next', + 'skip', + 'stop', + 'merge', + 'lookup', + 'does_nothing', ]) - expect(h0.tasks().map(t=>t.name)).equals([ + expect(h0.tasks().map((t) => t.name)).equals([ 'A', 'B', 'task0', @@ -2469,89 +2463,92 @@ describe('ordu', function() { 'task3', 'task4', 'task5', - 'task6' + 'task6', ]) - - out = await h0.exec({err1:true},null,{runid:'foo'}) + out = await h0.exec({ err1: true }, null, { runid: 'foo' }) //console.log(out) expect(out.err.message).equal('err1') - - out = await h0.exec({err2:true},void 0,{done:(res)=>{ - expect(res.err.message).equal('Unknown operation: not-an-op') - }}) + out = await h0.exec({ err2: true }, void 0, { + done: (res) => { + expect(res.err.message).equal('Unknown operation: not-an-op') + }, + }) expect(out.err.message).equal('Unknown operation: not-an-op') - }) - it('async', async ()=>{ - var h0 = new Ordu({debug:true}) + it('async', async () => { + var h0 = new Ordu({ debug: true }) var taskresult_log = [] var taskend_log = [] - h0.on('task-result', (tr)=>{ + h0.on('task-result', (tr) => { taskresult_log.push(tr) }) - h0.on('task-end', (ev)=>{ + h0.on('task-end', (ev) => { taskend_log.push(ev) }) function foo() { - return {op:'merge', out:{foo:1}} + return { op: 'merge', out: { foo: 1 } } } function bar() { - return new Promise(r=>setTimeout(()=>r({op:'merge', out:{bar:1}}),10)) + return new Promise((r) => + setTimeout(() => r({ op: 'merge', out: { bar: 1 } }), 10) + ) } async function zed() { - return new Promise(r=>setTimeout(()=>r({op:'merge', out:{zed:1}}),10)) + return new Promise((r) => + setTimeout(() => r({ op: 'merge', out: { zed: 1 } }), 10) + ) } async function qaz_impl() { - return new Promise(r=>setTimeout(()=>r({op:'merge', out:{qaz:1}}),10)) + return new Promise((r) => + setTimeout(() => r({ op: 'merge', out: { qaz: 1 } }), 10) + ) } - + async function qaz() { return await qaz_impl() } - async function ext0(x) { - return new Promise(r=>setTimeout(()=>r('ext0-'+x),10)) + return new Promise((r) => setTimeout(() => r('ext0-' + x), 10)) } - + function a_ext0() { var ext0p = ext0('a') - return {op:'merge',out:{ext0p:ext0p}} + return { op: 'merge', out: { ext0p: ext0p } } } async function b_ext0(spec) { var ext0r = await spec.data.ext0p - return {op:'merge',out:{ext0r:ext0r}} + return { op: 'merge', out: { ext0r: ext0r } } } - function ext1(x, cb) { - setTimeout(()=>cb(null,'ext1-'+x),10) + setTimeout(() => cb(null, 'ext1-' + x), 10) } function a_ext1() { - return new Promise(r=>{ - ext1('a', function(err, out) { - r({op:'merge',out:{ext1r:out}}) + return new Promise((r) => { + ext1('a', function (err, out) { + r({ op: 'merge', out: { ext1r: out } }) }) }) } - - h0.add({name:'foo', exec:foo}) - h0.add([bar,zed,{name:'qaz',exec:qaz}]) + + h0.add({ name: 'foo', exec: foo }) + h0.add([bar, zed, { name: 'qaz', exec: qaz }]) h0.add(a_ext0) h0.add(b_ext0) h0.add(a_ext1) - + var out = await h0.exec() //console.dir(out,{depth:null}) expect(out.err).not.exists() @@ -2562,23 +2559,23 @@ describe('ordu', function() { zed: 1, qaz: 1, ext0r: 'ext0-a', - ext1r: 'ext1-a' + ext1r: 'ext1-a', }) expect(out.data.ext0p).exists() - - //console.dir(taskresult_log, {depth:null}) //console.dir(taskend_log, {depth:null}) - }) - it('insert-order', async () => { var h0 = new Ordu() - var names = (h0)=>h0.tasks().map(t=>t.name).join(' ') - + var names = (h0) => + h0 + .tasks() + .map((t) => t.name) + .join(' ') + h0.add(function a() {}) expect(names(h0)).equal('a') @@ -2588,83 +2585,80 @@ describe('ordu', function() { h0.add(function c() {}) expect(names(h0)).equal('a b c') - - h0.add(function A() {}, {before:'a'}) + h0.add(function A() {}, { before: 'a' }) expect(names(h0)).equal('A a b c') - h0.add(function B() {}, {before:'b'}) + h0.add(function B() {}, { before: 'b' }) expect(names(h0)).equal('A a B b c') - h0.add(function C() {}, {before:'c'}) + h0.add(function C() {}, { before: 'c' }) expect(names(h0)).equal('A a B b C c') - - h0.add(function a0() {}, {after:'a'}) + h0.add(function a0() {}, { after: 'a' }) expect(names(h0)).equal('A a a0 B b C c') - h0.add(function b0() {}, {after:'b'}) + h0.add(function b0() {}, { after: 'b' }) expect(names(h0)).equal('A a a0 B b b0 C c') - h0.add(function c0() {}, {after:'c'}) + h0.add(function c0() {}, { after: 'c' }) expect(names(h0)).equal('A a a0 B b b0 C c c0') - - h0.add(function A0() {}, {before:'a'}) + h0.add(function A0() {}, { before: 'a' }) expect(names(h0)).equal('A A0 a a0 B b b0 C c c0') - h0.add(function B0() {}, {before:'b'}) + h0.add(function B0() {}, { before: 'b' }) expect(names(h0)).equal('A A0 a a0 B B0 b b0 C c c0') - h0.add(function C0() {}, {before:'c'}) + h0.add(function C0() {}, { before: 'c' }) expect(names(h0)).equal('A A0 a a0 B B0 b b0 C C0 c c0') - - h0.add(function a1() {}, {after:'a'}) + h0.add(function a1() {}, { after: 'a' }) expect(names(h0)).equal('A A0 a a1 a0 B B0 b b0 C C0 c c0') - h0.add(function b1() {}, {after:'b'}) + h0.add(function b1() {}, { after: 'b' }) expect(names(h0)).equal('A A0 a a1 a0 B B0 b b1 b0 C C0 c c0') - h0.add(function c1() {}, {after:'c'}) + h0.add(function c1() {}, { after: 'c' }) expect(names(h0)).equal('A A0 a a1 a0 B B0 b b1 b0 C C0 c c1 c0') - - h0.add(function A1() {}, {after:'A'}) + h0.add(function A1() {}, { after: 'A' }) expect(names(h0)).equal('A A1 A0 a a1 a0 B B0 b b1 b0 C C0 c c1 c0') - h0.add(function AA0() {}, {before:'A'}) + h0.add(function AA0() {}, { before: 'A' }) expect(names(h0)).equal('AA0 A A1 A0 a a1 a0 B B0 b b1 b0 C C0 c c1 c0') - //console.log(names(h0)) }) - it('errors', async () => { var h0 = new Ordu() h0.add(function a() { return { - err: new Error('a-err') + err: new Error('a-err'), } }) var out = await h0.exec() expect(out.err.message).equals('a-err') - - var cbout - await h0.exec({},{},{done:function(rout) { - cbout = rout - }}) - - await new Promise(r=>setImmediate(()=>{ - expect(cbout.err.message).equals('a-err') - r() - })) - + await h0.exec( + {}, + {}, + { + done: function (rout) { + cbout = rout + }, + } + ) + await new Promise((r) => + setImmediate(() => { + expect(cbout.err.message).equals('a-err') + r() + }) + ) var h1 = new Ordu() @@ -2675,20 +2669,24 @@ describe('ordu', function() { var h1out = await h1.exec() expect(h1out.err.message).equals('a-terr') - var h1cbout - await h1.exec({},{},{done:function(rout) { - h1cbout = rout - }}) - - await new Promise(r=>setImmediate(()=>{ - expect(h1cbout.err.message).equals('a-terr') - r() - })) + await h1.exec( + {}, + {}, + { + done: function (rout) { + h1cbout = rout + }, + } + ) - + await new Promise((r) => + setImmediate(() => { + expect(h1cbout.err.message).equals('a-terr') + r() + }) + ) }) - }) }).call(this,require("timers").setImmediate) diff --git a/test/coverage.html b/test/coverage.html index b9ea2f8..dfd7328 100644 --- a/test/coverage.html +++ b/test/coverage.html @@ -547,7 +547,7 @@

Test Report

0
0
11
-
235
+
210
@@ -574,7 +574,7 @@

Test Report

ordu-legacy construct - 9 + 6 2 @@ -602,49 +602,49 @@

Test Report

ordu-legacy process - 1 + 3 6 ordu-legacy tags - 3 + 2 7 ordu sanity - 1 + 0 8 ordu happy - 125 + 105 9 ordu async - 63 + 57 10 ordu insert-order - 9 + 14 11 ordu errors - 3 + 2 diff --git a/test/ordu-legacy.test.js b/test/ordu-legacy.test.js index 4b47c8d..6165d23 100644 --- a/test/ordu-legacy.test.js +++ b/test/ordu-legacy.test.js @@ -6,14 +6,13 @@ var Ordu = require('..').LegacyOrdu var Lab = require('@hapi/lab') Lab = null != Lab.script ? Lab : require('hapi-lab-shim') - var Code = require('@hapi/code') var lab = (exports.lab = Lab.script()) var describe = lab.describe var it = lab.it var expect = Code.expect -describe('ordu-legacy', function() { +describe('ordu-legacy', function () { it('construct', async () => { var w = Ordu() expect(w).to.exist() @@ -56,20 +55,20 @@ describe('ordu-legacy', function() { ctxt$: { index$: 0, taskname$: 'first', - len: 3 + len: 3, }, data$: [], index$: 0, taskname$: 'first', kind: 'error', - why: 'no foo' + why: 'no foo', }) }) it('happy', async () => { var w = Ordu() - w.add(function(ctxt, data) { + w.add(function (ctxt, data) { data.x = 1 }) @@ -105,14 +104,14 @@ describe('ordu-legacy', function() { var w = Ordu({ name: 'foo' }) w.add(function zero() {}) - .add(function() {}) + .add(function () {}) .add(function two() {}) expect(w.tasknames()).to.equal(['zero', 'foo_task1', 'two']) expect(w.taskdetails()).to.equal([ 'zero:{tags:}', 'foo_task1:{tags:}', - 'two:{tags:}' + 'two:{tags:}', ]) expect('' + w).to.equal('foo:[zero,foo_task1,two]') }) diff --git a/test/ordu.test.js b/test/ordu.test.js index a3e5cd3..1034387 100644 --- a/test/ordu.test.js +++ b/test/ordu.test.js @@ -12,181 +12,173 @@ var describe = lab.describe var it = lab.it var expect = Code.expect -describe('ordu', function() { +describe('ordu', function () { it('sanity', async () => { var h0 = new Ordu() expect(h0).exists() }) - + it('happy', async () => { var h0 = new Ordu() var taskresult_log = [] var taskend_log = [] - h0.on('task-result', (tr)=>{ + h0.on('task-result', (tr) => { taskresult_log.push(tr) }) - h0.on('task-end', (ev)=>{ + h0.on('task-end', (ev) => { taskend_log.push(ev) }) - h0.add({ name: 'A', from: 'my-ref-01', meta: { - from: {foo:1} - } + from: { foo: 1 }, + }, }) h0.add({ name: 'B', - active: false + active: false, }) h0.add({ exec: (spec) => { - if(spec.ctx.err0) { + if (spec.ctx.err0) { throw new Error('err0') } - if(spec.ctx.err2) { - return {op:'not-an-op'} + if (spec.ctx.err2) { + return { op: 'not-an-op' } } return null - } + }, }) - h0.add({ id: '0', exec: () => ({ op: 'merge', out: { - x:2 + x: 2, }, - why: 'some-reason' - }) + why: 'some-reason', + }), }) h0.add({ if: { x: 4, - xx: 40 + xx: 40, }, exec: () => ({ op: 'merge', out: { - q: 1 - } - }) + q: 1, + }, + }), }) - h0.add({ name: 'a', - exec: async() => { - return new Promise((r)=>setTimeout(()=>{r({ - op: 'merge' - // out missing! - })},10)) - } + exec: async () => { + return new Promise((r) => + setTimeout(() => { + r({ + op: 'merge', + // out missing! + }) + }, 10) + ) + }, }) - h0.add( - function b() { - return { - op: 'merge', - out: { - x:4 - } - } + h0.add(function b() { + return { + op: 'merge', + out: { + x: 4, + }, } - ) + }) - h0.add( - function c() { - return { - op: 'lookup', - out: { - id:'001' - } - } + h0.add(function c() { + return { + op: 'lookup', + out: { + id: '001', + }, } - ) + }) - - h0 - .add({ - if: { - 'x': 4 + h0.add({ + if: { + x: 4, + }, + exec: () => ({ + op: 'merge', + out: { + qq: 2, }, - exec: () => ({ - op: 'merge', - out: { - qq: 2 - } - }) - }) - .add({ - exec: () => ({ - op: 'stop', - out: { - last: 99 - } - }) - }) - + }), + }).add({ + exec: () => ({ + op: 'stop', + out: { + last: 99, + }, + }), + }) h0.add({ exec: () => ({ op: 'merge', out: { - 'should-never-be-reached': true - } - }) + 'should-never-be-reached': true, + }, + }), }) + h0.add(() => {}) + + expect( + Object.keys(h0.task).map( + (tn) => tn + '~' + ('function' === typeof h0.task[tn].exec) + ) + ).equal([ + 'A~true', + 'B~true', + 'task0~true', + 'task1~true', + 'task2~true', + 'a~true', + 'b~true', + 'c~true', + 'task3~true', + 'task4~true', + 'task5~true', + 'task6~true', + ]) - h0.add(()=>{}) - - expect(Object.keys(h0.task) - .map(tn=>tn+'~'+('function'===typeof(h0.task[tn].exec)))) - .equal([ - 'A~true', - 'B~true', - 'task0~true', - 'task1~true', - 'task2~true', - 'a~true', - 'b~true', - 'c~true', - 'task3~true', - 'task4~true', - 'task5~true', - 'task6~true' - ]) - - h0.operator('lookup', async (tr, ctx, data) => { - if(ctx.err1) throw new Error('err1') + if (ctx.err1) throw new Error('err1') - return new Promise((r)=>{ - setTimeout(()=>{ + return new Promise((r) => { + setTimeout(() => { data.y = tr.out - r({stop:false}) - },10) + r({ stop: false }) + }, 10) }) }) - h0.operator(function does_nothing(tr, ctx, data) { - return {stop:false} + return { stop: false } }) - + //console.log(h0.tasks()) expect(h0.tasks().length).equal(12) - + var out = await h0.exec() expect(out.data).equal({ x: 4, y: { id: '001' }, qq: 2, last: 99 }) expect(out.task_count).equal(8) @@ -195,51 +187,53 @@ describe('ordu', function() { //console.dir(taskresult_log, {depth:null}) //console.dir(taskend_log, {depth:null}) - expect(taskresult_log.map(te=>te.name+'~'+te.op)).equal([ - 'A~next', - 'B~skip', - 'task0~next', - 'task1~merge', - 'task2~skip', - 'a~merge', - 'b~merge', - 'c~lookup', - 'task3~merge', - 'task4~stop' + expect(taskresult_log.map((te) => te.name + '~' + te.op)).equal([ + 'A~next', + 'B~skip', + 'task0~next', + 'task1~merge', + 'task2~skip', + 'a~merge', + 'b~merge', + 'c~lookup', + 'task3~merge', + 'task4~stop', ]) - expect(taskend_log.map(te=>te.name+'~'+te.op+'~'+te.operate.stop)).equal([ - 'A~next~false', - 'B~skip~false', - 'task0~next~false', - 'task1~merge~false', - 'task2~skip~false', - 'a~merge~false', - 'b~merge~false', - 'c~lookup~false', - 'task3~merge~false', - 'task4~stop~true' + expect( + taskend_log.map((te) => te.name + '~' + te.op + '~' + te.operate.stop) + ).equal([ + 'A~next~false', + 'B~skip~false', + 'task0~next~false', + 'task1~merge~false', + 'task2~skip~false', + 'a~merge~false', + 'b~merge~false', + 'c~lookup~false', + 'task3~merge~false', + 'task4~stop~true', ]) - - - - out = await h0.exec({},{z:1, y: null}) + out = await h0.exec({}, { z: 1, y: null }) expect(out.data).equal({ z: 1, x: 4, y: { id: '001' }, qq: 2, last: 99 }) expect(out.task_count).equal(8) expect(out.task_total).equal(12) - - out = await h0.exec({err0:true},{z:2}) + out = await h0.exec({ err0: true }, { z: 2 }) //console.log(out) expect(out.err.message).equal('err0') - var operators = h0.operators() expect(Object.keys(operators)).equal([ - 'next','skip','stop','merge','lookup', 'does_nothing' + 'next', + 'skip', + 'stop', + 'merge', + 'lookup', + 'does_nothing', ]) - expect(h0.tasks().map(t=>t.name)).equals([ + expect(h0.tasks().map((t) => t.name)).equals([ 'A', 'B', 'task0', @@ -251,89 +245,92 @@ describe('ordu', function() { 'task3', 'task4', 'task5', - 'task6' + 'task6', ]) - - out = await h0.exec({err1:true},null,{runid:'foo'}) + out = await h0.exec({ err1: true }, null, { runid: 'foo' }) //console.log(out) expect(out.err.message).equal('err1') - - out = await h0.exec({err2:true},void 0,{done:(res)=>{ - expect(res.err.message).equal('Unknown operation: not-an-op') - }}) + out = await h0.exec({ err2: true }, void 0, { + done: (res) => { + expect(res.err.message).equal('Unknown operation: not-an-op') + }, + }) expect(out.err.message).equal('Unknown operation: not-an-op') - }) - it('async', async ()=>{ - var h0 = new Ordu({debug:true}) + it('async', async () => { + var h0 = new Ordu({ debug: true }) var taskresult_log = [] var taskend_log = [] - h0.on('task-result', (tr)=>{ + h0.on('task-result', (tr) => { taskresult_log.push(tr) }) - h0.on('task-end', (ev)=>{ + h0.on('task-end', (ev) => { taskend_log.push(ev) }) function foo() { - return {op:'merge', out:{foo:1}} + return { op: 'merge', out: { foo: 1 } } } function bar() { - return new Promise(r=>setTimeout(()=>r({op:'merge', out:{bar:1}}),10)) + return new Promise((r) => + setTimeout(() => r({ op: 'merge', out: { bar: 1 } }), 10) + ) } async function zed() { - return new Promise(r=>setTimeout(()=>r({op:'merge', out:{zed:1}}),10)) + return new Promise((r) => + setTimeout(() => r({ op: 'merge', out: { zed: 1 } }), 10) + ) } async function qaz_impl() { - return new Promise(r=>setTimeout(()=>r({op:'merge', out:{qaz:1}}),10)) + return new Promise((r) => + setTimeout(() => r({ op: 'merge', out: { qaz: 1 } }), 10) + ) } - + async function qaz() { return await qaz_impl() } - async function ext0(x) { - return new Promise(r=>setTimeout(()=>r('ext0-'+x),10)) + return new Promise((r) => setTimeout(() => r('ext0-' + x), 10)) } - + function a_ext0() { var ext0p = ext0('a') - return {op:'merge',out:{ext0p:ext0p}} + return { op: 'merge', out: { ext0p: ext0p } } } async function b_ext0(spec) { var ext0r = await spec.data.ext0p - return {op:'merge',out:{ext0r:ext0r}} + return { op: 'merge', out: { ext0r: ext0r } } } - function ext1(x, cb) { - setTimeout(()=>cb(null,'ext1-'+x),10) + setTimeout(() => cb(null, 'ext1-' + x), 10) } function a_ext1() { - return new Promise(r=>{ - ext1('a', function(err, out) { - r({op:'merge',out:{ext1r:out}}) + return new Promise((r) => { + ext1('a', function (err, out) { + r({ op: 'merge', out: { ext1r: out } }) }) }) } - - h0.add({name:'foo', exec:foo}) - h0.add([bar,zed,{name:'qaz',exec:qaz}]) + + h0.add({ name: 'foo', exec: foo }) + h0.add([bar, zed, { name: 'qaz', exec: qaz }]) h0.add(a_ext0) h0.add(b_ext0) h0.add(a_ext1) - + var out = await h0.exec() //console.dir(out,{depth:null}) expect(out.err).not.exists() @@ -344,23 +341,23 @@ describe('ordu', function() { zed: 1, qaz: 1, ext0r: 'ext0-a', - ext1r: 'ext1-a' + ext1r: 'ext1-a', }) expect(out.data.ext0p).exists() - - //console.dir(taskresult_log, {depth:null}) //console.dir(taskend_log, {depth:null}) - }) - it('insert-order', async () => { var h0 = new Ordu() - var names = (h0)=>h0.tasks().map(t=>t.name).join(' ') - + var names = (h0) => + h0 + .tasks() + .map((t) => t.name) + .join(' ') + h0.add(function a() {}) expect(names(h0)).equal('a') @@ -370,83 +367,80 @@ describe('ordu', function() { h0.add(function c() {}) expect(names(h0)).equal('a b c') - - h0.add(function A() {}, {before:'a'}) + h0.add(function A() {}, { before: 'a' }) expect(names(h0)).equal('A a b c') - h0.add(function B() {}, {before:'b'}) + h0.add(function B() {}, { before: 'b' }) expect(names(h0)).equal('A a B b c') - h0.add(function C() {}, {before:'c'}) + h0.add(function C() {}, { before: 'c' }) expect(names(h0)).equal('A a B b C c') - - h0.add(function a0() {}, {after:'a'}) + h0.add(function a0() {}, { after: 'a' }) expect(names(h0)).equal('A a a0 B b C c') - h0.add(function b0() {}, {after:'b'}) + h0.add(function b0() {}, { after: 'b' }) expect(names(h0)).equal('A a a0 B b b0 C c') - h0.add(function c0() {}, {after:'c'}) + h0.add(function c0() {}, { after: 'c' }) expect(names(h0)).equal('A a a0 B b b0 C c c0') - - h0.add(function A0() {}, {before:'a'}) + h0.add(function A0() {}, { before: 'a' }) expect(names(h0)).equal('A A0 a a0 B b b0 C c c0') - h0.add(function B0() {}, {before:'b'}) + h0.add(function B0() {}, { before: 'b' }) expect(names(h0)).equal('A A0 a a0 B B0 b b0 C c c0') - h0.add(function C0() {}, {before:'c'}) + h0.add(function C0() {}, { before: 'c' }) expect(names(h0)).equal('A A0 a a0 B B0 b b0 C C0 c c0') - - h0.add(function a1() {}, {after:'a'}) + h0.add(function a1() {}, { after: 'a' }) expect(names(h0)).equal('A A0 a a1 a0 B B0 b b0 C C0 c c0') - h0.add(function b1() {}, {after:'b'}) + h0.add(function b1() {}, { after: 'b' }) expect(names(h0)).equal('A A0 a a1 a0 B B0 b b1 b0 C C0 c c0') - h0.add(function c1() {}, {after:'c'}) + h0.add(function c1() {}, { after: 'c' }) expect(names(h0)).equal('A A0 a a1 a0 B B0 b b1 b0 C C0 c c1 c0') - - h0.add(function A1() {}, {after:'A'}) + h0.add(function A1() {}, { after: 'A' }) expect(names(h0)).equal('A A1 A0 a a1 a0 B B0 b b1 b0 C C0 c c1 c0') - h0.add(function AA0() {}, {before:'A'}) + h0.add(function AA0() {}, { before: 'A' }) expect(names(h0)).equal('AA0 A A1 A0 a a1 a0 B B0 b b1 b0 C C0 c c1 c0') - //console.log(names(h0)) }) - it('errors', async () => { var h0 = new Ordu() h0.add(function a() { return { - err: new Error('a-err') + err: new Error('a-err'), } }) var out = await h0.exec() expect(out.err.message).equals('a-err') - - var cbout - await h0.exec({},{},{done:function(rout) { - cbout = rout - }}) - - await new Promise(r=>setImmediate(()=>{ - expect(cbout.err.message).equals('a-err') - r() - })) - + await h0.exec( + {}, + {}, + { + done: function (rout) { + cbout = rout + }, + } + ) + await new Promise((r) => + setImmediate(() => { + expect(cbout.err.message).equals('a-err') + r() + }) + ) var h1 = new Ordu() @@ -457,18 +451,22 @@ describe('ordu', function() { var h1out = await h1.exec() expect(h1out.err.message).equals('a-terr') - var h1cbout - await h1.exec({},{},{done:function(rout) { - h1cbout = rout - }}) - - await new Promise(r=>setImmediate(()=>{ - expect(h1cbout.err.message).equals('a-terr') - r() - })) + await h1.exec( + {}, + {}, + { + done: function (rout) { + h1cbout = rout + }, + } + ) - + await new Promise((r) => + setImmediate(() => { + expect(h1cbout.err.message).equals('a-terr') + r() + }) + ) }) - })