fixed some tests, lint, better run-scripts
This commit is contained in:
parent
2a601ac6f6
commit
6f3a291ef5
@ -125,7 +125,7 @@ gulp.task('dev:browser', ['build:test'], function () {
|
||||
gulp.watch('src/**/*.js', ['build:test'])
|
||||
|
||||
gulp.src(files.test)
|
||||
.pipe(watch('build/**/*.js'))
|
||||
.pipe(watch(['build/**/*.js']))
|
||||
.pipe(jasmineBrowser.specRunner())
|
||||
.pipe(jasmineBrowser.server({port: options.testport}))
|
||||
})
|
||||
|
@ -4,9 +4,9 @@
|
||||
"description": "A framework for real-time p2p shared editing on arbitrary complex data types",
|
||||
"main": "y.js",
|
||||
"scripts": {
|
||||
"test": "gulp test",
|
||||
"lint": "standard",
|
||||
"build": "gulp build"
|
||||
"test": "./node_modules/.bin/gulp test",
|
||||
"lint": "./node_modules/.bin/standard",
|
||||
"build": "./node_modules/.bin/standard build"
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint",
|
||||
|
@ -17,7 +17,7 @@ g.g = g
|
||||
|
||||
function wait (t) {
|
||||
if (t == null) {
|
||||
t = 10
|
||||
t = 5
|
||||
}
|
||||
var def = Promise.defer()
|
||||
setTimeout(function () {
|
||||
@ -106,9 +106,9 @@ g.compareAllUsers = async(function * compareAllUsers (users) { //eslint-disable-
|
||||
}
|
||||
yield users[0].connector.flushAll()
|
||||
yield g.garbageCollectAllUsers(users)
|
||||
yield wait(200)
|
||||
yield wait(50)
|
||||
yield g.garbageCollectAllUsers(users)
|
||||
yield wait(200)
|
||||
yield wait(50)
|
||||
for (var uid = 0; uid < users.length; uid++) {
|
||||
var u = users[uid]
|
||||
// compare deleted ops against deleteStore
|
||||
@ -202,4 +202,4 @@ function async (makeGenerator) {
|
||||
}
|
||||
}
|
||||
}
|
||||
g.wrapCo = async
|
||||
g.async = async
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
class AbstractTransaction { // eslint-disable-line no-unused-vars
|
||||
class AbstractTransaction {
|
||||
constructor (store) {
|
||||
this.store = store
|
||||
}
|
||||
|
@ -207,7 +207,9 @@ class RBTree { // eslint-disable-line no-unused-vars
|
||||
o_['id[1]'] = id[1]
|
||||
os.push(o_)
|
||||
})
|
||||
console.table(os)
|
||||
if (console.table != null) {
|
||||
console.table(os)
|
||||
}
|
||||
}
|
||||
find (id) {
|
||||
return this.findNode(id).val
|
||||
|
@ -27,14 +27,14 @@ var Struct = {
|
||||
return op
|
||||
},
|
||||
requiredOps: function (op) {
|
||||
return [] // [op.target]
|
||||
return [op.target]
|
||||
},
|
||||
execute: function * (op) {
|
||||
// console.log('Delete', op, console.trace())
|
||||
var target = yield* this.getOperation(op.target)
|
||||
if (target != null && !target.deleted) {
|
||||
target.deleted = true
|
||||
if (target.left === null || (yield* this.getOperation(target.left)).deleted) {
|
||||
if (target.left !== null && (yield* this.getOperation(target.left)).deleted) {
|
||||
this.store.addToGarbageCollector(target.id)
|
||||
target.gc = true
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, wrapCo, garbageCollectAllUsers */
|
||||
/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, async, garbageCollectAllUsers */
|
||||
/* eslint-env browser,jasmine */
|
||||
|
||||
var numberOfYArrayTests = 5
|
||||
var numberOfYArrayTests = 10
|
||||
|
||||
describe('Array Type', function () {
|
||||
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100
|
||||
beforeEach(wrapCo(function * (done) {
|
||||
beforeEach(async(function * (done) {
|
||||
yield createUsers(this, 3)
|
||||
y1 = (yconfig1 = this.users[0]).root
|
||||
y2 = (yconfig2 = this.users[1]).root
|
||||
y3 = (yconfig3 = this.users[2]).root
|
||||
flushAll = this.users[0].connector.flushAll
|
||||
yield wait(100)
|
||||
yield wait(10)
|
||||
done()
|
||||
}))
|
||||
afterEach(wrapCo(function * (done) {
|
||||
afterEach(async(function * (done) {
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
|
||||
describe('Basic tests', function () {
|
||||
it('insert three elements, try re-get property', wrapCo(function * (done) {
|
||||
it('insert three elements, try re-get property', async(function * (done) {
|
||||
var array = yield y1.set('Array', Y.Array)
|
||||
array.insert(0, [1, 2, 3])
|
||||
array = yield y1.get('Array') // re-get property
|
||||
expect(array.toArray()).toEqual([1, 2, 3])
|
||||
done()
|
||||
}))
|
||||
it('Basic insert in array (handle three conflicts)', wrapCo(function * (done) {
|
||||
it('Basic insert in array (handle three conflicts)', async(function * (done) {
|
||||
yield y1.set('Array', Y.Array)
|
||||
yield flushAll()
|
||||
var l1 = yield y1.get('Array')
|
||||
@ -43,7 +43,7 @@ describe('Array Type', function () {
|
||||
expect(l2.toArray()).toEqual(l3.toArray())
|
||||
done()
|
||||
}))
|
||||
it('Basic insert&delete in array (handle three conflicts)', wrapCo(function * (done) {
|
||||
it('Basic insert&delete in array (handle three conflicts)', async(function * (done) {
|
||||
var l1, l2, l3
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y', 'z'])
|
||||
@ -60,7 +60,7 @@ describe('Array Type', function () {
|
||||
expect(l2.toArray()).toEqual([0, 2, 'y'])
|
||||
done()
|
||||
}))
|
||||
it('Handles getOperations ascending ids bug in late sync', wrapCo(function * (done) {
|
||||
it('Handles getOperations ascending ids bug in late sync', async(function * (done) {
|
||||
var l1, l2
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y'])
|
||||
@ -79,7 +79,7 @@ describe('Array Type', function () {
|
||||
expect(l1.toArray()).toEqual(l2.toArray())
|
||||
done()
|
||||
}))
|
||||
it('Handles deletions in late sync', wrapCo(function * (done) {
|
||||
it('Handles deletions in late sync', async(function * (done) {
|
||||
var l1, l2
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y'])
|
||||
@ -96,21 +96,18 @@ describe('Array Type', function () {
|
||||
expect(l1.toArray()).toEqual(l2.toArray())
|
||||
done()
|
||||
}))
|
||||
it('Handles deletions in late sync (2)', wrapCo(function * (done) {
|
||||
it('Handles deletions in late sync (2)', async(function * (done) {
|
||||
var l1, l2
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
yield flushAll()
|
||||
l2 = yield y2.get('Array')
|
||||
l1.insert(0, ['x', 'y'])
|
||||
l1.delete(0, 2)
|
||||
yield wait()
|
||||
yield flushAll()
|
||||
yield wait()
|
||||
expect(l1.toArray()).toEqual(l2.toArray())
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Basic insert. Then delete the whole array', wrapCo(function * (done) {
|
||||
it('Basic insert. Then delete the whole array', async(function * (done) {
|
||||
var l1, l2, l3
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y', 'z'])
|
||||
@ -124,7 +121,7 @@ describe('Array Type', function () {
|
||||
expect(l2.toArray()).toEqual([])
|
||||
done()
|
||||
}))
|
||||
it('Basic insert. Then delete the whole array (merge listeners on late sync)', wrapCo(function * (done) {
|
||||
it('Basic insert. Then delete the whole array (merge listeners on late sync)', async(function * (done) {
|
||||
var l1, l2, l3
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y', 'z'])
|
||||
@ -142,7 +139,7 @@ describe('Array Type', function () {
|
||||
expect(l2.toArray()).toEqual([])
|
||||
done()
|
||||
}))
|
||||
it('Basic insert. Then delete the whole array (merge deleter on late sync)', wrapCo(function * (done) {
|
||||
it('Basic insert. Then delete the whole array (merge deleter on late sync)', async(function * (done) {
|
||||
var l1, l2, l3
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y', 'z'])
|
||||
@ -150,9 +147,7 @@ describe('Array Type', function () {
|
||||
yconfig1.disconnect()
|
||||
l1.delete(0, 3)
|
||||
l2 = yield y2.get('Array')
|
||||
yield wait()
|
||||
yconfig1.reconnect()
|
||||
yield wait()
|
||||
l3 = yield y3.get('Array')
|
||||
yield flushAll()
|
||||
expect(l1.toArray()).toEqual(l2.toArray())
|
||||
@ -160,7 +155,7 @@ describe('Array Type', function () {
|
||||
expect(l2.toArray()).toEqual([])
|
||||
done()
|
||||
}))
|
||||
it('throw insert & delete events', wrapCo(function * (done) {
|
||||
it('throw insert & delete events', async(function * (done) {
|
||||
var array = yield this.users[0].root.set('array', Y.Array)
|
||||
var event
|
||||
array.observe(function (e) {
|
||||
@ -183,7 +178,7 @@ describe('Array Type', function () {
|
||||
yield wait(50)
|
||||
done()
|
||||
}))
|
||||
it('garbage collects', wrapCo(function * (done) {
|
||||
it('garbage collects', async(function * (done) {
|
||||
var l1, l2, l3
|
||||
l1 = yield y1.set('Array', Y.Array)
|
||||
l1.insert(0, ['x', 'y', 'z'])
|
||||
@ -201,7 +196,6 @@ describe('Array Type', function () {
|
||||
expect(l1.toArray()).toEqual(l2.toArray())
|
||||
expect(l2.toArray()).toEqual(l3.toArray())
|
||||
expect(l2.toArray()).toEqual([])
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
})
|
||||
@ -228,7 +222,7 @@ describe('Array Type', function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
beforeEach(wrapCo(function * (done) {
|
||||
beforeEach(async(function * (done) {
|
||||
yield this.users[0].root.set('Array', Y.Array)
|
||||
yield flushAll()
|
||||
|
||||
@ -239,11 +233,11 @@ describe('Array Type', function () {
|
||||
this.arrays = yield Promise.all(promises)
|
||||
done()
|
||||
}))
|
||||
it('arrays.length equals users.length', wrapCo(function * (done) { // eslint-disable-line
|
||||
it('arrays.length equals users.length', async(function * (done) { // eslint-disable-line
|
||||
expect(this.arrays.length).toEqual(this.users.length)
|
||||
done()
|
||||
}))
|
||||
it(`succeed after ${numberOfYArrayTests} actions`, wrapCo(function * (done) {
|
||||
it(`succeed after ${numberOfYArrayTests} actions`, async(function * (done) {
|
||||
for (var u of this.users) {
|
||||
u.connector.debug = true
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, wrapCo */
|
||||
/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, async */
|
||||
/* eslint-env browser,jasmine */
|
||||
|
||||
var numberOfYMapTests = 5
|
||||
@ -7,7 +7,7 @@ describe('Map Type', function () {
|
||||
var y1, y2, y3, y4, flushAll
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000
|
||||
beforeEach(wrapCo(function * (done) {
|
||||
beforeEach(async(function * (done) {
|
||||
yield createUsers(this, 5)
|
||||
y1 = this.users[0].root
|
||||
y2 = this.users[1].root
|
||||
@ -16,13 +16,13 @@ describe('Map Type', function () {
|
||||
flushAll = this.users[0].connector.flushAll
|
||||
done()
|
||||
}))
|
||||
afterEach(wrapCo(function * (done) {
|
||||
afterEach(async(function * (done) {
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}), 5000)
|
||||
|
||||
describe('Basic tests', function () {
|
||||
it('Basic get&set of Map property (converge via sync)', wrapCo(function * (done) {
|
||||
it('Basic get&set of Map property (converge via sync)', async(function * (done) {
|
||||
y1.set('stuff', 'stuffy')
|
||||
expect(y1.get('stuff')).toEqual('stuffy')
|
||||
yield flushAll()
|
||||
@ -30,26 +30,23 @@ describe('Map Type', function () {
|
||||
var u = this.users[key].root
|
||||
expect(u.get('stuff')).toEqual('stuffy')
|
||||
}
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Map can set custom types (Map)', wrapCo(function * (done) {
|
||||
it('Map can set custom types (Map)', async(function * (done) {
|
||||
var map = yield y1.set('Map', Y.Map)
|
||||
map.set('one', 1)
|
||||
map = yield y1.get('Map')
|
||||
expect(map.get('one')).toEqual(1)
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Map can set custom types (Array)', wrapCo(function * (done) {
|
||||
it('Map can set custom types (Array)', async(function * (done) {
|
||||
var array = yield y1.set('Array', Y.Array)
|
||||
array.insert(0, [1, 2, 3])
|
||||
array = yield y1.get('Array')
|
||||
expect(array.toArray()).toEqual([1, 2, 3])
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Basic get&set of Map property (converge via update)', wrapCo(function * (done) {
|
||||
it('Basic get&set of Map property (converge via update)', async(function * (done) {
|
||||
yield flushAll()
|
||||
y1.set('stuff', 'stuffy')
|
||||
expect(y1.get('stuff')).toEqual('stuffy')
|
||||
@ -61,10 +58,9 @@ describe('Map Type', function () {
|
||||
}
|
||||
done()
|
||||
}))
|
||||
it('Basic get&set of Map property (handle conflict)', wrapCo(function * (done) {
|
||||
it('Basic get&set of Map property (handle conflict)', async(function * (done) {
|
||||
yield flushAll()
|
||||
y1.set('stuff', 'c0')
|
||||
|
||||
y2.set('stuff', 'c1')
|
||||
|
||||
yield flushAll()
|
||||
@ -72,10 +68,9 @@ describe('Map Type', function () {
|
||||
var u = this.users[key]
|
||||
expect(u.root.get('stuff')).toEqual('c0')
|
||||
}
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Basic get&set&delete of Map property (handle conflict)', wrapCo(function * (done) {
|
||||
it('Basic get&set&delete of Map property (handle conflict)', async(function * (done) {
|
||||
yield flushAll()
|
||||
y1.set('stuff', 'c0')
|
||||
y1.delete('stuff')
|
||||
@ -86,10 +81,9 @@ describe('Map Type', function () {
|
||||
var u = this.users[key]
|
||||
expect(u.root.get('stuff')).toBeUndefined()
|
||||
}
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Basic get&set of Map property (handle three conflicts)', wrapCo(function * (done) {
|
||||
it('Basic get&set of Map property (handle three conflicts)', async(function * (done) {
|
||||
yield flushAll()
|
||||
y1.set('stuff', 'c0')
|
||||
y2.set('stuff', 'c1')
|
||||
@ -101,10 +95,9 @@ describe('Map Type', function () {
|
||||
var u = this.users[key]
|
||||
expect(u.root.get('stuff')).toEqual('c0')
|
||||
}
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('Basic get&set&delete of Map property (handle three conflicts)', wrapCo(function * (done) {
|
||||
it('Basic get&set&delete of Map property (handle three conflicts)', async(function * (done) {
|
||||
yield flushAll()
|
||||
y1.set('stuff', 'c0')
|
||||
y2.set('stuff', 'c1')
|
||||
@ -122,10 +115,9 @@ describe('Map Type', function () {
|
||||
var u = this.users[key]
|
||||
expect(u.root.get('stuff')).toBeUndefined()
|
||||
}
|
||||
yield compareAllUsers(this.users)
|
||||
done()
|
||||
}))
|
||||
it('throws add & update & delete events (with type and primitive content)', wrapCo(function * (done) {
|
||||
it('throws add & update & delete events (with type and primitive content)', async(function * (done) {
|
||||
var event
|
||||
yield flushAll()
|
||||
y1.observe(function (e) {
|
||||
@ -186,7 +178,7 @@ describe('Map Type', function () {
|
||||
}
|
||||
}
|
||||
}
|
||||
beforeEach(wrapCo(function * (done) {
|
||||
beforeEach(async(function * (done) {
|
||||
yield y1.set('Map', Y.Map)
|
||||
yield flushAll()
|
||||
|
||||
@ -197,7 +189,7 @@ describe('Map Type', function () {
|
||||
this.maps = yield Promise.all(promises)
|
||||
done()
|
||||
}))
|
||||
it(`succeed after ${numberOfYMapTests} actions`, wrapCo(function * (done) {
|
||||
it(`succeed after ${numberOfYMapTests} actions`, async(function * (done) {
|
||||
yield applyRandomTransactions(this.users, this.maps, randomMapTransactions, numberOfYMapTests)
|
||||
yield flushAll()
|
||||
yield compareMapValues(this.maps)
|
||||
|
Loading…
x
Reference in New Issue
Block a user