diff --git a/.gitignore b/.gitignore index 56f45cc2..764dd8f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -node_modules/* +node_modules npm-debug.log gun.min.js yarn.lock @@ -7,4 +7,7 @@ yarn.lock .idea/ *.bak *.new -*.DS_store +*.DS_store + +# Unbuilt files. +src/ diff --git a/test/distributed.js b/e2e/distributed.js similarity index 100% rename from test/distributed.js rename to e2e/distributed.js diff --git a/test/holy/grail.js b/e2e/holy/grail.js similarity index 100% rename from test/holy/grail.js rename to e2e/holy/grail.js diff --git a/test/holy/gun-server.js b/e2e/holy/gun-server.js similarity index 100% rename from test/holy/gun-server.js rename to e2e/holy/gun-server.js diff --git a/test/holy/index.html b/e2e/holy/index.html similarity index 100% rename from test/holy/index.html rename to e2e/holy/index.html diff --git a/test/holy/ports.json b/e2e/holy/ports.json similarity index 100% rename from test/holy/ports.json rename to e2e/holy/ports.json diff --git a/e2e/package.json b/e2e/package.json new file mode 100644 index 00000000..7908c7ff --- /dev/null +++ b/e2e/package.json @@ -0,0 +1,11 @@ +{ + "name": "gun-tests-e2e", + "version": "0.0.0", + "description": "End to end tests for gun", + "private": true, + "main": "distributed.js", + "devDependencies": { + "panic-server": "~>0.3.0", + "selenium-webdriver": "~>2.53.2" + } +} diff --git a/gun.js b/gun.js index 1b36199e..2f7150b3 100644 --- a/gun.js +++ b/gun.js @@ -910,8 +910,7 @@ } at.once = true; return gun; - }; - + } function output(at){ var cat = this, gun = cat.gun, tmp; // TODO: BUG! Outgoing `get` to read from in memory!!! @@ -1112,7 +1111,6 @@ }); return; } - console.debug(103, 'out', cat.get); at = obj_to(at, {get: {}}); } else { if(cat.ask){ return } @@ -1120,14 +1118,12 @@ if(cat.get){ if(cat.soul){ cat.ask = -1; - console.debug(104, 'out', cat.get, cat.ask); gun.on('out', { get: {'#': cat.soul}, '#': Gun.on.ask(Gun.HAM.synth, gun), }); return; } - console.debug(102, 'any out', cat.get, cat.ask); cat.back.on('out', { get: obj_put({}, _field, cat.get), gun: gun @@ -1142,20 +1138,27 @@ function input(at, ev){ at = at._ || at; var cat = this, gun = at.gun, coat = gun._, change = at.put, tmp; - console.debug(119, 'in', cat.get, change, cat.next, cat.maps); - console.debug(117, 'in', cat.get, change, cat.next, cat.maps); - console.debug(116, 'in', cat.get, change, cat.next, cat.maps); - console.debug(115, 'in', cat.get, change, cat.next, cat.maps); - console.debug(109, 'in', cat.get, change, cat.next); - console.debug(107, 'in', cat.get, change, cat.next, cat.maps); - console.debug(6, 'in', cat.get, change, cat.next, cat.maps); - console.debug(5, 'in', cat.get, change, cat.next, cat.maps); - console.debug(3, 'in', cat.get, change, cat.next, cat.maps); + console.debug(107, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(106, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(105, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(102, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(15, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(9, 'in', cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(8, 'in', cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(6, 'in', cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(4, 'in', cat.get, change, cat.next, cat.maps); + console.debug(22, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); + console.debug(21, 'in', cat, cat.get, change, cat.next, cat.maps, cat.soul); if(cat.maps){ + var proxy = obj_to(at, {get: cat.get, gun: cat.gun}); // TODO: BUG! Broken via! + console.debug(14, 'in', cat, cat.get, change, proxy.put); obj_map(cat.maps, function(cat){ - cat.on('in', at); - }) + cat.on('in', proxy); + }); + console.debug(18, 'in', cat, cat.get, change, proxy.put); + console.debug(24, "REMEMBER", cat.get, change, cat.next, cat.maps); } + console.debug(11, 'in', cat.get, change, cat.next, cat.maps, cat.soul); if(value.call(cat, at, ev)){ return; } @@ -1168,43 +1171,45 @@ return; } if(u === put){ - //not(cat, at); + if(cat === coat){ + console.debug(19, 'end'); + not(cat, at); + } else { + console.debug(16, 'off'); + Gun.obj.del(coat.maps, cat.id); + } return true; } if(!(rel = Gun.val.rel.is(put))){ - /*if(cat.proxy && cat.proxy.at !== at){ // TODO: CLEAN UP? Cleaner approach? - if(cat.proxy.rel){ - cat.put = coat.put; - } - cat.on('in', cat.proxy.at = obj_to(at, {get: cat.get, gun: coat.gun, via: at})); // TODO: BUG!!! Re-using at as via will create the wrong at via path! - return true; - }*/ if(cat.proxy){ cat.put = coat.put; } - console.debug(7, '!', cat); if(Gun.val.is(put)){ - //not(coat, at); - not(cat, at); + if(cat === coat){ + not(cat, at); + } else { + (coat.maps || (coat.maps = {}))[cat.id || (cat.id = Math.random())] = cat; + } return true; } + if(!cat.proxy && cat !== coat){ + console.debug(108, '????', cat !== coat, u !== coat.put); + if(u !== coat.put){ // TODO: BUG!? Is this a safe condition? + console.debug(23, 'values', cat.get, put, cat !== coat, u !== coat.put); + return true; + } + } + console.debug(25, 'values', cat.get, put, !cat.proxy, cat !== coat); return; }; // TODO: MARK! COME BACK HERE! What if we INVERT the model? Rather than map subbing to all refs that come it way, the refs know of the map? if(coat !== cat){ - console.debug(110, 'values', coat !== cat, coat.ask, cat.ask); (coat.maps || (coat.maps = {}))[cat.id || (cat.id = Math.random())] = cat; - /* - if(!(cat.proxy || (cat.proxy = {}))[coat.id = coat.id || Gun.text.random(6)]){ - cat.proxy[coat.id] = {ref: coat.gun, sub: gun._.on('in', input, cat)}; - } else { - solve(coat, cat); - ask(cat, rel); + if(coat.proxy){ + console.debug(10, 'values', cat.get, rel, coat.proxy); + //return true; } - */ - //return true; } - console.debug(7, 'values', cat.rel, coat.proxy); if(coat.proxy){ if(rel === coat.proxy.rel){ ev.stun(); @@ -1213,53 +1218,34 @@ at.put = coat.put = tmp.put; return true; } - //Gun.obj.del(cat.on('in').map, coat.proxy.ref._.id); tmp = coat.proxy; + console.debug(12, 'values', cat.get, rel, coat.proxy); not(coat, at); - //not(cat, at); } tmp = coat.proxy = {rel: rel, ref: coat.root.get(rel), was: tmp}; + console.debug(20, 'values', cat.get, rel, coat.proxy); tmp.sub = tmp.ref._.on('in', input, coat); + console.debug(21, 'values', cat.get, rel, coat.proxy); tmp = coat.put; - console.debug(111, 'values', rel, coat.proxy); + console.debug(103, 'values', coat.proxy); ask(cat, rel); if(tmp !== coat.put){ ev.stun() } - /*if(cat.maps){ - obj_map(cat.maps, function(cat){ - cat.on('in', at); - }) - }*/ return true; } - function solve(coat, cat){ - if(!coat.proxy){ return } - var was = coat.proxy.was; - if(!was){ return } - was = was.ref._; - obj_map(cat.next, function(sub, key){ - var a = was.next[key]; - if(!a){ return } - var id = a._.id, proxy = sub._.proxy; - if(!(sub = sub._.proxy)){ return } - if(!sub[id]){ return } - if(sub[id].sub){ sub[id].sub.off() } - Gun.obj.del(sub, id); - }) - } function map(data, key){ // Map over only the changes on every update. if(node_ === key){ return } var cat = this.cat, next = cat.next || {}, via = this.at, gun, chain, at, tmp; + console.debug(26, 'map -->>', key, data, next); if(!(gun = next[key])){ return } at = gun._; - if(cat.soul){ + if(at.field){ at.put = data; - at.field = key; + //at.field = key; chain = gun; } else { chain = via.gun.get(key, null, {path: true}); // TODO: path won't be needed with 0.5 } - console.debug(118, '-->>', key, data, gun, chain); - console.debug(4, '-->>', key, data); + console.debug(7, 'map -->>', key, data, chain); gun.on('in', { put: data, get: key, @@ -1283,7 +1269,7 @@ if(obj_has(at,'put')){ at.put = u; } - console.debug(8, 'woot!', at); + console.debug(13, 'not', key, u); gun.on('in', { get: key, put: u, @@ -1305,8 +1291,8 @@ return; } if(0 === cat.ask){ return } + console.debug(104, 'ask', soul, cat.next); obj_map(cat.next, function(gun, key){ - console.debug(112, 'ask', soul, key); gun.on('out', { get: {'#': soul, '.': key}, gun: gun, @@ -1383,7 +1369,7 @@ var opt = opt || {}, gun = opt.gun = this; if(opt.change){ opt.change = 1 } opt.any = cb; - console.debug(101, 'any!'); + console.debug(100, 'lazy eval'); return gun.on('in', any, opt).on('out', {get: opt}); } function any(at, ev){ var opt = this; @@ -1411,6 +1397,7 @@ if(opt.as){ opt.any.call(opt.as, at, ev); } else { + console.debug(17, 'any!', at, data); opt.any.call(gun, at.err, data, at.get, at, ev); } } @@ -1476,7 +1463,7 @@ function batch(){ var as = this; if(!as.graph || obj_map(as.stun, no)){ return } - console.debug(1, 'PUT!', as.env.graph); + console.debug(1, 'OUT!', as.env.graph); (as.res||iife)(function(){ as.ref.on('out', { gun: as.ref, put: as.out = as.env.graph, opt: as.opt, @@ -1668,8 +1655,9 @@ } Gun.HAM.union = function(vertex, node, opt){ if(!node || !vertex || !node._ || !vertex._){ return } - opt = num_is(opt)? {machine: opt} : {machine: (+new Date)}; + opt = num_is(opt)? {machine: opt} : {machine: Gun.state()}; opt.union = Gun.obj.copy(vertex); // TODO: PERF! This will slow things down! + // TODO: PERF! Biggest slowdown (after localStorage) is the above line. Fix! Fix! opt.vertex = vertex; opt.node = node; obj_map(node._, meta, opt.union); @@ -1679,7 +1667,7 @@ return opt.union; } Gun.HAM.delta = function(vertex, node, opt){ - opt = num_is(opt)? {machine: opt} : {machine: (+new Date)}; + opt = num_is(opt)? {machine: opt} : {machine: Gun.state()}; if(!vertex){ return Gun.obj.copy(node) } opt.soul = Gun.node.soul(opt.vertex = vertex); if(!opt.soul){ return } @@ -1694,6 +1682,7 @@ var HAM = Gun.HAM(opt.machine, is, cs, value, vertex[field]); + // TODO: BUG!!!! WHAT ABOUT DEFERRED!??? @@ -1712,9 +1701,9 @@ }, root); obj_map(put, function(node, soul){ var root = this, next = root.next || (root.next = {}), gun = next[soul] || (next[soul] = root.gun.get(soul)); - gun._.put = root.graph[soul]; - console.debug(114, 'ack', soul, node); - console.debug(106, 'ack', soul, node); + gun._.put = root.graph[soul]; // TODO: BUG! Clone! + console.debug(5, 'IN ->', soul, node); + console.debug(3, 'IN ->', soul, node); gun.on('in', { put: node, get: soul, @@ -2109,7 +2098,6 @@ console.log("map!"); chain.on(cb); } - console.debug(100, 'to map'); return chain; } function map(at,ev){ @@ -2121,7 +2109,7 @@ var gun = this.gun, cat = this.cat; //console.log("-- EACH -->", f, v); var id = this.id;if(cat.set[id+f]){ return } cat.set[id+f] = 1; - console.debug(108, "-- EACH -->", f, v); + console.debug(101, "-- EACH -->", f, v); cat.on('in', {gun: gun.get(f, null, {path: true}), get: f, put: v, via: this.at}); } var obj_map = Gun.obj.map, noop = function(){}, event = {stun: noop, off: noop}, n_ = Gun.node._; @@ -2161,6 +2149,7 @@ (opt = {}).prefix = (at.opt || opt).prefix || at.gun.Back('opt.prefix') || 'gun/'; Gun.graph.is(at.put, function(node, soul){ //try{store.setItem(opt.prefix + soul, Gun.text.ify(node)); + // TODO: BUG! PERF! Biggest slowdown is because of localStorage stringifying larger and larger nodes! try{store.setItem(opt.prefix + soul, Gun.text.ify(root._.graph[soul]||node)); }catch(e){ err = e || "localStorage failure" } }); @@ -2182,8 +2171,6 @@ return; } if(Gun.obj.has(lex, '.')){var tmp = data[lex['.']];data = {_: data._};if(u !== tmp){data[lex['.']] = tmp}} - console.debug(113, 'lS get', data); - console.debug(105, 'lS get', data); //console.log('@@@@@@@@@@@@local get', data, at); gun.Back(-1).on('in', {'@': at['#'], put: Gun.graph.node(data)}); //},100); diff --git a/package.json b/package.json index ab9f8c81..85e98218 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "start": "node examples/http.js 8080", "prepublish": "npm run unbuild && uglifyjs gun.js -o gun.min.js -c -m", "test": "mocha", + "e2e": "mocha e2e/distributed.js", "docker": "hooks/build", "unbuild": "node lib/unbuild.js" }, @@ -53,8 +54,6 @@ "devDependencies": { "express": "~>4.13.4", "mocha": "~>1.9.0", - "panic-server": "~>0.3.0", - "selenium-webdriver": "~>2.53.2", - "uglify-js": "^2.2.0" + "uglify-js": "~>2.2.0" } } diff --git a/test/common.js b/test/common.js index 4007d6e4..37e23aba 100644 --- a/test/common.js +++ b/test/common.js @@ -34,7 +34,7 @@ describe('Performance', function(){ return; // performance tests } }); console.log('map: native', (t1 = (perf.now() - t1)/1000) + 's'); - + var t2 = perf.now(); var obj = {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e', 6: 'f', 7: 'g', 8: 'h', 9: 'i'}; perf(function(){ @@ -118,7 +118,7 @@ describe('Performance', function(){ return; // performance tests } }); console.log('on: native', (t1 = (perf.now() - t1)/1000) + 's'); - + var on = Gun.on.create(), c = 0; var t2 = perf.now(); perf(function(i){ @@ -155,7 +155,7 @@ describe('Performance', function(){ return; // performance tests describe('Gun', function(){ var t = {}; - + describe('Utility', function(){ var u; /* // causes logger to no longer log. @@ -355,7 +355,7 @@ describe('Gun', function(){ it('has',function(){ var obj = {a:1,b:2}; expect(Gun.obj.has(obj,'a')).to.be.ok(); - }); + }); it('empty',function(){ expect(Gun.obj.empty()).to.be(true); expect(Gun.obj.empty({a:false})).to.be(false); @@ -525,7 +525,7 @@ describe('Gun', function(){ }); e.on('foo', 1); e.on('bar', 2); - }); + }); it('resume params', function(done){ var e = {on: Gun.on}; e.on('foo', function(a, ev){ @@ -633,7 +633,7 @@ describe('Gun', function(){ if(f.f){ f.f(arg); f.cb = 0; - return; + return; } }, cb; f.flow = function(fn){ @@ -883,16 +883,16 @@ describe('Gun', function(){ describe('ify', function(){ console.log("TODO: BUG! Upgrade IFY tests to new internal API!"); return; - + var test, gun = Gun(); - + it('null', function(done){ Gun.ify(null, function(err, ctx){ - expect(err).to.be.ok(); + expect(err).to.be.ok(); done(); }); }); - + it('basic', function(done){ var data = {a: false, b: true, c: 0, d: 1, e: '', f: 'g', h: null}; Gun.ify(data, function(err, ctx){ @@ -909,14 +909,14 @@ describe('Gun', function(){ Gun.ify(data, function(err, ctx){ expect(err).to.not.be.ok(); expect(ctx.err).to.not.be.ok(); - + expect(ctx.root).to.eql(data); expect(ctx.root === data).to.not.be.ok(); expect(Gun.node.soul(ctx.root) === Gun.node.soul(data)); done(); }, {pure: true}); }); - + it('arrays', function(done){ var data = {before: {path: 'kill'}, one: {two: {lol: 'troll', three: [9, 8, 7, 6, 5]}}}; Gun.ify(data, function(err, ctx){ @@ -925,7 +925,7 @@ describe('Gun', function(){ done(); }); }); - + it('undefined', function(done){ var data = {z: undefined, x: 'bye'}; Gun.ify(data, function(err, ctx){ @@ -933,7 +933,7 @@ describe('Gun', function(){ done(); }); }); - + it('NaN', function(done){ var data = {a: NaN, b: 2}; Gun.ify(data, function(err, ctx){ @@ -941,7 +941,7 @@ describe('Gun', function(){ done(); }); }); - + it('Infinity', function(done){ // SAD DAY PANDA BEAR :( :( :(... Mark wants Infinity. JSON won't allow. var data = {a: 1, b: Infinity}; Gun.ify(data, function(err, ctx){ @@ -949,7 +949,7 @@ describe('Gun', function(){ done(); }); }); - + it('function', function(done){ var data = {c: function(){}, d: 'hi'}; Gun.ify(data, function(err, ctx){ @@ -957,7 +957,7 @@ describe('Gun', function(){ done(); }); }); - + it('extraneous', function(done){ var data = {_: {'#': 'shhh', meta: {yay: 1}}, sneak: true}; Gun.ify(data, function(err, ctx){ @@ -965,7 +965,7 @@ describe('Gun', function(){ done(); }); }); - + it('document', function(done){ var data = {users: {1: {where: {lat: Math.random(), lng: Math.random(), i: 1}}}}; Gun.ify(data, function(err, ctx){ @@ -982,7 +982,7 @@ describe('Gun', function(){ done(); }); }); - + return; // TODO! Fix GUN to handle this! data = {}; data.sneak = false; @@ -991,7 +991,7 @@ describe('Gun', function(){ test = Gun.ify(data); expect(test.err.meta).to.be.ok(); // TODO: Fail: this passes, somehow? Fix ify code! }); - + describe('Schedule', function(){ console.log("TODO: BUG! Upgrade SCHEDULE tests to new internal API!"); return; @@ -1001,7 +1001,7 @@ describe('Gun', function(){ done(); //setTimeout(function(){ done() },1); }); }); - + it('many', function(done){ Gun.schedule(Gun.time.is() + 50, function(){ done.first = true; @@ -1018,12 +1018,12 @@ describe('Gun', function(){ }); }); }); - + describe('Union', function(){ console.log("TODO: BUG! Upgrade UNION tests to new internal API!"); return; var gun = Gun(); - + it('fail', function(){ var prime = { 'asdf': { @@ -1038,7 +1038,7 @@ describe('Gun', function(){ var ctx = Gun.HAM.graph(gun, prime); expect(ctx).to.not.be.ok(); });return; - + it('basic', function(done){ var prime = { 'asdf': { @@ -1055,7 +1055,7 @@ describe('Gun', function(){ done(); }); }); - + it('disjoint', function(done){ var prime = { 'asdf': { @@ -1074,7 +1074,7 @@ describe('Gun', function(){ done(); }); }); - + it('mutate', function(done){ var prime = { 'asdf': { @@ -1091,7 +1091,7 @@ describe('Gun', function(){ done(); }); }); - + it('disjoint past', function(done){ var prime = { 'asdf': { @@ -1124,7 +1124,7 @@ describe('Gun', function(){ done(); }); }); - + it('future', function(done){ var prime = { 'asdf': { @@ -1161,7 +1161,7 @@ describe('Gun', function(){ done(); }); }); - + it('disjoint future max', function(done){ var prime = { 'asdf': { @@ -1184,7 +1184,7 @@ describe('Gun', function(){ done(); //setTimeout(function(){ done() },1); }); }); - + it('future max', function(done){ var prime = { 'asdf': { @@ -1215,7 +1215,7 @@ describe('Gun', function(){ done(); //setTimeout(function(){ done() },1); }); }); - + it('two nodes', function(done){ // chat app problem where disk dropped the last data, turns out it was a union problem! var state = Gun.time.is(); var prime = { @@ -1241,7 +1241,7 @@ describe('Gun', function(){ done(); }); }); - + it('append third node', function(done){ // chat app problem where disk dropped the last data, turns out it was a union problem! var state = Gun.time.is(); var prime = { @@ -1268,14 +1268,14 @@ describe('Gun', function(){ done(); }); }); - + it('ify null', function(){ var node = Gun.union.ify(null, 'pseudo'); expect(Gun.node.soul(node)).to.be('pseudo'); }); - + it('ify node', function(){ - + var graph = { 'asdf': { _: {'#': 'asdf', '>': { @@ -1297,7 +1297,7 @@ describe('Gun', function(){ expect(node.x).to.be(1); expect(node.y).to.be(2); }); - + it('ify graph', function(){ var graph = { 'asdf': { @@ -1347,18 +1347,18 @@ describe('Gun', function(){ describe('API', function(){ var gopt = {wire:{put:function(n,cb){cb()},get:function(k,cb){cb()}}}; var gun = Gun(); - + it.skip('gun chain separation', function(done){ // TODO: UNDO! var gun = Gun(); - + var c1 = gun.put({hello: 'world'}); - + var c2 = gun.put({hi: 'earth'}); - + c1.on(function(val){ expect(val.hi).to.not.be.ok(); }); - + c2.on(function(val){ expect(val.hello).to.not.be.ok(); if(done.c){ return } @@ -1367,7 +1367,7 @@ describe('Gun', function(){ }); describe.skip('timeywimey', function(){ // TODO: UNDO! - + it('kitty', function(done){ var g1 = gun.put({hey: 'kitty'}).key('timeywimey/kitty'); @@ -1382,12 +1382,12 @@ describe('Gun', function(){ done(); done.c = 1; }); }); - + it('kitty puppy', function(done){ var g3 = gun.put({hey: 'kitty'}).key('timeywimey/kitty/puppy'); var g4 = gun.put({hi: 'puppy'}).key('timeywimey/kitty/puppy'); - + var g5 = gun.get('timeywimey/kitty/puppy').on(function(val){ //delete val._; //console.log("puppy?", val); @@ -1397,7 +1397,7 @@ describe('Gun', function(){ done(); done.c = 1; }); }); - + it('hello', function(done){ gun.get('timeywimey/hello').on(function(val){ //delete val._; @@ -1409,7 +1409,7 @@ describe('Gun', function(){ gun.put({hello: 'world'}).key('timeywimey/hello'); }); - + it('hello foo', function(done){ gun.get('timeywimey/hello/foo').on(function(val){ //delete val._; @@ -1425,12 +1425,12 @@ describe('Gun', function(){ gun.put({foo: 'bar'}).key('timeywimey/hello/foo'); }); - + it('all', function(done){ gun.put({hey: 'kitty'}).key('timeywimey/all'); gun.put({hi: 'puppy'}).key('timeywimey/all'); - + gun.get('timeywimey/all').on(function(val){ // console.log('all', done.c, val); expect(val.hey).to.be('kitty'); @@ -1445,12 +1445,12 @@ describe('Gun', function(){ done(); done.c = 1; } }); - + gun.put({hello: 'world'}).key('timeywimey/all'); - + gun.put({foo: 'bar'}).key('timeywimey/all'); }); - + }); describe.only('plural chains', function(){ @@ -1579,7 +1579,6 @@ describe('Gun', function(){ }); it('uncached synchronous map on mutate', function(done){ - console.log("((((((((((((((((((((((((((((((((((((((((((((("); var s = Gun.state.map();s.soul = 'u/m/mutate'; Gun.on('put', {gun: gun, put: Gun.graph.ify({ alice: { @@ -1594,11 +1593,9 @@ describe('Gun', function(){ } }, s)}); var check = {}, count = {}; - console.debug.i = 100; gun.get('u/m/mutate').map().path('name').any(function(e,v,f,at){ check[v] = f; count[v] = (count[v] || 0) + 1; - console.log("***********", f,v, this); if(check.Alice && check.Bob && check['undefined']){ expect(count.Alice).to.be(1); expect(count.Bob).to.be(1); @@ -1607,35 +1604,10 @@ describe('Gun', function(){ } }); setTimeout(function(){ - console.debug.i=1;console.log("-----------------"); gun.get('u/m/mutate').path('alice').put(7); }, 300); }); - //return; - it.only("===============", function(){ - console.log("================="); - console.log("================="); - console.log("================="); - console.log("================="); - localStorage.clear(); - var gun = Gun(); - - var list = gun.get('list'); - list.set({a:1}); - list.set({b:2}); - list.set({c:3}); - list.set({e:4}); - list.set({f:5}); - list.set({g:6}); - - console.log("on!"); - list.map(function(data){ - console.log("data", data); - }); - - }); - return; it('uncached synchronous map on mutate node', function(done){ var s = Gun.state.map();s.soul = 'u/m/mutate/n'; Gun.on('put', {gun: gun, put: Gun.graph.ify({ @@ -1651,26 +1623,32 @@ describe('Gun', function(){ } }, s)}); var check = {}, count = {}; - gun.get('u/m/mutate/n').map().path('name').on(function(v,f){ + console.debug.i=100;console.log("?????????????"); + gun.get('u/m/mutate/n').map().path('name').any(function(e,v,f){ check[v] = f; count[v] = (count[v] || 0) + 1; - if(check.Alice && check.Bob && check['Alice Zzxyz']){ + console.log("************", f,v); + if(check.Alice && check.Bob && check['undefined'] && check['Alice Zzxyz']){ setTimeout(function(){ expect(done.last).to.be.ok(); expect(check['Alice Aabca']).to.not.be.ok(); expect(count.Alice).to.be(1); expect(count.Bob).to.be(1); + expect(count['undefined']).to.be(1); expect(count['Alice Zzxyz']).to.be(1); done(); },100); } }); setTimeout(function(){ + console.debug.i=1;console.log("----------------------"); gun.get('u/m/mutate/n').path('alice').put({ _:{'#':'u/m/m/n/soul'}, name: 'Alice Zzxyz' }); + return; setTimeout(function(){ + console.log("=================================="); gun.get('umaliceo').put({ name: 'Alice Aabca' }); @@ -1678,7 +1656,7 @@ describe('Gun', function(){ }, 10); }, 300); }); - + return; it('uncached synchronous map on mutate node uncached', function(done){ var s = Gun.state.map();s.soul = 'u/m/mutate/n/u'; Gun.on('put', {gun: gun, put: Gun.graph.ify({ @@ -3470,7 +3448,7 @@ describe('Gun', function(){ done(); }); }); - + it('put regex', function(done){ gun.put({reg: /regex/i}, function(err, ok){ expect(err).to.be.ok(); @@ -3500,7 +3478,7 @@ describe('Gun', function(){ done(); }); }); - + it('put node with soul get soul', function(done){ gun.put({_: {'#': 'foo'}, hello: 'world'}) .get({'#': 'foo'}, function(err, node){ @@ -3733,7 +3711,7 @@ describe('Gun', function(){ done.r = 1; if(done.w){ done(); done.c = 1 }; }); }); - + it('get key path put', function(done){ var gun = Gun().put({foo:'lol', extra: 'yes'}).key('key/path/put'); var data = gun.get('key/path/put'); @@ -3788,7 +3766,7 @@ describe('Gun', function(){ done(); done.end = true; }); }); - + it('put node get field', function(done){ // future feature. var gun = Gun(); gun.put({_:{'#': 'soul/field'}, hi: 'lol', foo: 'bar'});//.key('key/field'); @@ -3981,7 +3959,7 @@ describe('Gun', function(){ get.put({}); get.val(function(data){ // TODO: API CHANGE! Empty objects should react. //console.log("...1", data); - expect(Gun.obj.empty(data, '_')).to.be.ok(); // API CHANGED, + expect(Gun.obj.empty(data, '_')).to.be.ok(); // API CHANGED, //expect(Gun.val.rel.is(data.very)).to.be.ok(); });//, {wait: 10000}); setTimeout(function(){ @@ -4160,7 +4138,7 @@ describe('Gun', function(){ done.r = 1; if(done.w){ done(); done.c = 1 }; }); }); - + it.skip('put gun node', function(done){ var mark = gun.put({age: 23, name: "Mark Nadal"}); var amber = gun.put({age: 23, name: "Amber Nadal"}); @@ -4171,7 +4149,7 @@ describe('Gun', function(){ expect(val).to.be("Amber Nadal"); }); }); - + it('put val', function(done){ gun.put({hello: "world"}).val(function(val){ expect(val.hello).to.be('world'); @@ -4183,7 +4161,7 @@ describe('Gun', function(){ done(); }, 100); }); - + it('put key val', function(done){ gun.put({hello: "world"}).key('hello/world').val(function(val, field){ if(done.c){ return } @@ -4196,7 +4174,7 @@ describe('Gun', function(){ done(); }, 100); }); - + it('get val', function(done){ gun.get('hello/world').val(function(val, field){ expect(val.hello).to.be('world'); @@ -4245,7 +4223,7 @@ describe('Gun', function(){ done(); }, 100); }); - + it('get empty put', function(done){ var gun = Gun({init: true}); gun.get('nothing/here').put({far: "wide"}, function(err, ok){ @@ -4382,7 +4360,7 @@ describe('Gun', function(){ }); }); }); - + gun.get('order/second', function(){ //console.log('callback', 2); done.two = true; @@ -4639,7 +4617,7 @@ describe('Gun', function(){ done(); }); }); - + it('context null put value val error', function(done){ gun.put("oh yes", function(err){ expect(err).to.be.ok(); @@ -4726,10 +4704,10 @@ describe('Gun', function(){ it('val path put val', function(done){ var gun = Gun(); - + var al = gun.put({gender:'m', age:30, name:'alfred'}).key('user/alfred'); var beth = gun.put({gender:'f', age:22, name:'beth'}).key('user/beth'); - + al.val(function(a){ beth.put({friend: a}, function(err, ok){ expect(err).to.not.be.ok(); @@ -4738,7 +4716,7 @@ describe('Gun', function(){ done(); }); }); - + }); // TODO: Write a test that tests for keysoul has a key meta indicator. // TODO: A soulsoul does not have a key meta indicator. @@ -4746,7 +4724,7 @@ describe('Gun', function(){ it('val path put val key', function(done){ // bug discovered from Jose's visualizer var gun = Gun(), s = Gun.time.is(), n = function(){ return Gun.time.is() } this.timeout(5000); - + gun.put({gender:'m', age:30, name:'alfred'}).key('user/alfred'); gun.put({gender:'f', age:22, name:'beth' }).key('user/beth'); //gun.get('user/beth').path('friend').put(gun.get('user/alfred')); // ideal format which we have a future test for. @@ -4786,7 +4764,7 @@ describe('Gun', function(){ expect(obj.here).to.be('you'); } if(field === 'b'){ - expect(obj.go).to.be('dear'); + expect(obj.go).to.be('dear'); } if(field === 'c'){ expect(obj.sir).to.be('!'); @@ -4809,7 +4787,7 @@ describe('Gun', function(){ done(); }, 'qwertyasdfzxcv'); }); - + it.skip('no false positive null emit', function(done){ // TODO: THE API HAS CHANGED! REDO TEHSE! var gun = Gun({wire: {get: function(key, cb){ var g = {}; @@ -4857,9 +4835,9 @@ describe('Gun', function(){ tmp.keynode[tmp.soul] = tmp.rel; Gun.is.node.ify(tmp.keynode, 'me'); tmp.keynode[Gun._.meta]['key'] = 1; - + gun.get('me', function(err, data){ - + }).val(function(val){ done.count = (done.count || 0) + 1; setTimeout(function(){ @@ -4887,7 +4865,7 @@ describe('Gun', function(){ n = {_: {'#': soul }}; cb(null, n); }}}), soul = Gun.text.random(); - + gun.get(soul).path('a').val(function(val){ done.count = (done.count || 0) + 1; setTimeout(function(){ @@ -4902,7 +4880,7 @@ describe('Gun', function(){ var gun = Gun(gopt).get('thoughts').not(function(key){ this.put({}).key(key); }); - + setTimeout(function(){ gun.not(function(){ done.not = true; @@ -5149,7 +5127,7 @@ describe('Gun', function(){ }); g.put(obj); }); - + it('map chain map before', function(done){ var g = Gun().get('m/c/m/b'); var obj = { @@ -5199,9 +5177,9 @@ describe('Gun', function(){ expect(Gun.obj.empty(rel, Gun._.meta)).to.be.ok(); }); done.c += 1; - setTimeout(function(){ + setTimeout(function(){ expect(done.c).to.be(1); - done() + done() },10); }); }); @@ -5213,7 +5191,7 @@ describe('Gun', function(){ if(done.c){return} done(); done.c = 1; }); }); - + // TODO: BUG! We need 2 more tests... without .set()... and multiple paths on the same node. it('set multiple', function(done){ // kinda related to flip flop? var gun = Gun().get('sets').set(), i = 0; @@ -5237,7 +5215,7 @@ describe('Gun', function(){ Gun.obj.map(gun.__.graph, function(){ done.i++ }); expect(done.i).to.be(1); // make sure there isn't double. Gun.log.verbose = false; - done() + done() },10); } }); @@ -5267,7 +5245,7 @@ describe('Gun', function(){ }}, gun1 = Gun({wire: {get: hooks.get}}).get('race') , gun2 = Gun({wire: hooks}); //.get('race'); - + setTimeout(function(){ gun2.put({the: 'data'}).key('race'); setTimeout(function(){ @@ -5281,10 +5259,10 @@ describe('Gun', function(){ it('get pseudo merge', function(done){ var gun = Gun(); - + gun.put({a: 1, z: -1}).key('pseudo'); gun.put({b: 2, z: 0}).key('pseudo'); - + gun.get('pseudo').val(function(val){ expect(val.a).to.be(1); expect(val.b).to.be(2); @@ -5292,15 +5270,15 @@ describe('Gun', function(){ done(); }); }); - + it('get pseudo merge on', function(done){ var gun = Gun(); - + gun.put({a: 1, z: -1}).key('pseudon'); gun.put({b: 2, z: 0}).key('pseudon'); - + gun.get('pseudon').on(function(val){ - if(done.val){ return } // TODO: Maybe prevent repeat ons where there is no diff? (may not happen to after 1.0.0) + if(done.val){ return } // TODO: Maybe prevent repeat ons where there is no diff? (may not happen to after 1.0.0) done.val = val; expect(val.a).to.be(1); expect(val.b).to.be(2); @@ -5400,9 +5378,9 @@ describe('Gun', function(){ if('location' == field){ delete change._; ctx.l++; if('Bob' == passenger.name){ - expect(change).to.eql({'lat': '37.6159', 'lng': '-128.5'}); + expect(change).to.eql({'lat': '37.6159', 'lng': '-128.5'}); } else { - expect(change).to.eql({'lat': 'f37.6159', 'lng': 'f-128.5'}); + expect(change).to.eql({'lat': 'f37.6159', 'lng': 'f-128.5'}); } } if(ctx.n == 2 && ctx.d == 2 && ctx.l == 2){ done() } @@ -5576,9 +5554,9 @@ describe('Gun', function(){ if('location' == field){ delete val._; if(!ctx.l){ - expect(val).to.eql({'lat': '37.6159', 'lng': '-128.5'}); + expect(val).to.eql({'lat': '37.6159', 'lng': '-128.5'}); } else { - expect(val).to.eql({'lat': 'f37.6159', 'lng': 'f-128.5'}); + expect(val).to.eql({'lat': 'f37.6159', 'lng': 'f-128.5'}); } ctx.l++; } @@ -5700,7 +5678,7 @@ describe('Gun', function(){ c: { d: 1, e: 2, - f: 3 + f: 3 } } }, @@ -5800,7 +5778,7 @@ describe('Gun', function(){ },100); }); - it.only("get users map path path any later", function(done){ + it("get users map path path any later", function(done){ var gun = Gun(); gun.get('g/n/m/f/l').map().path('spouse').path('work'); gun.put({_:{'#':'g/n/m/f/l'}, @@ -5882,7 +5860,7 @@ describe('Gun', function(){ return; return; return; - it.only("get map path val", function(done){ // Terje's bug + it("get map path val", function(done){ // Terje's bug var gun = Gun(); var ctx = {l: -1, d: 0}; var passengers = gun.get('passengers/path').not(function(key){ @@ -5897,9 +5875,9 @@ describe('Gun', function(){ console.log("******", field, val); expect(field).to.be('lng'); if(ctx.l){ - expect(val).to.be('-128.5'); + expect(val).to.be('-128.5'); } else { - expect(val).to.eql('f-128.5'); + expect(val).to.eql('f-128.5'); } ctx.l++; if(ctx.l){ done() } @@ -5914,7 +5892,7 @@ describe('Gun', function(){ },300); }); - it.only("FILT ER FILTER", function(done){ + it("FILT ER FILTER", function(done){ var g = Gun(); var a = gun.put({}); var b = gun.put({age: 19, name: "bob"}); @@ -5942,7 +5920,7 @@ describe('Gun', function(){ } }); }); - + it("map path", function(done){ var gun = Gun(); var g = gun.get('map/path/ing'); @@ -5967,7 +5945,7 @@ describe('Gun', function(){ }); g.put({a: {x:{y:1}}, b: {x:{y:2}}, c: {x:{y:3}}}); }); - + it("put path deep val -> path val", function(done){ // Terje's bug var gun = Gun(); gun.put({you: {have: {got: {to: {be: {kidding: "me!"}}}}}}).path('you.have.got.to.be').val(function(val, field){ @@ -5978,7 +5956,7 @@ describe('Gun', function(){ }); }); }); - + it("get set path put, map path val -> path val", function(done){ // Terje's bug var gun = Gun(); var ctx = {l: -1, d: 0}; @@ -6027,7 +6005,7 @@ describe('Gun', function(){ gun.put({history: put}); }, 1); }); - + it('path rel should not slowdown', function(done){ this.timeout(5000); var gun = Gun(/*gopt*/).put({ @@ -6138,22 +6116,22 @@ describe('Gun', function(){ it("gun get on, later gun put key", function(done){ var gun = Gun(); - - var keyC = gun.get('keyC').on(function(val){ + + var keyC = gun.get('keyC').on(function(val){ expect(val.hello).to.be('world'); if(done.done){ return } done.done = true; done(); }); - + setTimeout(function(){ gun.put({hello: 'world'}).key('keyC'); }, 100); }); - it('gun get put, sub path put, original val', function(done){ // bug from Jesse working on Trace // + it('gun get put, sub path put, original val', function(done){ // bug from Jesse working on Trace // var gun = Gun(gopt).get('players'); - + gun.put({ taken: true, history: {0: {}, 1: {}} @@ -6165,7 +6143,7 @@ describe('Gun', function(){ .back .path('taken') .put(false) - + // TODO: BUG! There is a variation of this, where we just do `.val` rather than `gun.val` and `.val` by itself (chained off of the sub-paths) doesn't even get called. :( gun.on(function(players){ // this val is subscribed to the original put and therefore does not get any of the sub-path listeners, therefore it gets called EARLY with the original/old data rather than waiting for the sub-path data to "finish" and then get called. expect(players.history).to.be(null); @@ -6204,7 +6182,7 @@ describe('Gun', function(){ put(1000); put(5000);*/ put(1000, true); - + var gun2 = Gun(); gun2.__.opt.wire.put = null; function put2(num, t) { @@ -6237,7 +6215,7 @@ describe('Gun', function(){ } ); it('choke time.now by using a while loop', function(){ - var i = 10; //100000; // causes an overflow. + var i = 10; //100000; // causes an overflow. while(--i){ Gun.time.now(); } @@ -6263,7 +6241,7 @@ describe('Gun', function(){ }); it("test assignment", function(done){ var env = {graph: {}}; - function speed(other){ + function speed(other){ var i = 10000; while(i--){ var $ = {soul: Gun.text.random()}; @@ -6304,7 +6282,7 @@ describe('Gun', function(){ }); it("gun put recursive path slowdown MUTANT TEST", function(done){ this.timeout(30000); - + Gun.chain.put = function(val, cb, opt){ var gun = this.chain(), obj; var drift = Gun.time.now(), call = {}; @@ -6312,7 +6290,7 @@ describe('Gun', function(){ gun._.at('soul').event( //( function($){ - var chain = $.gun || gun; + var chain = $.gun || gun; var ctx = {}, obj = val, $ = Gun.obj.copy($); var hash = $.field? $.soul + $.field : ($.from? $.from + ($.at || '') : $.soul); if(call[hash]){ return } @@ -6392,7 +6370,7 @@ describe('Gun', function(){ gun._.at('soul').emit({soul: Gun.roulette.call(gun), field: null, empty: true}); return gun; } - + var gun = Gun(); //.get('bug').put({}); gun.__.opt.hooks.put = null; function put(num, t) { @@ -6413,7 +6391,7 @@ describe('Gun', function(){ } return new Date().getTime() - now; } - + //put(1, true); //put(2); //put(10); @@ -6453,7 +6431,7 @@ describe('Gun', function(){ var gun = Gun(); var data = gun.get('some/not/yet/set/put/thing/2'); var path = data.path('sub'); - function put(d, t, f){ + function put(d, t, f){ setTimeout(function(){ path.put(d, function(err, ok){ expect(err).to.not.be.ok(); @@ -6542,7 +6520,7 @@ describe('Gun', function(){ expect(Gun.val.rel.is(p[2])).to.be.ok(); expect(Gun.val.rel.is(p[3])).to.be.ok(); }) - + var players = [], me; gun.map(function (player, number) { players[number] = player; @@ -6557,7 +6535,7 @@ describe('Gun', function(){ me = number; } }); - + Gun.list.map([0, 1, 2, 3], function (player, number) { number = number - 1; gun @@ -6574,7 +6552,7 @@ describe('Gun', function(){ }); }); }); - + it("gun get path empty val", function(done){ // flip flop bug done.c = 0; var u; @@ -6594,7 +6572,7 @@ describe('Gun', function(){ me.put({x: 0, y: 0}); },10); }); - + it("gun get path empty on", function(done){ done.c = 0; var u; @@ -6605,7 +6583,7 @@ describe('Gun', function(){ expect(done.fail).to.not.be.ok(); expect(val).to.not.be(u); if(done.done || !val.x || !val.y){ return } // it is okay if ON gets called many times, this protects against that. - // TODO: although it would be nice if we could minimize the amount of duplications. (may not happen to after 1.0.0) + // TODO: although it would be nice if we could minimize the amount of duplications. (may not happen to after 1.0.0) expect(val.x).to.be(1); expect(val.y).to.be(1); done.done = true; @@ -6617,7 +6595,7 @@ describe('Gun', function(){ me.put({x: 1, y: 1}); },10); }); - + it("gun get path empty not", function(done){ var u; var gun = Gun(gopt).opt({init: true}) @@ -6627,7 +6605,7 @@ describe('Gun', function(){ done(); }); }); - + it("gun get path empty init", function(done){ var u; var gun = Gun(gopt).opt({init: true}); @@ -6647,7 +6625,7 @@ describe('Gun', function(){ } }}).get('example/todo/data/graph'); gun.on(function renderToDo(val){ - done.on = true; + done.on = true; }); setTimeout(function(){ gun.path(Gun.text.random()).put('hoorah'); @@ -6678,7 +6656,7 @@ describe('Gun', function(){ },100); }); /* // This test didn't work for what I was wanting to test :(, will either remove it or modify it if I think of a clever solution to test what I want to test. - it.only("simulate json app", function(done){ + it("simulate json app", function(done){ var peers = {}; peers.server = Gun(); function wipeServer(){ @@ -7108,21 +7086,21 @@ describe('Gun', function(){ // 0: fluffy // 1: fluff // 3: bacon - // 9: `.not` + // 9: `.not` depp.path('spouse.pet.name').val().on(log); // 0: fluffy // 1: fluff */ }); - + describe('Streams', function(){ console.log("TODO: BUG! Upgrade UNION tests to new internal API!"); return; var gun = Gun(), g = function(){ return Gun({wire: {get: ctx.get}}); }, ctx = {gen: 9, extra: 100, network: 2}; - + it('prep hook', function(done){ this.timeout(ctx.gen * ctx.extra); var peer = Gun(), ref; @@ -7169,7 +7147,7 @@ describe('Gun', function(){ } if(obj.go){ done.b = obj.go; - expect(obj.go).to.be('dear'); + expect(obj.go).to.be('dear'); } if(obj.sir){ done.c = obj.sir; @@ -7180,7 +7158,7 @@ describe('Gun', function(){ } }); }); - + it('map chain path', function(done){ var set = gun.put({ a: {name: "Mark", @@ -7189,7 +7167,7 @@ describe('Gun', function(){ pet: {coat: "calico", name: "Cali"} }, c: {name: "Bob", pet: {coat: "tux", name: "Casper"} - } + } }); set.map().path('pet').val(function(obj, field){ if(obj.name === 'Hobbes'){ @@ -7212,14 +7190,14 @@ describe('Gun', function(){ } }); }); - + it('get big on', function(done){ this.timeout(ctx.gen * ctx.extra); var test = {c: 0, last: 0}; g().get('big').on(function(val){ if(test.done){ return console.log("hey yo! you got duplication on your ons!"); } delete val._; - if(val['f' + (test.last + 1)]){ + if(val['f' + (test.last + 1)]){ test.c += 1; test.last += 1; } @@ -7265,7 +7243,7 @@ describe('Gun', function(){ done(); }); }); - + it('get big map val', function(done){ this.timeout(ctx.gen * ctx.extra); var test = {c: 0, seen: {}}; @@ -7280,7 +7258,7 @@ describe('Gun', function(){ } }); }); - + it('val emits all data', function(done){ // bug in chat app var chat = Gun().get('example/chat/data').not(function(){ this.put({1: {who: 'Welcome', what: "to the chat app!", when: 0}}).key('example/chat/data'); @@ -7291,7 +7269,7 @@ describe('Gun', function(){ chat.put({random4: {who: 'mark', what: "4", when: 4}}); chat.put({random5: {who: 'mark', what: "5", when: 5}}); var seen = {1: false, 2: false, 3: false, 4: false, 5: false} - setTimeout(function(){ + setTimeout(function(){ chat.map(function(m){ }).val(function(msg, field){ var msg = Gun.obj.copy(msg); if(msg.what){