diff --git a/examples/prosemirror-history.js b/examples/prosemirror-history.js index 33106b7d..d84f3fbf 100644 --- a/examples/prosemirror-history.js +++ b/examples/prosemirror-history.js @@ -3,8 +3,8 @@ import { Plugin } from 'prosemirror-state' import crel from 'crel' import * as Y from '../src/index.js' import { prosemirrorPluginKey } from 'y-prosemirror' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import * as historyProtocol from 'y-protocols/history.js' const niceColors = ['#3cb44b', '#4363d8', '#f58231', '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', '#008080', '#9a6324', '#800000', '#808000', '#000075', '#808080'] diff --git a/package.json b/package.json index 90d421b4..57b2197d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "module": "./dist/yjs.mjs'", "sideEffects": false, "scripts": { - "test": "npm run lint && npm run dist && node ./dist/tests.js --repitition-time 10000", + "test": "npm run lint && npm run dist && node ./dist/tests.js --repitition-time 50", + "test-exhaustive": "npm run lint && npm run dist && node ./dist/tests.js --repitition-time 10000", "dist": "rm -rf dist examples/build && PRODUCTION=1 rollup -c", "watch": "rollup -wc", "lint": "standard", diff --git a/rollup.config.js b/rollup.config.js index 803c4e7e..7fce1eea 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -56,7 +56,7 @@ export default [{ sourcemap: true, paths: path => { if (/^funlib\//.test(path)) { - return `funlib/dist${path.slice(6)}` + return `lib0/dist${path.slice(6)}` } return path } diff --git a/src/structs/Delete.js b/src/structs/Delete.js index 34698b2a..835dac09 100644 --- a/src/structs/Delete.js +++ b/src/structs/Delete.js @@ -5,8 +5,8 @@ import { getStructReference } from 'y-protocols/sync.js' import * as ID from '../utils/ID.js' import { writeStructToTransaction } from '../utils/structEncoding.js' -import * as decoding from 'funlib/decoding.js' -import * as encoding from 'funlib/encoding.js' +import * as decoding from 'lib0/decoding.js' +import * as encoding from 'lib0/encoding.js' // import { Item } from './Item.js' // eslint-disable-line // import { Y } from '../utils/Y.js' // eslint-disable-line import { deleteItemRange } from '../utils/structManipulation.js' diff --git a/src/structs/GC.js b/src/structs/GC.js index a7034fe4..4821c9da 100644 --- a/src/structs/GC.js +++ b/src/structs/GC.js @@ -5,8 +5,8 @@ import { getStructReference } from 'y-protocols/sync.js' import * as ID from '../utils/ID.js' import { writeStructToTransaction } from '../utils/structEncoding.js' -import * as decoding from 'funlib/decoding.js' -import * as encoding from 'funlib/encoding.js' +import * as decoding from 'lib0/decoding.js' +import * as encoding from 'lib0/encoding.js' // import { Y } from '../utils/Y.js' // eslint-disable-line // TODO should have the same base class as Item diff --git a/src/structs/Item.js b/src/structs/Item.js index 885fe397..80efc4c1 100644 --- a/src/structs/Item.js +++ b/src/structs/Item.js @@ -7,8 +7,8 @@ import * as ID from '../utils/ID.js' import { Delete } from './Delete.js' import { writeStructToTransaction } from '../utils/structEncoding.js' import { GC } from './GC.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' /** * @private diff --git a/src/structs/ItemBinary.js b/src/structs/ItemBinary.js index b3714c6e..165d125e 100644 --- a/src/structs/ItemBinary.js +++ b/src/structs/ItemBinary.js @@ -6,8 +6,8 @@ import { Item } from './Item.js' import * as stringify from 'y-protocols/utils/structStringify.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemBinary extends Item { diff --git a/src/structs/ItemEmbed.js b/src/structs/ItemEmbed.js index 551de984..1ad0fa5c 100644 --- a/src/structs/ItemEmbed.js +++ b/src/structs/ItemEmbed.js @@ -4,8 +4,8 @@ import { Item } from './Item.js' import * as stringify from 'y-protocols/utils/structStringify.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemEmbed extends Item { diff --git a/src/structs/ItemFormat.js b/src/structs/ItemFormat.js index d9472068..9f005f7e 100644 --- a/src/structs/ItemFormat.js +++ b/src/structs/ItemFormat.js @@ -4,8 +4,8 @@ import { Item } from './Item.js' import * as stringify from 'y-protocols/utils/structStringify.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemFormat extends Item { diff --git a/src/structs/ItemJSON.js b/src/structs/ItemJSON.js index 5ccdbaf2..88b976e8 100644 --- a/src/structs/ItemJSON.js +++ b/src/structs/ItemJSON.js @@ -4,8 +4,8 @@ import { Item, splitHelper } from './Item.js' import * as stringify from 'y-protocols/utils/structStringify.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemJSON extends Item { diff --git a/src/structs/ItemString.js b/src/structs/ItemString.js index 753be26f..84d2d850 100644 --- a/src/structs/ItemString.js +++ b/src/structs/ItemString.js @@ -4,8 +4,8 @@ import { Item, splitHelper } from './Item.js' import * as stringify from 'y-protocols/utils/structStringify.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line export class ItemString extends Item { diff --git a/src/types/YXmlElement.js b/src/types/YXmlElement.js index ee1225ed..0a73731e 100644 --- a/src/types/YXmlElement.js +++ b/src/types/YXmlElement.js @@ -3,8 +3,8 @@ */ import { YMap } from './YMap.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line import { YArray } from './YArray.js' import { YXmlEvent } from './YXmlEvent.js' diff --git a/src/types/YXmlHook.js b/src/types/YXmlHook.js index cb287ffd..e41c3536 100644 --- a/src/types/YXmlHook.js +++ b/src/types/YXmlHook.js @@ -3,8 +3,8 @@ */ import { YMap } from './YMap.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import { Y } from '../utils/Y.js' // eslint-disable-line /** diff --git a/src/utils/DeleteStore.js b/src/utils/DeleteStore.js index 355fbc73..f48c9534 100644 --- a/src/utils/DeleteStore.js +++ b/src/utils/DeleteStore.js @@ -2,7 +2,7 @@ * @module utils */ -import { Tree } from 'funlib/tree.js' +import { Tree } from 'lib0/tree.js' import * as ID from './ID.js' export class DSNode { diff --git a/src/utils/ID.js b/src/utils/ID.js index bb8d82fa..6548bd3b 100644 --- a/src/utils/ID.js +++ b/src/utils/ID.js @@ -3,8 +3,8 @@ */ import { getStructReference } from 'y-protocols/sync.js' -import * as decoding from 'funlib/decoding.js' -import * as encoding from 'funlib/encoding.js' +import * as decoding from 'lib0/decoding.js' +import * as encoding from 'lib0/encoding.js' export class ID { constructor (user, clock) { diff --git a/src/utils/OperationStore.js b/src/utils/OperationStore.js index a64300b1..04a6b6a6 100644 --- a/src/utils/OperationStore.js +++ b/src/utils/OperationStore.js @@ -2,7 +2,7 @@ * @module utils */ -import { Tree } from 'funlib/tree.js' +import { Tree } from 'lib0/tree.js' import * as ID from '../utils/ID.js' import { getStruct } from 'y-protocols/sync.js' import { GC } from '../structs/GC.js' diff --git a/src/utils/Transaction.js b/src/utils/Transaction.js index 269d7d07..3cea6b9d 100644 --- a/src/utils/Transaction.js +++ b/src/utils/Transaction.js @@ -2,7 +2,7 @@ * @module utils */ -import * as encoding from 'funlib/encoding.js' +import * as encoding from 'lib0/encoding.js' /** * A transaction is created for every change on the Yjs model. It is possible diff --git a/src/utils/Y.js b/src/utils/Y.js index 8079f44d..ec2f90e9 100644 --- a/src/utils/Y.js +++ b/src/utils/Y.js @@ -1,9 +1,9 @@ import { DeleteStore } from './DeleteStore.js' import { OperationStore } from './OperationStore.js' import { StateStore } from './StateStore.js' -import * as random from 'funlib/random.js' +import * as random from 'lib0/random.js' import { createRootID } from './ID.js' -import { Observable } from 'funlib/observable.js' +import { Observable } from 'lib0/observable.js' import { Transaction } from './Transaction.js' /** diff --git a/src/utils/integrateRemoteStructs.js b/src/utils/integrateRemoteStructs.js index 4b62a6d6..07f42851 100644 --- a/src/utils/integrateRemoteStructs.js +++ b/src/utils/integrateRemoteStructs.js @@ -3,7 +3,7 @@ */ import { getStruct } from 'y-protocols/sync.js' -import * as decoding from 'funlib/decoding.js' +import * as decoding from 'lib0/decoding.js' import { GC } from '../structs/GC.js' import { Y } from '../utils/Y.js' // eslint-disable-line import { Item } from '../structs/Item.js' // eslint-disable-line diff --git a/tests/DeleteStore.tests.js b/tests/DeleteStore.tests.js index 1e13d476..d947a11a 100644 --- a/tests/DeleteStore.tests.js +++ b/tests/DeleteStore.tests.js @@ -1,5 +1,5 @@ -import * as prng from 'funlib/prng.js' -import * as t from 'funlib/testing.js' +import * as prng from 'lib0/prng.js' +import * as t from 'lib0/testing.js' import { DeleteStore } from '../src/utils/DeleteStore.js' import * as ID from '../src/utils/ID.js' @@ -58,8 +58,8 @@ export const testRepeatDeleteStoreTests = tc => { const ds = new DeleteStore() const dsArray = [] for (let i = 0; i < 200; i++) { - const pos = prng.int32(gen, 0, 10) - const len = prng.int32(gen, 0, 4) + const pos = prng.int31(gen, 0, 10) + const len = prng.int31(gen, 0, 4) const gc = prng.bool(gen) ds.mark(ID.createID(0, pos), len, gc) for (let j = 0; j < len; j++) { @@ -72,7 +72,7 @@ export const testRepeatDeleteStoreTests = tc => { dsArray[i] = null } } - t.compareArrays(dsToArray(ds), dsArray, 'Expected DS result') + t.compareArrays(dsToArray(ds), dsArray) let size = 0 let lastEl = null for (let i = 0; i < dsArray.length; i++) { @@ -82,5 +82,5 @@ export const testRepeatDeleteStoreTests = tc => { } lastEl = el } - t.assert(size === ds.length, 'DS sizes match') + t.assert(size === ds.length) } diff --git a/tests/helper.js b/tests/helper.js index 4b76d359..d8235d86 100644 --- a/tests/helper.js +++ b/tests/helper.js @@ -5,11 +5,11 @@ import { ItemString } from '../src/structs/ItemString.js' import { defragmentItemContent } from '../src/utils/defragmentItemContent.js' import Quill from 'quill' import { GC } from '../src/structs/GC.js' -import * as random from 'funlib/prng.js' +import * as random from 'lib0/prng.js' import * as syncProtocol from 'y-protocols/sync.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' -import { createMutex } from 'funlib/mutex.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' +import { createMutex } from 'lib0/mutex.js' import { QuillBinding } from 'y-quill' import { DomBinding } from 'y-dom' diff --git a/tests/index.js b/tests/index.js index 25f10007..e0d0a09f 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,7 +1,7 @@ -import { runTests } from 'funlib/testing.js' -import { isBrowser } from 'funlib/environment.js' -import * as log from 'funlib/logging.js' +import { runTests } from 'lib0/testing.js' +import { isBrowser } from 'lib0/environment.js' +import * as log from 'lib0/logging.js' import * as deleteStore from './DeleteStore.tests.js' import * as array from './y-array.tests.js' diff --git a/tests/testHelper.js b/tests/testHelper.js index ff81e159..4683212f 100644 --- a/tests/testHelper.js +++ b/tests/testHelper.js @@ -1,9 +1,9 @@ import * as Y from '../src/index.js' -import * as t from 'funlib/testing.js' -import * as prng from 'funlib/prng.js' -import { createMutex } from 'funlib/mutex.js' -import * as encoding from 'funlib/encoding.js' -import * as decoding from 'funlib/decoding.js' +import * as t from 'lib0/testing.js' +import * as prng from 'lib0/prng.js' +import { createMutex } from 'lib0/mutex.js' +import * as encoding from 'lib0/encoding.js' +import * as decoding from 'lib0/decoding.js' import * as syncProtocol from 'y-protocols/sync.js' import { defragmentItemContent } from '../src/utils/defragmentItemContent.js' @@ -331,21 +331,19 @@ export const compare = users => { }) for (var i = 0; i < data.length - 1; i++) { // t.describe(`Comparing user${i} with user${i + 1}`) - t.compare(userArrayValues[i].length, users[i].get('array').length, 'array length correctly computed') - t.compare(userArrayValues[i], userArrayValues[i + 1], 'array types') - t.compare(userMapValues[i], userMapValues[i + 1], 'map types') - t.compare(userXmlValues[i], userXmlValues[i + 1], 'xml types') - t.compare(userTextValues[i].map(a => a.insert).join('').length, users[i].get('text').length, 'text length correctly computed') - t.compare(userTextValues[i], userTextValues[i + 1], 'text types') - t.compare(data[i].os, data[i + 1].os, 'os', customOSCompare) - t.compare(data[i].ds, data[i + 1].ds, 'ds', customOSCompare) - t.compare(data[i].ss, data[i + 1].ss, 'ss', customOSCompare) + t.compare(userArrayValues[i].length, users[i].get('array').length) + t.compare(userArrayValues[i], userArrayValues[i + 1]) + t.compare(userMapValues[i], userMapValues[i + 1]) + t.compare(userXmlValues[i], userXmlValues[i + 1]) + t.compare(userTextValues[i].map(a => a.insert).join('').length, users[i].get('text').length) + t.compare(userTextValues[i], userTextValues[i + 1]) + t.compare(data[i].os, data[i + 1].os, null, customOSCompare) + t.compare(data[i].ds, data[i + 1].ds, null, customOSCompare) + t.compare(data[i].ss, data[i + 1].ss, null, customOSCompare) } - users.forEach(user => { - if (user._missingStructs.size !== 0) { - t.fail('missing structs should be empty!') - } - }) + users.forEach(user => + t.assert(user._missingStructs.size === 0) + ) users.map(u => u.destroy()) } @@ -354,20 +352,20 @@ export const applyRandomTests = (tc, mods, iterations) => { const result = init({ users: 5, prng: gen }) const { testConnector, users } = result for (var i = 0; i < iterations; i++) { - if (prng.int32(gen, 0, 100) <= 2) { + if (prng.int31(gen, 0, 100) <= 2) { // 2% chance to disconnect/reconnect a random user if (prng.bool(gen)) { testConnector.disconnectRandom() } else { testConnector.reconnectRandom() } - } else if (prng.int32(gen, 0, 100) <= 1) { + } else if (prng.int31(gen, 0, 100) <= 1) { // 1% chance to flush all & garbagecollect // TODO: We do not gc all users as this does not work yet // await garbageCollectUsers(t, users) testConnector.flushAllMessages() // await users[0].db.emptyGarbageCollector() // TODO: reintroduce GC tests! - } else if (prng.int32(gen, 0, 100) <= 50) { + } else if (prng.int31(gen, 0, 100) <= 50) { // 50% chance to flush a random message testConnector.flushRandomMessage() } diff --git a/tests/y-array.tests.js b/tests/y-array.tests.js index fca47d4e..044bf8ac 100644 --- a/tests/y-array.tests.js +++ b/tests/y-array.tests.js @@ -1,18 +1,18 @@ import { init, compare, applyRandomTests } from './testHelper.js' import * as Y from '../src/index.js' -import * as t from 'funlib/testing.js' -import * as prng from 'funlib/prng.js' +import * as t from 'lib0/testing.js' +import * as prng from 'lib0/prng.js' export const testDeleteInsert = tc => { const { users, array0 } = init(tc, { users: 2 }) array0.delete(0, 0) - t.assert(true, 'Does not throw when deleting zero elements with position 0') + t.describe('Does not throw when deleting zero elements with position 0') t.fails(() => { array0.delete(1, 1) - }, 'Throws when deleting with an invalid position') + }) array0.insert(0, ['A']) array0.delete(1, 0) - t.assert(true, 'Does not throw when deleting zero elements with valid position 1') + t.describe('Does not throw when deleting zero elements with valid position 1') compare(users) } @@ -229,23 +229,23 @@ let arrayTransactions = [ const yarray = user.define('array', Y.Array) var uniqueNumber = getUniqueNumber() var content = [] - var len = prng.int32(gen, 1, 4) + var len = prng.int31(gen, 1, 4) for (var i = 0; i < len; i++) { content.push(uniqueNumber) } - var pos = prng.int32(gen, 0, yarray.length) + var pos = prng.int31(gen, 0, yarray.length) yarray.insert(pos, content) }, function insertTypeArray (t, user, gen) { const yarray = user.define('array', Y.Array) - var pos = prng.int32(gen, 0, yarray.length) + var pos = prng.int31(gen, 0, yarray.length) yarray.insert(pos, [Y.Array]) var array2 = yarray.get(pos) array2.insert(0, [1, 2, 3, 4]) }, function insertTypeMap (t, user, gen) { const yarray = user.define('array', Y.Array) - var pos = prng.int32(gen, 0, yarray.length) + var pos = prng.int31(gen, 0, yarray.length) yarray.insert(pos, [Y.Map]) var map = yarray.get(pos) map.set('someprop', 42) @@ -256,14 +256,14 @@ let arrayTransactions = [ const yarray = user.define('array', Y.Array) var length = yarray.length if (length > 0) { - var somePos = prng.int32(gen, 0, length - 1) - var delLength = prng.int32(gen, 1, Math.min(2, length - somePos)) + var somePos = prng.int31(gen, 0, length - 1) + var delLength = prng.int31(gen, 1, Math.min(2, length - somePos)) if (yarray instanceof Y.Array) { if (prng.bool(gen)) { var type = yarray.get(somePos) if (type.length > 0) { - somePos = prng.int32(gen, 0, type.length - 1) - delLength = prng.int32(gen, 0, Math.min(2, type.length - somePos)) + somePos = prng.int31(gen, 0, type.length - 1) + delLength = prng.int31(gen, 0, Math.min(2, type.length - somePos)) type.delete(somePos, delLength) } } else { diff --git a/tests/y-map.tests.js b/tests/y-map.tests.js index 805acb0d..4a1febcf 100644 --- a/tests/y-map.tests.js +++ b/tests/y-map.tests.js @@ -1,7 +1,7 @@ import { initArrays, compareUsers, applyRandomTests } from './helper.js' import * as Y from '../src/index.js' import { test, proxyConsole } from 'cutest' -import * as random from 'funlib/prng/prng.js' +import * as random from 'lib0/prng/prng.js' proxyConsole()