Skip to content

Commit 5365ed8

Browse files
committed
Better tests when register object/classes
1 parent e399611 commit 5365ed8

File tree

5 files changed

+257
-254
lines changed

5 files changed

+257
-254
lines changed

package.json

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
11
{
2-
"name": "dop",
3-
"version": "0.28.0",
4-
"main": "./dist/dop.nodejs.js",
5-
"browser": "./dist/dop.js",
6-
"unpkg": "./dist/dop.min.js",
7-
"license": "MIT",
8-
"url": "http://www.distributedobjectprotocol.org",
9-
"repository": {
10-
"type": "git",
11-
"url": "git+https://github.com/DistributedObjectProtocol/dop.git"
12-
},
13-
"author": "Josema Gonzalez (http://josema.es/)",
14-
"description": "Distributed Object Protocol.",
15-
"keywords": [
16-
"realtime",
17-
"pubsub",
18-
"state management",
19-
"data-flow",
20-
"distributed",
21-
"objects",
22-
"protocol",
23-
"reactive",
24-
"sync",
25-
"synchronization",
26-
"rpc",
27-
"remote",
28-
"connect",
29-
"websocket",
30-
"events",
31-
"sockets",
32-
"xhr",
33-
"server",
34-
"client"
35-
],
36-
"dependencies": {
37-
"dop-transports": "^2.0.7"
38-
},
39-
"devDependencies": {
40-
"coveralls": "^2.11.4",
41-
"electron": "^1.4.12",
42-
"express": "^4.13.4",
43-
"faucet": "^0.0.1",
44-
"grunt": "^0.4.5",
45-
"grunt-cli": "^1.2.0",
46-
"grunt-contrib-concat": "^0.5.0",
47-
"grunt-contrib-copy": "^0.8.2",
48-
"grunt-contrib-uglify": "^0.6.0",
49-
"grunt-contrib-watch": "^0.6.1",
50-
"grunt-optimize-js": "^0.6.0",
51-
"grunt-replace": "^1.0.1",
52-
"grunt-string-replace": "^1.3.1",
53-
"js-combinatorics": "^0.5.2",
54-
"lodash.merge": "^4.6.0",
55-
"tap": "^7.1.2",
56-
"tape": "^4.6.3",
57-
"tape-run": "^2.1.4"
58-
},
59-
"scripts": {
60-
"dev": "grunt",
61-
"build": "grunt --build",
62-
"test": "tap test/**.js test/protocol/**.js",
63-
"test-proxy": "tap test/**.js test/protocol/**.js --test-arg=proxy",
64-
"test-electron": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\"",
65-
"test-chrome": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\" --browser chrome",
66-
"test-safari": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\" --browser safari",
67-
"test-firefox": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\" --browser firefox",
68-
"test-websockets": "tap test/protocol/**.js --test-arg=websockets",
69-
"test-socketio": "tap test/protocol/**.js --test-arg=socketio",
70-
"test-sockjs": "tap test/protocol/**.js --test-arg=sockjs",
71-
"test-local": "tap test/protocol/**.js --test-arg=local"
72-
}
2+
"name": "dop",
3+
"version": "0.28.1",
4+
"main": "./dist/dop.nodejs.js",
5+
"browser": "./dist/dop.js",
6+
"unpkg": "./dist/dop.min.js",
7+
"license": "MIT",
8+
"url": "http://www.distributedobjectprotocol.org",
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/DistributedObjectProtocol/dop.git"
12+
},
13+
"author": "Josema Gonzalez (http://josema.es/)",
14+
"description": "Distributed Object Protocol.",
15+
"keywords": [
16+
"realtime",
17+
"pubsub",
18+
"state management",
19+
"data-flow",
20+
"distributed",
21+
"objects",
22+
"protocol",
23+
"reactive",
24+
"sync",
25+
"synchronization",
26+
"rpc",
27+
"remote",
28+
"connect",
29+
"websocket",
30+
"events",
31+
"sockets",
32+
"xhr",
33+
"server",
34+
"client"
35+
],
36+
"dependencies": {
37+
"dop-transports": "^2.0.7"
38+
},
39+
"devDependencies": {
40+
"coveralls": "^2.11.4",
41+
"electron": "^1.4.12",
42+
"express": "^4.13.4",
43+
"faucet": "^0.0.1",
44+
"grunt": "^0.4.5",
45+
"grunt-cli": "^1.2.0",
46+
"grunt-contrib-concat": "^0.5.0",
47+
"grunt-contrib-copy": "^0.8.2",
48+
"grunt-contrib-uglify": "^0.6.0",
49+
"grunt-contrib-watch": "^0.6.1",
50+
"grunt-optimize-js": "^0.6.0",
51+
"grunt-replace": "^1.0.1",
52+
"grunt-string-replace": "^1.3.1",
53+
"js-combinatorics": "^0.5.2",
54+
"lodash.merge": "^4.6.0",
55+
"tap": "^7.1.2",
56+
"tape": "^4.6.3",
57+
"tape-run": "^2.1.4"
58+
},
59+
"scripts": {
60+
"dev": "grunt",
61+
"build": "grunt --build",
62+
"test": "tap test/**.js test/protocol/**.js",
63+
"test-proxy": "tap test/**.js test/protocol/**.js --test-arg=proxy",
64+
"test-electron": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\"",
65+
"test-chrome": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\" --browser chrome",
66+
"test-safari": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\" --browser safari",
67+
"test-firefox": "browserify test/protocol/*.js test/*.js | tape-run --render=\"faucet\" --browser firefox",
68+
"test-websockets": "tap test/protocol/**.js --test-arg=websockets",
69+
"test-socketio": "tap test/protocol/**.js --test-arg=socketio",
70+
"test-sockjs": "tap test/protocol/**.js --test-arg=sockjs",
71+
"test-local": "tap test/protocol/**.js --test-arg=local"
72+
}
7373
}

src/api/isObjectRegistrable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
dop.isObjectRegistrable = function(object) {
2-
return isObject(object)
2+
return isObject(object) && !isArray(object)
33
}

src/api/register.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dop.register = function(object) {
22
dop.util.invariant(
3-
dop.isObjectRegistrable(object) && !isArray(object),
4-
'dop.register needs an object or an array as first parameter'
3+
dop.isObjectRegistrable(object),
4+
'dop.register needs an object as first parameter'
55
)
66
return dop.isRegistered(object)
77
? dop.getObjectProxy(object)

test/register.js

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,76 @@
1-
var test = require('tape');
1+
var test = require('tape')
22
// require('tabe').createStream( test );
3-
var dop = require('./.proxy').create();
4-
var objectTarget = {deep1:{deep2:{}}}
5-
var object = dop.register(objectTarget);
3+
var dop = require('./.proxy').create()
4+
var objectTarget = { deep1: { deep2: {} } }
5+
var object = dop.register(objectTarget)
66

77
test('Object root', function(t) {
88
t.equal(dop.getObjectRoot(object), dop.getObjectProxy(object))
99
t.equal(dop.getObjectRoot(object.deep1), dop.getObjectProxy(object))
1010
t.equal(dop.getObjectRoot(object.deep1.deep2), dop.getObjectProxy(object))
11-
t.end();
12-
});
11+
t.end()
12+
})
1313

1414
test('Object parent', function(t) {
1515
t.equal(dop.getObjectParent(object), undefined)
1616
t.equal(dop.getObjectParent(object.deep1), dop.getObjectProxy(object))
17-
t.equal(dop.getObjectParent(object.deep1.deep2), dop.getObjectProxy(object.deep1))
18-
t.end();
19-
});
17+
t.equal(
18+
dop.getObjectParent(object.deep1.deep2),
19+
dop.getObjectProxy(object.deep1)
20+
)
21+
t.end()
22+
})
2023

2124
test('Object property', function(t) {
2225
t.equal(dop.getObjectProperty(object), 1)
2326
t.equal(dop.getObjectProperty(object.deep1), 'deep1')
2427
t.equal(dop.getObjectProperty(object.deep1.deep2), 'deep2')
25-
t.end();
26-
});
28+
t.end()
29+
})
2730

2831
test('Object proxy and target', function(t) {
2932
t.equal(dop.getObjectProxy(object), object)
3033
t.equal(dop.getObjectProxy(objectTarget), object)
3134
t.equal(dop.getObjectTarget(object), objectTarget)
3235
t.equal(dop.getObjectTarget(objectTarget), objectTarget)
33-
t.end();
34-
});
35-
36-
36+
t.end()
37+
})
3738

3839
test('Correct configuration on deleted neested object', function(t) {
3940
var object = dop.register({
4041
subobject: {
41-
name:"Josema",
42-
surname:"Gonzalez",
42+
name: 'Josema',
43+
surname: 'Gonzalez'
4344
}
4445
})
45-
var copy = object.subobject;
46+
var copy = object.subobject
4647
dop.del(object, 'subobject')
47-
dop.set(copy, "lol", {test:1234})
48+
dop.set(copy, 'lol', { test: 1234 })
4849
t.equal(dop.getObjectRoot(copy.lol), object)
4950
t.equal(dop.getObjectPath(copy.lol), undefined)
50-
t.deepEqual(dop.getObjectPath(copy.lol, false), [2, "subobject", "lol"])
51-
dop.set(object, "subobject", copy)
52-
t.deepEqual(dop.getObjectPath(copy.lol), [2, "subobject", "lol"])
53-
54-
t.end()
55-
});
51+
t.deepEqual(dop.getObjectPath(copy.lol, false), [2, 'subobject', 'lol'])
52+
dop.set(object, 'subobject', copy)
53+
t.deepEqual(dop.getObjectPath(copy.lol), [2, 'subobject', 'lol'])
5654

55+
t.end()
56+
})
5757

5858
test('register({})', function(t) {
5959
var o = dop.register({})
6060
t.equal(typeof o, 'object')
6161
t.end()
6262
})
6363

64-
6564
test('register(new Date)', function(t) {
66-
var o = dop.register(new Date)
65+
var o = dop.register(new Date())
6766
t.equal(typeof o, 'object')
6867
t.end()
6968
})
7069

7170
test('register([])', function(t) {
7271
try {
73-
var o = dop.register([])
74-
} catch(e) {
72+
var o = dop.register([])
73+
} catch (e) {
7574
t.equal(typeof e, 'object')
7675
t.end()
7776
}
@@ -83,7 +82,6 @@ test('register([])', function(t) {
8382
// prearr: {arr: [{a:1},{b:2},{c:3,subarr:[{d:4}]}]}
8483
// });
8584

86-
8785
// test('Level', function(t) {
8886
// t.equal(object["~DOP"].l, 1);
8987
// t.equal(object.subobject["~DOP"].l, 2);
@@ -112,16 +110,14 @@ test('register([])', function(t) {
112110
// t.equal(object.prearr.arr[2].subarr[0]["~DOP"].ia, true);
113111
// t.end();
114112

115-
116113
// dop.observe(object.subobject, function(){
117114
// console.log('changed', object.subobject.value)
118115
// })
119116

120117
// copy = object.subobject
121118
// object.subobject.value = 111
122-
// object.subobject = {value:'new'}
119+
// object.subobject = {value:'new'}
123120
// object.subobject.value = 222
124121
// copy.value = 222
125122

126123
// })
127-

0 commit comments

Comments
 (0)