| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |         var tools = require("../index");        var expect = require('expect.js');        describe('Tools API', function() {            //  before(setup);            //  after(cleanup);            describe('add_action do_action', function() {                it('Can add an `action` function to be called with do_action', function(done) {                    var tool = tools();                    console.log(tool);                                        tool.add_action("test", function() {                        expect(true)                        done();                    }, 10);                    tool.do_action("test");                });                it('Can add an `action` function to be called with do_action with extra arguments', function(                    done) {                    var tool = tools();                    tool.add_action("test", function(myarg) {                        expect(myarg).to.equal("hello");                        done();                    }, 10);                    tool.do_action("test", "hello");                });                it('Can add an `action` function to be called with do_action sorted', function(done) {                    var tool = tools();                    var iii = 0;                    tool.add_action("test", function() {                        expect(iii).to.equal(2)                        iii++                    }, 30);                    tool.add_action("test", function() {                        expect(iii).to.equal(1)                        iii++                        done();                    }, 20);                    tool.add_action("test", function() {                        expect(iii).to.equal(3)                        iii++                    }, 50);                    tool.add_action("test", function() {                        expect(iii).to.equal(0)                        iii++                    }, 10);                    tool.do_action("test");                });                it('Can add an `action` function to be called with do_action with extra arguments sorted',                    function(done) {                        var tool = tools();                        var iii = 0;                        tool.add_action("test", function(myarg) {                            expect(iii).to.equal(2)                            expect(myarg).to.equal("hello");                            iii++                        }, 30);                        tool.add_action("test", function(myarg) {                            expect(iii).to.equal(1)                            expect(myarg).to.equal("hello");                            iii++                            done();                        }, 20);                        tool.add_action("test", function(myarg) {                            expect(iii).to.equal(3)                            expect(myarg).to.equal("hello");                            iii++                        }, 50);                        tool.add_action("test", function(myarg) {                            expect(iii).to.equal(0)                            expect(myarg).to.equal("hello");                            iii++                        }, 10);                        tool.do_action("test", "hello");                    });            })            describe('add_filters apply_filters', function() {                it('Can add an `filter` function to be called with apply_filters ARRAY', function(done) {                    var tool = tools();                    tool.add_filters("test", function(a) {                        a.push("test");                        return a;                    }, 10, "test");                    var t = tool.apply_filters("test", []);                    expect(t).to.be.an('array');                    expect(t.length).to.equal(1);                    expect(t[0]).to.equal("test");                    done();                });                it('Can add an `filter` function to be called with apply_filters ARRAY sorted', function(done) {                    var tool = tools();                    tool.add_filters("test", function(a) {                        a.push("test");                        return a;                    }, 10);                    tool.add_filters("test", function(a) {                        a.push("test2");                        return a;                    }, 5);                    var t = tool.apply_filters("test", []);                    expect(t).to.be.an('array');                    expect(t.length).to.equal(2);                    expect(t[0]).to.equal("test2");                    done();                });                it('Can add an `filter` function to be called with apply_filters ARRAY sorted 2', function(done) {                    var tool = tools();                    tool.add_filters("test", function(a) {                        if(a.length>0){                            a[0]=a[0]+":1";                        }                        return a;                    }, 10);                    var t = tool.apply_filters("test", ["1","2","3"]);                    expect(t).to.be.an('array');                    expect(t.length).to.equal(3);                    expect(t[0]).to.equal("1:1");                    done();                });                it('Can add an `filter` function to be called with apply_filters ARRAY sorted', function(done) {                    var tool = tools();                    tool.add_filters("test", function(a) {                        a.push(function(b, cb) {                            console.log("LLL", arguments);                            cb(null, b())                        })                        return a;                    }, 10);                    tool.add_filters("test", function(a) {                        a.push(function(b, cb) {                            console.log("oooo", arguments);                            cb(null, b())                        })                        return a;                    }, 5);                    tool.add_filters("testaa", function(a) {                        a.push(function(b, cb) {                            console.log("aaa", arguments);                            cb(null, b())                        })                        return a;                    }, 5);                                        var t = tool.apply_filters_map(["test","testaa"],function(ao){                    		console.log("OOOOOAAA",ao)                    }, function(err, result) {                        console.log("JJJJJJJJJJJJ", arguments);                    });                    console.log(t);                    expect(t).to.be.an('array');                    expect(t.length).to.equal(2);                    expect(t[0]).to.equal("test2");                    done();                });            })        })
 |