replace tape with node:test

This commit is contained in:
Andre Staltz 2023-07-11 11:08:53 +03:00
parent 07f83677d4
commit af5ac3435d
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
4 changed files with 49 additions and 48 deletions

View File

@ -43,12 +43,10 @@
"rimraf": "^4.4.0",
"secret-stack": "^6.4.1",
"secret-handshake-ext": "^0.0.7",
"ssb-box": "^1.0.1",
"tap-arc": "^0.3.5",
"tape": "^5.6.3"
"ssb-box": "^1.0.1"
},
"scripts": {
"test": "tape test/*.js | tap-arc --bail",
"test": "node --test",
"format-code": "prettier --write \"(lib|test)/**/*.js\"",
"format-code-staged": "pretty-quick --staged --pattern \"(lib|test)/**/*.js\"",
"coverage": "c8 --reporter=lcov npm run test"

View File

@ -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 Keypair = require('ppppp-keypair')
const Algorithm = require('../lib/algorithm')
@ -33,7 +34,7 @@ test('sync a feed with goal=all', async (t) => {
})
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 carolPostsRootMsg = alice.db.get(carolPostsRootHash)
@ -47,7 +48,7 @@ test('sync a feed with goal=all', async (t) => {
const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.map((msg) => msg.data.text)
t.deepEquals(
assert.deepEqual(
arr,
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7'],
'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')
const remoteAlice = await p(bob.connect)(alice.getAddress())
t.pass('bob connected to alice')
assert('bob connected to alice')
bob.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
{
const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.map((msg) => msg.data.text)
t.deepEquals(
assert.deepEqual(
arr,
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10'],
'bob has msgs 1..10 from carol'
@ -107,7 +108,7 @@ test('sync a feed with goal=newest', async (t) => {
})
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 carolPostsRootMsg = alice.db.get(carolPostsRootHash)
@ -121,7 +122,7 @@ test('sync a feed with goal=newest', async (t) => {
const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.map((msg) => msg.data.text)
t.deepEquals(
assert.deepEqual(
arr,
['m1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7'],
'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')
const remoteAlice = await p(bob.connect)(alice.getAddress())
t.pass('bob connected to alice')
assert('bob connected to alice')
bob.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
{
const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.map((msg) => msg.data.text)
t.deepEquals(
assert.deepEqual(
arr,
['m6', 'm7', 'm8', 'm9', 'm10'],
'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()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.map((msg) => msg.data.text)
t.deepEquals(
assert.deepEqual(
arr,
['m6', 'm7', 'm8', 'm9', 'm10'],
'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()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.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')
bob.tangleSync.setGoal(carolPostsRootHash, 'newest-5')
const remoteAlice = await p(bob.connect)(alice.getAddress())
t.pass('bob connected to alice')
assert('bob connected to alice')
bob.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
{
const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data)
.map((msg) => msg.data.text)
t.deepEquals(
assert.deepEqual(
arr,
['m6', 'm7', 'm8', 'm9', 'm10'],
'bob has msgs 6..10 from carol'

View File

@ -1,4 +1,5 @@
const test = require('tape')
const test = require('node:test')
const assert = require('node:assert')
const p = require('util').promisify
const Keypair = require('ppppp-keypair')
const { createPeer } = require('./util')
@ -38,13 +39,13 @@ test('sync an identity tangle', async (t) => {
keypair: aliceKeypair2,
})
t.deepEquals(
assert.deepEqual(
getIdentity(alice.db.msgs()),
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
'alice has her identity tangle'
)
t.deepEquals(
assert.deepEqual(
getIdentity(bob.db.msgs()),
[],
"bob doesn't have alice's identity tangle"
@ -54,13 +55,13 @@ test('sync an identity tangle', async (t) => {
alice.tangleSync.setGoal(aliceID, 'all')
const remoteAlice = await p(bob.connect)(alice.getAddress())
t.pass('bob connected to alice')
assert('bob connected to alice')
bob.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
t.deepEquals(
assert.deepEqual(
getIdentity(bob.db.msgs()),
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
"bob has alice's identity tangle"

View File

@ -1,4 +1,5 @@
const test = require('tape')
const test = require('node:test')
const assert = require('node:assert')
const p = require('util').promisify
const Keypair = require('ppppp-keypair')
const { createPeer } = require('./util')
@ -136,13 +137,13 @@ test('sync a thread where both peers have portions', async (t) => {
keypair: daveKeypair,
})
t.deepEquals(
assert.deepEqual(
getTexts(alice.db.msgs()),
['A', 'B1', 'B2', 'C1'],
'alice has a portion of the thread'
)
t.deepEquals(
assert.deepEqual(
getTexts(bob.db.msgs()),
['A', 'B1', 'B2', 'D1'],
'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')
const remoteAlice = await p(bob.connect)(alice.getAddress())
t.pass('bob connected to alice')
assert('bob connected to alice')
bob.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
t.deepEquals(
assert.deepEqual(
getTexts(alice.db.msgs()),
['A', 'B1', 'B2', 'C1', 'D1'],
'alice has the full thread'
)
t.deepEquals(
assert.deepEqual(
getTexts(bob.db.msgs()),
['A', 'B1', 'B2', 'D1', 'C1'],
'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],
})
t.deepEquals(
assert.deepEqual(
getTexts(alice.db.msgs()),
['A', 'A1', 'A2'],
'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')
// ON PURPOSE: alice does not set the goal
// alice.tangleSync.setGoal(rootA.hash, 'all')
const remoteAlice = await p(bob.connect)(alice.getAddress())
t.pass('bob connected to alice')
assert('bob connected to alice')
bob.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
t.deepEquals(
assert.deepEqual(
getTexts(bob.db.msgs()),
['A', 'A1', 'A2'],
'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],
})
t.deepEquals(
assert.deepEqual(
getTexts(alice.db.msgs()),
['A', 'A1', 'A2'],
'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')
alice.tangleSync.setGoal(rootA.hash, 'all')
const remoteBob = await p(alice.connect)(bob.getAddress())
t.pass('alice connected to bob')
assert('alice connected to bob')
alice.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
t.deepEquals(
assert.deepEqual(
getTexts(bob.db.msgs()),
['A', 'A1', 'A2'],
'bob has the full thread'
@ -373,25 +374,25 @@ test('sync a thread with reactions too', async (t) => {
tangles: [rootA.hash, replyA1.hash],
})
t.deepEquals(
assert.deepEqual(
getTexts(alice.db.msgs()),
['A', 'A1', 'A2', 'yes'],
'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')
alice.tangleSync.setGoal(rootA.hash, 'all')
const remoteBob = await p(alice.connect)(bob.getAddress())
t.pass('alice connected to bob')
assert('alice connected to bob')
alice.tangleSync.initiate()
await p(setTimeout)(1000)
t.pass('tangleSync!')
assert('tangleSync!')
t.deepEquals(
assert.deepEqual(
getTexts(bob.db.msgs()),
['A', 'A1', 'A2', 'yes'],
'bob has the full thread'