export testHelper esm properly
This commit is contained in:
parent
336f7b1b1d
commit
2ec19defcb
@ -5,6 +5,7 @@
|
|||||||
"main": "./dist/yjs.cjs",
|
"main": "./dist/yjs.cjs",
|
||||||
"module": "./dist/yjs.mjs",
|
"module": "./dist/yjs.mjs",
|
||||||
"types": "./dist/src/index.d.ts",
|
"types": "./dist/src/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"funding": {
|
"funding": {
|
||||||
"type": "GitHub Sponsors ❤",
|
"type": "GitHub Sponsors ❤",
|
||||||
@ -31,6 +32,7 @@
|
|||||||
},
|
},
|
||||||
"./src/index.js": "./src/index.js",
|
"./src/index.js": "./src/index.js",
|
||||||
"./tests/testHelper.js": "./tests/testHelper.js",
|
"./tests/testHelper.js": "./tests/testHelper.js",
|
||||||
|
"./testHelper": "./dist/testHelper.mjs",
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -60,6 +60,23 @@ export default [{
|
|||||||
sourcemap: true
|
sourcemap: true
|
||||||
},
|
},
|
||||||
external: id => /^lib0\//.test(id)
|
external: id => /^lib0\//.test(id)
|
||||||
|
}, {
|
||||||
|
input: './tests/testHelper.js',
|
||||||
|
output: {
|
||||||
|
name: 'Y',
|
||||||
|
file: 'dist/testHelper.mjs',
|
||||||
|
format: 'esm',
|
||||||
|
sourcemap: true
|
||||||
|
},
|
||||||
|
external: id => /^lib0\//.test(id) || id === 'yjs',
|
||||||
|
plugins: [{
|
||||||
|
resolveId (importee) {
|
||||||
|
if (importee === '../src/index.js') {
|
||||||
|
return 'yjs'
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}]
|
||||||
}, {
|
}, {
|
||||||
input: './tests/index.js',
|
input: './tests/index.js',
|
||||||
output: {
|
output: {
|
||||||
|
@ -27,12 +27,13 @@ export {
|
|||||||
ContentString,
|
ContentString,
|
||||||
ContentType,
|
ContentType,
|
||||||
AbstractType,
|
AbstractType,
|
||||||
RelativePosition,
|
|
||||||
getTypeChildren,
|
getTypeChildren,
|
||||||
createRelativePositionFromTypeIndex,
|
createRelativePositionFromTypeIndex,
|
||||||
createRelativePositionFromJSON,
|
createRelativePositionFromJSON,
|
||||||
createAbsolutePositionFromRelativePosition,
|
createAbsolutePositionFromRelativePosition,
|
||||||
compareRelativePositions,
|
compareRelativePositions,
|
||||||
|
AbsolutePosition,
|
||||||
|
RelativePosition,
|
||||||
ID,
|
ID,
|
||||||
createID,
|
createID,
|
||||||
compareIDs,
|
compareIDs,
|
||||||
@ -41,6 +42,7 @@ export {
|
|||||||
createSnapshot,
|
createSnapshot,
|
||||||
createDeleteSet,
|
createDeleteSet,
|
||||||
createDeleteSetFromStructStore,
|
createDeleteSetFromStructStore,
|
||||||
|
cleanupYTextFormatting,
|
||||||
snapshot,
|
snapshot,
|
||||||
emptySnapshot,
|
emptySnapshot,
|
||||||
findRootTypeKey,
|
findRootTypeKey,
|
||||||
|
@ -601,7 +601,7 @@ export const decodeStateVector = decodedState => readStateVector(new DSDecoderV1
|
|||||||
*/
|
*/
|
||||||
export const writeStateVector = (encoder, sv) => {
|
export const writeStateVector = (encoder, sv) => {
|
||||||
encoding.writeVarUint(encoder.restEncoder, sv.size)
|
encoding.writeVarUint(encoder.restEncoder, sv.size)
|
||||||
sv.forEach((clock, client) => {
|
Array.from(sv.entries()).sort((a, b) => b[0] - a[0]).forEach(([client, clock]) => {
|
||||||
encoding.writeVarUint(encoder.restEncoder, client) // @todo use a special client decoder that is based on mapping
|
encoding.writeVarUint(encoder.restEncoder, client) // @todo use a special client decoder that is based on mapping
|
||||||
encoding.writeVarUint(encoder.restEncoder, clock)
|
encoding.writeVarUint(encoder.restEncoder, clock)
|
||||||
})
|
})
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
import * as Y from '../src/internals'
|
import * as Y from '../src/index.js'
|
||||||
import * as t from 'lib0/testing'
|
import * as t from 'lib0/testing'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Y.YText} ytext
|
* @param {Y.Text} ytext
|
||||||
*/
|
*/
|
||||||
const checkRelativePositions = ytext => {
|
const checkRelativePositions = ytext => {
|
||||||
// test if all positions are encoded and restored correctly
|
// test if all positions are encoded and restored correctly
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import { createDocFromSnapshot, Doc, snapshot, YMap } from '../src/internals'
|
import * as Y from '../src/index.js'
|
||||||
import * as t from 'lib0/testing'
|
import * as t from 'lib0/testing'
|
||||||
import { init } from './testHelper'
|
import { init } from './testHelper.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testBasicRestoreSnapshot = tc => {
|
export const testBasicRestoreSnapshot = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
doc.getArray('array').insert(0, ['hello'])
|
doc.getArray('array').insert(0, ['hello'])
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
doc.getArray('array').insert(1, ['world'])
|
doc.getArray('array').insert(1, ['world'])
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray('array').toArray(), ['hello'])
|
t.compare(docRestored.getArray('array').toArray(), ['hello'])
|
||||||
t.compare(doc.getArray('array').toArray(), ['hello', 'world'])
|
t.compare(doc.getArray('array').toArray(), ['hello', 'world'])
|
||||||
@ -21,19 +21,19 @@ export const testBasicRestoreSnapshot = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testEmptyRestoreSnapshot = tc => {
|
export const testEmptyRestoreSnapshot = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
snap.sv.set(9999, 0)
|
snap.sv.set(9999, 0)
|
||||||
doc.getArray().insert(0, ['world'])
|
doc.getArray().insert(0, ['world'])
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray().toArray(), [])
|
t.compare(docRestored.getArray().toArray(), [])
|
||||||
t.compare(doc.getArray().toArray(), ['world'])
|
t.compare(doc.getArray().toArray(), ['world'])
|
||||||
|
|
||||||
// now this snapshot reflects the latest state. It shoult still work.
|
// now this snapshot reflects the latest state. It shoult still work.
|
||||||
const snap2 = snapshot(doc)
|
const snap2 = Y.snapshot(doc)
|
||||||
const docRestored2 = createDocFromSnapshot(doc, snap2)
|
const docRestored2 = Y.createDocFromSnapshot(doc, snap2)
|
||||||
t.compare(docRestored2.getArray().toArray(), ['world'])
|
t.compare(docRestored2.getArray().toArray(), ['world'])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,15 +41,15 @@ export const testEmptyRestoreSnapshot = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testRestoreSnapshotWithSubType = tc => {
|
export const testRestoreSnapshotWithSubType = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
doc.getArray('array').insert(0, [new YMap()])
|
doc.getArray('array').insert(0, [new Y.Map()])
|
||||||
const subMap = doc.getArray('array').get(0)
|
const subMap = doc.getArray('array').get(0)
|
||||||
subMap.set('key1', 'value1')
|
subMap.set('key1', 'value1')
|
||||||
|
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
subMap.set('key2', 'value2')
|
subMap.set('key2', 'value2')
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray('array').toJSON(), [{
|
t.compare(docRestored.getArray('array').toJSON(), [{
|
||||||
key1: 'value1'
|
key1: 'value1'
|
||||||
@ -64,13 +64,13 @@ export const testRestoreSnapshotWithSubType = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testRestoreDeletedItem1 = tc => {
|
export const testRestoreDeletedItem1 = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
doc.getArray('array').insert(0, ['item1', 'item2'])
|
doc.getArray('array').insert(0, ['item1', 'item2'])
|
||||||
|
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
doc.getArray('array').delete(0)
|
doc.getArray('array').delete(0)
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray('array').toArray(), ['item1', 'item2'])
|
t.compare(docRestored.getArray('array').toArray(), ['item1', 'item2'])
|
||||||
t.compare(doc.getArray('array').toArray(), ['item2'])
|
t.compare(doc.getArray('array').toArray(), ['item2'])
|
||||||
@ -80,15 +80,15 @@ export const testRestoreDeletedItem1 = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testRestoreLeftItem = tc => {
|
export const testRestoreLeftItem = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
doc.getArray('array').insert(0, ['item1'])
|
doc.getArray('array').insert(0, ['item1'])
|
||||||
doc.getMap('map').set('test', 1)
|
doc.getMap('map').set('test', 1)
|
||||||
doc.getArray('array').insert(0, ['item0'])
|
doc.getArray('array').insert(0, ['item0'])
|
||||||
|
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
doc.getArray('array').delete(1)
|
doc.getArray('array').delete(1)
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray('array').toArray(), ['item0', 'item1'])
|
t.compare(docRestored.getArray('array').toArray(), ['item0', 'item1'])
|
||||||
t.compare(doc.getArray('array').toArray(), ['item0'])
|
t.compare(doc.getArray('array').toArray(), ['item0'])
|
||||||
@ -98,13 +98,13 @@ export const testRestoreLeftItem = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testDeletedItemsBase = tc => {
|
export const testDeletedItemsBase = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
doc.getArray('array').insert(0, ['item1'])
|
doc.getArray('array').insert(0, ['item1'])
|
||||||
doc.getArray('array').delete(0)
|
doc.getArray('array').delete(0)
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
doc.getArray('array').insert(0, ['item0'])
|
doc.getArray('array').insert(0, ['item0'])
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray('array').toArray(), [])
|
t.compare(docRestored.getArray('array').toArray(), [])
|
||||||
t.compare(doc.getArray('array').toArray(), ['item0'])
|
t.compare(doc.getArray('array').toArray(), ['item0'])
|
||||||
@ -114,13 +114,13 @@ export const testDeletedItemsBase = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testDeletedItems2 = tc => {
|
export const testDeletedItems2 = tc => {
|
||||||
const doc = new Doc({ gc: false })
|
const doc = new Y.Doc({ gc: false })
|
||||||
doc.getArray('array').insert(0, ['item1', 'item2', 'item3'])
|
doc.getArray('array').insert(0, ['item1', 'item2', 'item3'])
|
||||||
doc.getArray('array').delete(1)
|
doc.getArray('array').delete(1)
|
||||||
const snap = snapshot(doc)
|
const snap = Y.snapshot(doc)
|
||||||
doc.getArray('array').insert(0, ['item0'])
|
doc.getArray('array').insert(0, ['item0'])
|
||||||
|
|
||||||
const docRestored = createDocFromSnapshot(doc, snap)
|
const docRestored = Y.createDocFromSnapshot(doc, snap)
|
||||||
|
|
||||||
t.compare(docRestored.getArray('array').toArray(), ['item1', 'item3'])
|
t.compare(docRestored.getArray('array').toArray(), ['item1', 'item3'])
|
||||||
t.compare(doc.getArray('array').toArray(), ['item0', 'item1', 'item3'])
|
t.compare(doc.getArray('array').toArray(), ['item0', 'item1', 'item3'])
|
||||||
@ -140,11 +140,11 @@ export const testDependentChanges = tc => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type Doc
|
* @type {Y.Doc}
|
||||||
*/
|
*/
|
||||||
const doc0 = array0.doc
|
const doc0 = array0.doc
|
||||||
/**
|
/**
|
||||||
* @type Doc
|
* @type {Y.Doc}
|
||||||
*/
|
*/
|
||||||
const doc1 = array1.doc
|
const doc1 = array1.doc
|
||||||
|
|
||||||
@ -156,16 +156,16 @@ export const testDependentChanges = tc => {
|
|||||||
array1.insert(1, ['user2item1'])
|
array1.insert(1, ['user2item1'])
|
||||||
testConnector.syncAll()
|
testConnector.syncAll()
|
||||||
|
|
||||||
const snap = snapshot(array0.doc)
|
const snap = Y.snapshot(array0.doc)
|
||||||
|
|
||||||
array0.insert(2, ['user1item2'])
|
array0.insert(2, ['user1item2'])
|
||||||
testConnector.syncAll()
|
testConnector.syncAll()
|
||||||
array1.insert(3, ['user2item2'])
|
array1.insert(3, ['user2item2'])
|
||||||
testConnector.syncAll()
|
testConnector.syncAll()
|
||||||
|
|
||||||
const docRestored0 = createDocFromSnapshot(array0.doc, snap)
|
const docRestored0 = Y.createDocFromSnapshot(array0.doc, snap)
|
||||||
t.compare(docRestored0.getArray('array').toArray(), ['user1item1', 'user2item1'])
|
t.compare(docRestored0.getArray('array').toArray(), ['user1item1', 'user2item1'])
|
||||||
|
|
||||||
const docRestored1 = createDocFromSnapshot(array1.doc, snap)
|
const docRestored1 = Y.createDocFromSnapshot(array1.doc, snap)
|
||||||
t.compare(docRestored1.getArray('array').toArray(), ['user1item1', 'user2item1'])
|
t.compare(docRestored1.getArray('array').toArray(), ['user1item1', 'user2item1'])
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@ import * as t from 'lib0/testing'
|
|||||||
import * as prng from 'lib0/prng'
|
import * as prng from 'lib0/prng'
|
||||||
import * as encoding from 'lib0/encoding'
|
import * as encoding from 'lib0/encoding'
|
||||||
import * as decoding from 'lib0/decoding'
|
import * as decoding from 'lib0/decoding'
|
||||||
import * as syncProtocol from 'y-protocols/sync.js'
|
import * as syncProtocol from 'y-protocols/sync'
|
||||||
import * as object from 'lib0/object'
|
import * as object from 'lib0/object'
|
||||||
import * as Y from '../src/internals.js'
|
import * as Y from '../src/index.js'
|
||||||
export * from '../src/internals.js'
|
export * from '../src/index.js'
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -279,7 +279,7 @@ export class TestConnector {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
* @param {{users?:number}} conf
|
* @param {{users?:number}} conf
|
||||||
* @param {InitTestObjectCallback<T>} [initTestObject]
|
* @param {InitTestObjectCallback<T>} [initTestObject]
|
||||||
* @return {{testObjects:Array<any>,testConnector:TestConnector,users:Array<TestYInstance>,array0:Y.YArray<any>,array1:Y.YArray<any>,array2:Y.YArray<any>,map0:Y.YMap<any>,map1:Y.YMap<any>,map2:Y.YMap<any>,map3:Y.YMap<any>,text0:Y.YText,text1:Y.YText,text2:Y.YText,xml0:Y.YXmlElement,xml1:Y.YXmlElement,xml2:Y.YXmlElement}}
|
* @return {{testObjects:Array<any>,testConnector:TestConnector,users:Array<TestYInstance>,array0:Y.Array<any>,array1:Y.Array<any>,array2:Y.Array<any>,map0:Y.Map<any>,map1:Y.Map<any>,map2:Y.Map<any>,map3:Y.Map<any>,text0:Y.Text,text1:Y.Text,text2:Y.Text,xml0:Y.XmlElement,xml1:Y.XmlElement,xml2:Y.XmlElement}}
|
||||||
*/
|
*/
|
||||||
export const init = (tc, { users = 5 } = {}, initTestObject) => {
|
export const init = (tc, { users = 5 } = {}, initTestObject) => {
|
||||||
/**
|
/**
|
||||||
@ -304,7 +304,7 @@ export const init = (tc, { users = 5 } = {}, initTestObject) => {
|
|||||||
result.users.push(y)
|
result.users.push(y)
|
||||||
result['array' + i] = y.getArray('array')
|
result['array' + i] = y.getArray('array')
|
||||||
result['map' + i] = y.getMap('map')
|
result['map' + i] = y.getMap('map')
|
||||||
result['xml' + i] = y.get('xml', Y.YXmlElement)
|
result['xml' + i] = y.get('xml', Y.XmlElement)
|
||||||
result['text' + i] = y.getText('text')
|
result['text' + i] = y.getText('text')
|
||||||
}
|
}
|
||||||
testConnector.syncAll()
|
testConnector.syncAll()
|
||||||
@ -335,7 +335,7 @@ export const compare = users => {
|
|||||||
users.push(.../** @type {any} */(mergedDocs))
|
users.push(.../** @type {any} */(mergedDocs))
|
||||||
const userArrayValues = users.map(u => u.getArray('array').toJSON())
|
const userArrayValues = users.map(u => u.getArray('array').toJSON())
|
||||||
const userMapValues = users.map(u => u.getMap('map').toJSON())
|
const userMapValues = users.map(u => u.getMap('map').toJSON())
|
||||||
const userXmlValues = users.map(u => u.get('xml', Y.YXmlElement).toString())
|
const userXmlValues = users.map(u => u.get('xml', Y.XmlElement).toString())
|
||||||
const userTextValues = users.map(u => u.getText('text').toDelta())
|
const userTextValues = users.map(u => u.getText('text').toDelta())
|
||||||
for (const u of users) {
|
for (const u of users) {
|
||||||
t.assert(u.store.pendingDs === null)
|
t.assert(u.store.pendingDs === null)
|
||||||
@ -370,7 +370,7 @@ export const compare = users => {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
t.compare(Y.getStateVector(users[i].store), Y.getStateVector(users[i + 1].store))
|
t.compare(Y.encodeStateVector(users[i]), Y.encodeStateVector(users[i + 1]))
|
||||||
compareDS(Y.createDeleteSetFromStructStore(users[i].store), Y.createDeleteSetFromStructStore(users[i + 1].store))
|
compareDS(Y.createDeleteSetFromStructStore(users[i].store), Y.createDeleteSetFromStructStore(users[i + 1].store))
|
||||||
compareStructStores(users[i].store, users[i + 1].store)
|
compareStructStores(users[i].store, users[i + 1].store)
|
||||||
}
|
}
|
||||||
@ -385,8 +385,8 @@ export const compare = users => {
|
|||||||
export const compareItemIDs = (a, b) => a === b || (a !== null && b != null && Y.compareIDs(a.id, b.id))
|
export const compareItemIDs = (a, b) => a === b || (a !== null && b != null && Y.compareIDs(a.id, b.id))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Y.StructStore} ss1
|
* @param {import('../src/internals').StructStore} ss1
|
||||||
* @param {Y.StructStore} ss2
|
* @param {import('../src/internals').StructStore} ss2
|
||||||
*/
|
*/
|
||||||
export const compareStructStores = (ss1, ss2) => {
|
export const compareStructStores = (ss1, ss2) => {
|
||||||
t.assert(ss1.clients.size === ss2.clients.size)
|
t.assert(ss1.clients.size === ss2.clients.size)
|
||||||
@ -428,13 +428,13 @@ export const compareStructStores = (ss1, ss2) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Y.DeleteSet} ds1
|
* @param {import('../src/internals').DeleteSet} ds1
|
||||||
* @param {Y.DeleteSet} ds2
|
* @param {import('../src/internals').DeleteSet} ds2
|
||||||
*/
|
*/
|
||||||
export const compareDS = (ds1, ds2) => {
|
export const compareDS = (ds1, ds2) => {
|
||||||
t.assert(ds1.clients.size === ds2.clients.size)
|
t.assert(ds1.clients.size === ds2.clients.size)
|
||||||
ds1.clients.forEach((deleteItems1, client) => {
|
ds1.clients.forEach((deleteItems1, client) => {
|
||||||
const deleteItems2 = /** @type {Array<Y.DeleteItem>} */ (ds2.clients.get(client))
|
const deleteItems2 = /** @type {Array<import('../src/internals').DeleteItem>} */ (ds2.clients.get(client))
|
||||||
t.assert(deleteItems2 !== undefined && deleteItems1.length === deleteItems2.length)
|
t.assert(deleteItems2 !== undefined && deleteItems1.length === deleteItems2.length)
|
||||||
for (let i = 0; i < deleteItems1.length; i++) {
|
for (let i = 0; i < deleteItems1.length; i++) {
|
||||||
const di1 = deleteItems1[i]
|
const di1 = deleteItems1[i]
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import { init, compare, applyRandomTests, Doc } from './testHelper.js' // eslint-disable-line
|
import { init, compare, applyRandomTests, Doc } from './testHelper.js' // eslint-disable-line
|
||||||
|
|
||||||
import {
|
|
||||||
UndoManager
|
|
||||||
} from '../src/internals.js'
|
|
||||||
|
|
||||||
import * as Y from '../src/index.js'
|
import * as Y from '../src/index.js'
|
||||||
import * as t from 'lib0/testing'
|
import * as t from 'lib0/testing'
|
||||||
|
|
||||||
@ -12,7 +8,7 @@ import * as t from 'lib0/testing'
|
|||||||
*/
|
*/
|
||||||
export const testUndoText = tc => {
|
export const testUndoText = tc => {
|
||||||
const { testConnector, text0, text1 } = init(tc, { users: 3 })
|
const { testConnector, text0, text1 } = init(tc, { users: 3 })
|
||||||
const undoManager = new UndoManager(text0)
|
const undoManager = new Y.UndoManager(text0)
|
||||||
|
|
||||||
// items that are added & deleted in the same transaction won't be undo
|
// items that are added & deleted in the same transaction won't be undo
|
||||||
text0.insert(0, 'test')
|
text0.insert(0, 'test')
|
||||||
@ -81,7 +77,7 @@ export const testDoubleUndo = tc => {
|
|||||||
export const testUndoMap = tc => {
|
export const testUndoMap = tc => {
|
||||||
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
||||||
map0.set('a', 0)
|
map0.set('a', 0)
|
||||||
const undoManager = new UndoManager(map0)
|
const undoManager = new Y.UndoManager(map0)
|
||||||
map0.set('a', 1)
|
map0.set('a', 1)
|
||||||
undoManager.undo()
|
undoManager.undo()
|
||||||
t.assert(map0.get('a') === 0)
|
t.assert(map0.get('a') === 0)
|
||||||
@ -120,7 +116,7 @@ export const testUndoMap = tc => {
|
|||||||
*/
|
*/
|
||||||
export const testUndoArray = tc => {
|
export const testUndoArray = tc => {
|
||||||
const { testConnector, array0, array1 } = init(tc, { users: 3 })
|
const { testConnector, array0, array1 } = init(tc, { users: 3 })
|
||||||
const undoManager = new UndoManager(array0)
|
const undoManager = new Y.UndoManager(array0)
|
||||||
array0.insert(0, [1, 2, 3])
|
array0.insert(0, [1, 2, 3])
|
||||||
array1.insert(0, [4, 5, 6])
|
array1.insert(0, [4, 5, 6])
|
||||||
testConnector.syncAll()
|
testConnector.syncAll()
|
||||||
@ -171,7 +167,7 @@ export const testUndoArray = tc => {
|
|||||||
*/
|
*/
|
||||||
export const testUndoXml = tc => {
|
export const testUndoXml = tc => {
|
||||||
const { xml0 } = init(tc, { users: 3 })
|
const { xml0 } = init(tc, { users: 3 })
|
||||||
const undoManager = new UndoManager(xml0)
|
const undoManager = new Y.UndoManager(xml0)
|
||||||
const child = new Y.XmlElement('p')
|
const child = new Y.XmlElement('p')
|
||||||
xml0.insert(0, [child])
|
xml0.insert(0, [child])
|
||||||
const textchild = new Y.XmlText('content')
|
const textchild = new Y.XmlText('content')
|
||||||
@ -196,7 +192,7 @@ export const testUndoXml = tc => {
|
|||||||
*/
|
*/
|
||||||
export const testUndoEvents = tc => {
|
export const testUndoEvents = tc => {
|
||||||
const { text0 } = init(tc, { users: 3 })
|
const { text0 } = init(tc, { users: 3 })
|
||||||
const undoManager = new UndoManager(text0)
|
const undoManager = new Y.UndoManager(text0)
|
||||||
let counter = 0
|
let counter = 0
|
||||||
let receivedMetadata = -1
|
let receivedMetadata = -1
|
||||||
undoManager.on('stack-item-added', /** @param {any} event */ event => {
|
undoManager.on('stack-item-added', /** @param {any} event */ event => {
|
||||||
@ -222,7 +218,7 @@ export const testUndoEvents = tc => {
|
|||||||
export const testTrackClass = tc => {
|
export const testTrackClass = tc => {
|
||||||
const { users, text0 } = init(tc, { users: 3 })
|
const { users, text0 } = init(tc, { users: 3 })
|
||||||
// only track origins that are numbers
|
// only track origins that are numbers
|
||||||
const undoManager = new UndoManager(text0, { trackedOrigins: new Set([Number]) })
|
const undoManager = new Y.UndoManager(text0, { trackedOrigins: new Set([Number]) })
|
||||||
users[0].transact(() => {
|
users[0].transact(() => {
|
||||||
text0.insert(0, 'abc')
|
text0.insert(0, 'abc')
|
||||||
}, 42)
|
}, 42)
|
||||||
@ -240,8 +236,8 @@ export const testTypeScope = tc => {
|
|||||||
const text0 = new Y.Text()
|
const text0 = new Y.Text()
|
||||||
const text1 = new Y.Text()
|
const text1 = new Y.Text()
|
||||||
array0.insert(0, [text0, text1])
|
array0.insert(0, [text0, text1])
|
||||||
const undoManager = new UndoManager(text0)
|
const undoManager = new Y.UndoManager(text0)
|
||||||
const undoManagerBoth = new UndoManager([text0, text1])
|
const undoManagerBoth = new Y.UndoManager([text0, text1])
|
||||||
text1.insert(0, 'abc')
|
text1.insert(0, 'abc')
|
||||||
t.assert(undoManager.undoStack.length === 0)
|
t.assert(undoManager.undoStack.length === 0)
|
||||||
t.assert(undoManagerBoth.undoStack.length === 1)
|
t.assert(undoManagerBoth.undoStack.length === 1)
|
||||||
@ -260,7 +256,7 @@ export const testUndoDeleteFilter = tc => {
|
|||||||
* @type {Array<Y.Map<any>>}
|
* @type {Array<Y.Map<any>>}
|
||||||
*/
|
*/
|
||||||
const array0 = /** @type {any} */ (init(tc, { users: 3 }).array0)
|
const array0 = /** @type {any} */ (init(tc, { users: 3 }).array0)
|
||||||
const undoManager = new UndoManager(array0, { deleteFilter: item => !(item instanceof Y.Item) || (item.content instanceof Y.ContentType && item.content.type._map.size === 0) })
|
const undoManager = new Y.UndoManager(array0, { deleteFilter: item => !(item instanceof Y.Item) || (item.content instanceof Y.ContentType && item.content.type._map.size === 0) })
|
||||||
const map0 = new Y.Map()
|
const map0 = new Y.Map()
|
||||||
map0.set('hi', 1)
|
map0.set('hi', 1)
|
||||||
const map1 = new Y.Map()
|
const map1 = new Y.Map()
|
||||||
|
@ -157,7 +157,7 @@ export const testGetDeltaWithEmbeds = tc => {
|
|||||||
export const testTypesAsEmbed = tc => {
|
export const testTypesAsEmbed = tc => {
|
||||||
const { text0, text1, testConnector } = init(tc, { users: 2 })
|
const { text0, text1, testConnector } = init(tc, { users: 2 })
|
||||||
text0.applyDelta([{
|
text0.applyDelta([{
|
||||||
insert: new Y.YMap([['key', 'val']])
|
insert: new Y.Map([['key', 'val']])
|
||||||
}])
|
}])
|
||||||
t.compare(text0.toDelta()[0].insert.toJSON(), { key: 'val' })
|
t.compare(text0.toDelta()[0].insert.toJSON(), { key: 'val' })
|
||||||
let firedEvent = false
|
let firedEvent = false
|
||||||
@ -714,7 +714,7 @@ const qChanges = [
|
|||||||
if (prng.bool(gen)) {
|
if (prng.bool(gen)) {
|
||||||
ytext.insertEmbed(insertPos, { image: 'https://user-images.githubusercontent.com/5553757/48975307-61efb100-f06d-11e8-9177-ee895e5916e5.png' })
|
ytext.insertEmbed(insertPos, { image: 'https://user-images.githubusercontent.com/5553757/48975307-61efb100-f06d-11e8-9177-ee895e5916e5.png' })
|
||||||
} else {
|
} else {
|
||||||
ytext.insertEmbed(insertPos, new Y.YMap([[prng.word(gen), prng.word(gen)]]))
|
ytext.insertEmbed(insertPos, new Y.Map([[prng.word(gen), prng.word(gen)]]))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user