mirror of https://codeberg.org/pzp/pzp-sync.git
replace tape with node:test
This commit is contained in:
parent
07f83677d4
commit
af5ac3435d
|
@ -43,12 +43,10 @@
|
||||||
"rimraf": "^4.4.0",
|
"rimraf": "^4.4.0",
|
||||||
"secret-stack": "^6.4.1",
|
"secret-stack": "^6.4.1",
|
||||||
"secret-handshake-ext": "^0.0.7",
|
"secret-handshake-ext": "^0.0.7",
|
||||||
"ssb-box": "^1.0.1",
|
"ssb-box": "^1.0.1"
|
||||||
"tap-arc": "^0.3.5",
|
|
||||||
"tape": "^5.6.3"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tape test/*.js | tap-arc --bail",
|
"test": "node --test",
|
||||||
"format-code": "prettier --write \"(lib|test)/**/*.js\"",
|
"format-code": "prettier --write \"(lib|test)/**/*.js\"",
|
||||||
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.js\"",
|
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.js\"",
|
||||||
"coverage": "c8 --reporter=lcov npm run test"
|
"coverage": "c8 --reporter=lcov npm run test"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const test = require('tape')
|
const test = require('node:test')
|
||||||
|
const assert = require('node:assert')
|
||||||
const p = require('node:util').promisify
|
const p = require('node:util').promisify
|
||||||
const Keypair = require('ppppp-keypair')
|
const Keypair = require('ppppp-keypair')
|
||||||
const Algorithm = require('../lib/algorithm')
|
const Algorithm = require('../lib/algorithm')
|
||||||
|
@ -33,7 +34,7 @@ test('sync a feed with goal=all', async (t) => {
|
||||||
})
|
})
|
||||||
carolMsgs.push(rec.msg)
|
carolMsgs.push(rec.msg)
|
||||||
}
|
}
|
||||||
t.pass('alice has msgs 1..10 from carol')
|
assert('alice has msgs 1..10 from carol')
|
||||||
|
|
||||||
const carolPostsRootHash = alice.db.feed.getId(carolID, 'post')
|
const carolPostsRootHash = alice.db.feed.getId(carolID, 'post')
|
||||||
const carolPostsRootMsg = alice.db.get(carolPostsRootHash)
|
const carolPostsRootMsg = alice.db.get(carolPostsRootHash)
|
||||||
|
@ -47,7 +48,7 @@ test('sync a feed with goal=all', async (t) => {
|
||||||
const arr = [...bob.db.msgs()]
|
const arr = [...bob.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
arr,
|
arr,
|
||||||
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7'],
|
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7'],
|
||||||
'bob has msgs 1..7 from carol'
|
'bob has msgs 1..7 from carol'
|
||||||
|
@ -58,17 +59,17 @@ test('sync a feed with goal=all', async (t) => {
|
||||||
alice.tangleSync.setGoal(carolPostsRootHash, 'all')
|
alice.tangleSync.setGoal(carolPostsRootHash, 'all')
|
||||||
|
|
||||||
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
||||||
t.pass('bob connected to alice')
|
assert('bob connected to alice')
|
||||||
|
|
||||||
bob.tangleSync.initiate()
|
bob.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
{
|
{
|
||||||
const arr = [...bob.db.msgs()]
|
const arr = [...bob.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
arr,
|
arr,
|
||||||
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10'],
|
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10'],
|
||||||
'bob has msgs 1..10 from carol'
|
'bob has msgs 1..10 from carol'
|
||||||
|
@ -107,7 +108,7 @@ test('sync a feed with goal=newest', async (t) => {
|
||||||
})
|
})
|
||||||
carolMsgs.push(rec.msg)
|
carolMsgs.push(rec.msg)
|
||||||
}
|
}
|
||||||
t.pass('alice has msgs 1..10 from carol')
|
assert('alice has msgs 1..10 from carol')
|
||||||
|
|
||||||
const carolPostsRootHash = alice.db.feed.getId(carolID, 'post')
|
const carolPostsRootHash = alice.db.feed.getId(carolID, 'post')
|
||||||
const carolPostsRootMsg = alice.db.get(carolPostsRootHash)
|
const carolPostsRootMsg = alice.db.get(carolPostsRootHash)
|
||||||
|
@ -121,7 +122,7 @@ test('sync a feed with goal=newest', async (t) => {
|
||||||
const arr = [...bob.db.msgs()]
|
const arr = [...bob.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
arr,
|
arr,
|
||||||
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7'],
|
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7'],
|
||||||
'bob has msgs 1..7 from carol'
|
'bob has msgs 1..7 from carol'
|
||||||
|
@ -132,17 +133,17 @@ test('sync a feed with goal=newest', async (t) => {
|
||||||
alice.tangleSync.setGoal(carolPostsRootHash, 'all')
|
alice.tangleSync.setGoal(carolPostsRootHash, 'all')
|
||||||
|
|
||||||
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
||||||
t.pass('bob connected to alice')
|
assert('bob connected to alice')
|
||||||
|
|
||||||
bob.tangleSync.initiate()
|
bob.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
{
|
{
|
||||||
const arr = [...bob.db.msgs()]
|
const arr = [...bob.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
arr,
|
arr,
|
||||||
['m6', 'm7', 'm8', 'm9', 'm10'],
|
['m6', 'm7', 'm8', 'm9', 'm10'],
|
||||||
'bob has msgs 6..10 from carol'
|
'bob has msgs 6..10 from carol'
|
||||||
|
@ -191,7 +192,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
||||||
const arr = [...alice.db.msgs()]
|
const arr = [...alice.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
arr,
|
arr,
|
||||||
['m6', 'm7', 'm8', 'm9', 'm10'],
|
['m6', 'm7', 'm8', 'm9', 'm10'],
|
||||||
'alice has msgs 6..10 from carol'
|
'alice has msgs 6..10 from carol'
|
||||||
|
@ -207,24 +208,24 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
|
||||||
const arr = [...bob.db.msgs()]
|
const arr = [...bob.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(arr, ['m1', 'm2'], 'bob has msgs 1..2 from carol')
|
assert.deepEqual(arr, ['m1', 'm2'], 'bob has msgs 1..2 from carol')
|
||||||
}
|
}
|
||||||
|
|
||||||
alice.tangleSync.setGoal(carolPostsRootHash, 'newest-5')
|
alice.tangleSync.setGoal(carolPostsRootHash, 'newest-5')
|
||||||
bob.tangleSync.setGoal(carolPostsRootHash, 'newest-5')
|
bob.tangleSync.setGoal(carolPostsRootHash, 'newest-5')
|
||||||
|
|
||||||
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
||||||
t.pass('bob connected to alice')
|
assert('bob connected to alice')
|
||||||
|
|
||||||
bob.tangleSync.initiate()
|
bob.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
{
|
{
|
||||||
const arr = [...bob.db.msgs()]
|
const arr = [...bob.db.msgs()]
|
||||||
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
.filter((msg) => msg.metadata.identity === carolID && msg.data)
|
||||||
.map((msg) => msg.data.text)
|
.map((msg) => msg.data.text)
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
arr,
|
arr,
|
||||||
['m6', 'm7', 'm8', 'm9', 'm10'],
|
['m6', 'm7', 'm8', 'm9', 'm10'],
|
||||||
'bob has msgs 6..10 from carol'
|
'bob has msgs 6..10 from carol'
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const test = require('tape')
|
const test = require('node:test')
|
||||||
|
const assert = require('node:assert')
|
||||||
const p = require('util').promisify
|
const p = require('util').promisify
|
||||||
const Keypair = require('ppppp-keypair')
|
const Keypair = require('ppppp-keypair')
|
||||||
const { createPeer } = require('./util')
|
const { createPeer } = require('./util')
|
||||||
|
@ -38,13 +39,13 @@ test('sync an identity tangle', async (t) => {
|
||||||
keypair: aliceKeypair2,
|
keypair: aliceKeypair2,
|
||||||
})
|
})
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getIdentity(alice.db.msgs()),
|
getIdentity(alice.db.msgs()),
|
||||||
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
|
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
|
||||||
'alice has her identity tangle'
|
'alice has her identity tangle'
|
||||||
)
|
)
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getIdentity(bob.db.msgs()),
|
getIdentity(bob.db.msgs()),
|
||||||
[],
|
[],
|
||||||
"bob doesn't have alice's identity tangle"
|
"bob doesn't have alice's identity tangle"
|
||||||
|
@ -54,13 +55,13 @@ test('sync an identity tangle', async (t) => {
|
||||||
alice.tangleSync.setGoal(aliceID, 'all')
|
alice.tangleSync.setGoal(aliceID, 'all')
|
||||||
|
|
||||||
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
||||||
t.pass('bob connected to alice')
|
assert('bob connected to alice')
|
||||||
|
|
||||||
bob.tangleSync.initiate()
|
bob.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getIdentity(bob.db.msgs()),
|
getIdentity(bob.db.msgs()),
|
||||||
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
|
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
|
||||||
"bob has alice's identity tangle"
|
"bob has alice's identity tangle"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const test = require('tape')
|
const test = require('node:test')
|
||||||
|
const assert = require('node:assert')
|
||||||
const p = require('util').promisify
|
const p = require('util').promisify
|
||||||
const Keypair = require('ppppp-keypair')
|
const Keypair = require('ppppp-keypair')
|
||||||
const { createPeer } = require('./util')
|
const { createPeer } = require('./util')
|
||||||
|
@ -136,13 +137,13 @@ test('sync a thread where both peers have portions', async (t) => {
|
||||||
keypair: daveKeypair,
|
keypair: daveKeypair,
|
||||||
})
|
})
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(alice.db.msgs()),
|
getTexts(alice.db.msgs()),
|
||||||
['A', 'B1', 'B2', 'C1'],
|
['A', 'B1', 'B2', 'C1'],
|
||||||
'alice has a portion of the thread'
|
'alice has a portion of the thread'
|
||||||
)
|
)
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(bob.db.msgs()),
|
getTexts(bob.db.msgs()),
|
||||||
['A', 'B1', 'B2', 'D1'],
|
['A', 'B1', 'B2', 'D1'],
|
||||||
'bob has another portion of the thread'
|
'bob has another portion of the thread'
|
||||||
|
@ -152,19 +153,19 @@ test('sync a thread where both peers have portions', async (t) => {
|
||||||
alice.tangleSync.setGoal(startA.hash, 'all')
|
alice.tangleSync.setGoal(startA.hash, 'all')
|
||||||
|
|
||||||
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
||||||
t.pass('bob connected to alice')
|
assert('bob connected to alice')
|
||||||
|
|
||||||
bob.tangleSync.initiate()
|
bob.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(alice.db.msgs()),
|
getTexts(alice.db.msgs()),
|
||||||
['A', 'B1', 'B2', 'C1', 'D1'],
|
['A', 'B1', 'B2', 'C1', 'D1'],
|
||||||
'alice has the full thread'
|
'alice has the full thread'
|
||||||
)
|
)
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(bob.db.msgs()),
|
getTexts(bob.db.msgs()),
|
||||||
['A', 'B1', 'B2', 'D1', 'C1'],
|
['A', 'B1', 'B2', 'D1', 'C1'],
|
||||||
'bob has the full thread'
|
'bob has the full thread'
|
||||||
|
@ -219,26 +220,26 @@ test('sync a thread where initiator does not have the root', async (t) => {
|
||||||
tangles: [rootA.hash],
|
tangles: [rootA.hash],
|
||||||
})
|
})
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(alice.db.msgs()),
|
getTexts(alice.db.msgs()),
|
||||||
['A', 'A1', 'A2'],
|
['A', 'A1', 'A2'],
|
||||||
'alice has the full thread'
|
'alice has the full thread'
|
||||||
)
|
)
|
||||||
|
|
||||||
t.deepEquals(getTexts(bob.db.msgs()), [], 'bob has nothing')
|
assert.deepEqual(getTexts(bob.db.msgs()), [], 'bob has nothing')
|
||||||
|
|
||||||
bob.tangleSync.setGoal(rootA.hash, 'all')
|
bob.tangleSync.setGoal(rootA.hash, 'all')
|
||||||
// ON PURPOSE: alice does not set the goal
|
// ON PURPOSE: alice does not set the goal
|
||||||
// alice.tangleSync.setGoal(rootA.hash, 'all')
|
// alice.tangleSync.setGoal(rootA.hash, 'all')
|
||||||
|
|
||||||
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
const remoteAlice = await p(bob.connect)(alice.getAddress())
|
||||||
t.pass('bob connected to alice')
|
assert('bob connected to alice')
|
||||||
|
|
||||||
bob.tangleSync.initiate()
|
bob.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(bob.db.msgs()),
|
getTexts(bob.db.msgs()),
|
||||||
['A', 'A1', 'A2'],
|
['A', 'A1', 'A2'],
|
||||||
'bob has the full thread'
|
'bob has the full thread'
|
||||||
|
@ -293,25 +294,25 @@ test('sync a thread where receiver does not have the root', async (t) => {
|
||||||
tangles: [rootA.hash],
|
tangles: [rootA.hash],
|
||||||
})
|
})
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(alice.db.msgs()),
|
getTexts(alice.db.msgs()),
|
||||||
['A', 'A1', 'A2'],
|
['A', 'A1', 'A2'],
|
||||||
'alice has the full thread'
|
'alice has the full thread'
|
||||||
)
|
)
|
||||||
|
|
||||||
t.deepEquals(getTexts(bob.db.msgs()), [], 'bob has nothing')
|
assert.deepEqual(getTexts(bob.db.msgs()), [], 'bob has nothing')
|
||||||
|
|
||||||
bob.tangleSync.setGoal(rootA.hash, 'all')
|
bob.tangleSync.setGoal(rootA.hash, 'all')
|
||||||
alice.tangleSync.setGoal(rootA.hash, 'all')
|
alice.tangleSync.setGoal(rootA.hash, 'all')
|
||||||
|
|
||||||
const remoteBob = await p(alice.connect)(bob.getAddress())
|
const remoteBob = await p(alice.connect)(bob.getAddress())
|
||||||
t.pass('alice connected to bob')
|
assert('alice connected to bob')
|
||||||
|
|
||||||
alice.tangleSync.initiate()
|
alice.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(bob.db.msgs()),
|
getTexts(bob.db.msgs()),
|
||||||
['A', 'A1', 'A2'],
|
['A', 'A1', 'A2'],
|
||||||
'bob has the full thread'
|
'bob has the full thread'
|
||||||
|
@ -373,25 +374,25 @@ test('sync a thread with reactions too', async (t) => {
|
||||||
tangles: [rootA.hash, replyA1.hash],
|
tangles: [rootA.hash, replyA1.hash],
|
||||||
})
|
})
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(alice.db.msgs()),
|
getTexts(alice.db.msgs()),
|
||||||
['A', 'A1', 'A2', 'yes'],
|
['A', 'A1', 'A2', 'yes'],
|
||||||
'alice has the full thread'
|
'alice has the full thread'
|
||||||
)
|
)
|
||||||
|
|
||||||
t.deepEquals(getTexts(bob.db.msgs()), [], 'bob has nothing')
|
assert.deepEqual(getTexts(bob.db.msgs()), [], 'bob has nothing')
|
||||||
|
|
||||||
bob.tangleSync.setGoal(rootA.hash, 'all')
|
bob.tangleSync.setGoal(rootA.hash, 'all')
|
||||||
alice.tangleSync.setGoal(rootA.hash, 'all')
|
alice.tangleSync.setGoal(rootA.hash, 'all')
|
||||||
|
|
||||||
const remoteBob = await p(alice.connect)(bob.getAddress())
|
const remoteBob = await p(alice.connect)(bob.getAddress())
|
||||||
t.pass('alice connected to bob')
|
assert('alice connected to bob')
|
||||||
|
|
||||||
alice.tangleSync.initiate()
|
alice.tangleSync.initiate()
|
||||||
await p(setTimeout)(1000)
|
await p(setTimeout)(1000)
|
||||||
t.pass('tangleSync!')
|
assert('tangleSync!')
|
||||||
|
|
||||||
t.deepEquals(
|
assert.deepEqual(
|
||||||
getTexts(bob.db.msgs()),
|
getTexts(bob.db.msgs()),
|
||||||
['A', 'A1', 'A2', 'yes'],
|
['A', 'A1', 'A2', 'yes'],
|
||||||
'bob has the full thread'
|
'bob has the full thread'
|
||||||
|
|
Loading…
Reference in New Issue