From 6f3a291ef543d79bcd78e9f9328a55c9e1a3be8a Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Wed, 16 Sep 2015 16:25:30 +0200 Subject: [PATCH] fixed some tests, lint, better run-scripts --- gulpfile.js | 2 +- package.json | 6 ++-- src/Helper.spec.js | 8 +++--- src/OperationStore.js | 2 +- src/OperationStores/RedBlackTree.js | 4 ++- src/Struct.js | 4 +-- src/Types/Array.spec.js | 44 +++++++++++++---------------- src/Types/Map.spec.js | 36 +++++++++-------------- 8 files changed, 47 insertions(+), 59 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fb93bb36..a79a8245 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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})) }) diff --git a/package.json b/package.json index d7dc1ed5..c2e83993 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Helper.spec.js b/src/Helper.spec.js index 4fd7e903..d60f0bb8 100644 --- a/src/Helper.spec.js +++ b/src/Helper.spec.js @@ -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 diff --git a/src/OperationStore.js b/src/OperationStore.js index ef00145b..a872f1d1 100644 --- a/src/OperationStore.js +++ b/src/OperationStore.js @@ -2,7 +2,7 @@ 'use strict' -class AbstractTransaction { // eslint-disable-line no-unused-vars +class AbstractTransaction { constructor (store) { this.store = store } diff --git a/src/OperationStores/RedBlackTree.js b/src/OperationStores/RedBlackTree.js index 9885b967..2a679f0b 100644 --- a/src/OperationStores/RedBlackTree.js +++ b/src/OperationStores/RedBlackTree.js @@ -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 diff --git a/src/Struct.js b/src/Struct.js index 973ae5a7..c76f83ec 100644 --- a/src/Struct.js +++ b/src/Struct.js @@ -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 } diff --git a/src/Types/Array.spec.js b/src/Types/Array.spec.js index 7b27e6e3..9a0c3fa6 100644 --- a/src/Types/Array.spec.js +++ b/src/Types/Array.spec.js @@ -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 } diff --git a/src/Types/Map.spec.js b/src/Types/Map.spec.js index f4ade29b..aa23ba65 100644 --- a/src/Types/Map.spec.js +++ b/src/Types/Map.spec.js @@ -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)