From e34389f7c9efa510df5fb16f1e043dcdd550ff38 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Wed, 27 Sep 2023 16:28:16 +0200 Subject: [PATCH 1/5] Update tape to v5 and start updating tests --- package-lock.json | 203 ++++++++++++++++++----- package.json | 2 +- test/api/add-new-author-listener.test.js | 1 - test/lib/group-id.test.js | 3 + 4 files changed, 163 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index f4f0c7c5..c6fab065 100644 --- a/package-lock.json +++ b/package-lock.json @@ -45,7 +45,7 @@ "ssb-replicate": "^1.3.3", "standard": "^17.1.0", "tap-arc": "^0.4.0", - "tape": "^4.16.2" + "tape": "^5.7.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -158,6 +158,27 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, + "node_modules/@ljharb/resumer": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@ljharb/resumer/-/resumer-0.0.1.tgz", + "integrity": "sha512-skQiAOrCfO7vRTq53cxznMpks7wS1va95UCidALlOVWqvBAzwPVErwizDwoMqNVMEn1mDq0utxZd02eIrvF1lw==", + "dev": true, + "dependencies": { + "@ljharb/through": "^2.3.9" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/@ljharb/through": { + "version": "2.3.9", + "resolved": "https://registry.npmjs.org/@ljharb/through/-/through-2.3.9.tgz", + "integrity": "sha512-yN599ZBuMPPK4tdoToLlvgJB4CLK8fGl7ntfy0Wn7U6ttNvHYurd81bfUiK/6sMkiIwm65R6ck4L6+Y3DfVbNQ==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -417,6 +438,24 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/array.prototype.every": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/array.prototype.every/-/array.prototype.every-1.1.5.tgz", + "integrity": "sha512-FfMQJ+/joFGXpRCltbzV3znaP5QxIhLFySo0fEPn3GuoYlud9LhknMCIxdYKC2qsM/6VHoSp6YGwe3EZXrEcwQ==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.2.0", + "es-abstract": "^1.22.1", + "is-string": "^1.0.7" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/array.prototype.findlastindex": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/array.prototype.findlastindex/-/array.prototype.findlastindex-1.2.3.tgz", @@ -881,6 +920,53 @@ "typewiselite": "^1.0.0" } }, + "node_modules/compare-at-paths/node_modules/deep-equal": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.1.tgz", + "integrity": "sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g==", + "dev": true, + "dependencies": { + "is-arguments": "^1.0.4", + "is-date-object": "^1.0.1", + "is-regex": "^1.0.4", + "object-is": "^1.0.1", + "object-keys": "^1.1.1", + "regexp.prototype.flags": "^1.2.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/compare-at-paths/node_modules/tape": { + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/tape/-/tape-4.17.0.tgz", + "integrity": "sha512-KCuXjYxCZ3ru40dmND+oCLsXyuA8hoseu2SS404Px5ouyS0A99v8X/mdiLqsR5MTAyamMBN7PRwt2Dv3+xGIxw==", + "dev": true, + "dependencies": { + "@ljharb/resumer": "~0.0.1", + "@ljharb/through": "~2.3.9", + "call-bind": "~1.0.2", + "deep-equal": "~1.1.1", + "defined": "~1.0.1", + "dotignore": "~0.1.2", + "for-each": "~0.3.3", + "glob": "~7.2.3", + "has": "~1.0.3", + "inherits": "~2.0.4", + "is-regex": "~1.1.4", + "minimist": "~1.2.8", + "mock-property": "~1.0.0", + "object-inspect": "~1.12.3", + "resolve": "~1.22.6", + "string.prototype.trim": "~1.2.8" + }, + "bin": { + "tape": "bin/tape" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2181,6 +2267,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-package-type": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", + "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", + "dev": true, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/get-stdin": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-8.0.0.tgz", @@ -2315,6 +2410,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-dynamic-import": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-dynamic-import/-/has-dynamic-import-2.0.1.tgz", + "integrity": "sha512-X3fbtsZmwb6W7fJGR9o7x65fZoodygCrZ3TVycvghP62yYQfS0t4RS0Qcz+j5tQYUKeSWS09tHkWW6WhFV3XhQ==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.1.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -3398,6 +3506,21 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "dev": true }, + "node_modules/mock-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/mock-property/-/mock-property-1.0.0.tgz", + "integrity": "sha512-imC60k5A55GPUU43PqczbubOyyxCudIgneACKzL3PKfsBk08dc1HgNNU8siQbEIAPPjVUhc+gb0v0ypZ/iP9pw==", + "dev": true, + "dependencies": { + "functions-have-names": "^1.2.2", + "has": "^1.0.3", + "has-property-descriptors": "^1.0.0", + "isarray": "^2.0.5" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/monotonic-timestamp": { "version": "0.0.9", "resolved": "https://registry.npmjs.org/monotonic-timestamp/-/monotonic-timestamp-0.0.9.tgz", @@ -4600,15 +4723,6 @@ "node": ">=4" } }, - "node_modules/resumer": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", - "integrity": "sha512-Fn9X8rX8yYF4m81rZCK/5VmrmsSbqS/i3rDLl6ZZHAXgC2nTAx3dhwG8q8odP/RmdLa2YrybDJaAMg+X1ajY3w==", - "dev": true, - "dependencies": { - "through": "~2.3.4" - } - }, "node_modules/ret": { "version": "0.1.15", "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", @@ -5845,26 +5959,33 @@ } }, "node_modules/tape": { - "version": "4.16.2", - "resolved": "https://registry.npmjs.org/tape/-/tape-4.16.2.tgz", - "integrity": "sha512-TUChV+q0GxBBCEbfCYkGLkv8hDJYjMdSWdE0/Lr331sB389dsvFUHNV9ph5iQqKzt8Ss9drzcda/YeexclBFqg==", + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/tape/-/tape-5.7.0.tgz", + "integrity": "sha512-6EZoHjMDUUhet8+k32w/9onULL1U8idXKvBCnZxuZF2iFe+tMYOsKo4bpCtXbTSngZmYBnkU08TMhJwsKaHhaw==", "dev": true, "dependencies": { - "call-bind": "~1.0.2", - "deep-equal": "~1.1.1", - "defined": "~1.0.1", - "dotignore": "~0.1.2", - "for-each": "~0.3.3", - "glob": "~7.2.3", - "has": "~1.0.3", - "inherits": "~2.0.4", - "is-regex": "~1.1.4", - "minimist": "~1.2.7", - "object-inspect": "~1.12.3", - "resolve": "~1.22.1", - "resumer": "~0.0.0", - "string.prototype.trim": "~1.2.7", - "through": "~2.3.8" + "@ljharb/resumer": "^0.0.1", + "@ljharb/through": "^2.3.9", + "array.prototype.every": "^1.1.5", + "call-bind": "^1.0.2", + "deep-equal": "^2.2.2", + "defined": "^1.0.1", + "dotignore": "^0.1.2", + "for-each": "^0.3.3", + "get-package-type": "^0.1.0", + "glob": "^7.2.3", + "has": "^1.0.3", + "has-dynamic-import": "^2.0.1", + "inherits": "^2.0.4", + "is-regex": "^1.1.4", + "minimist": "^1.2.8", + "mock-property": "^1.0.0", + "object-inspect": "^1.12.3", + "object-is": "^1.1.5", + "object-keys": "^1.1.1", + "object.assign": "^4.1.4", + "resolve": "^2.0.0-next.4", + "string.prototype.trim": "^1.2.8" }, "bin": { "tape": "bin/tape" @@ -5873,18 +5994,18 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/tape/node_modules/deep-equal": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.1.tgz", - "integrity": "sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g==", + "node_modules/tape/node_modules/resolve": { + "version": "2.0.0-next.4", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-2.0.0-next.4.tgz", + "integrity": "sha512-iMDbmAWtfU+MHpxt/I5iWI7cY6YVEZUQ3MBgPQ++XD1PELuJHIl82xBmObyP2KyQmkNB2dsqF7seoQQiAn5yDQ==", "dev": true, "dependencies": { - "is-arguments": "^1.0.4", - "is-date-object": "^1.0.1", - "is-regex": "^1.0.4", - "object-is": "^1.0.1", - "object-keys": "^1.1.1", - "regexp.prototype.flags": "^1.2.0" + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -5908,12 +6029,6 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, - "node_modules/through": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", - "dev": true - }, "node_modules/through2": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/through2/-/through2-4.0.2.tgz", diff --git a/package.json b/package.json index d6467c72..2269e2d1 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "ssb-replicate": "^1.3.3", "standard": "^17.1.0", "tap-arc": "^0.4.0", - "tape": "^4.16.2" + "tape": "^5.7.0" }, "keywords": [ "scuttlebutt", diff --git a/test/api/add-new-author-listener.test.js b/test/api/add-new-author-listener.test.js index 8d38744e..e225e95b 100644 --- a/test/api/add-new-author-listener.test.js +++ b/test/api/add-new-author-listener.test.js @@ -40,7 +40,6 @@ test('addNewAuthorListener', async t => { setTimeout(() => { admin.close() newPerson.close() - t.end() }, 1000) }) diff --git a/test/lib/group-id.test.js b/test/lib/group-id.test.js index 6887d5cd..d6d8cd2b 100644 --- a/test/lib/group-id.test.js +++ b/test/lib/group-id.test.js @@ -52,10 +52,13 @@ test('groupId', t => { t.equal(groupId({ groupInitMsg, groupKey }), data.groupId, 'can calculate groupId with groupKey') server.close() + t.end() }) +}) // ----------------------------------------------------------- +test('groupId vectors', t=> { /* testing against shared test-vectors */ vectors.forEach(vector => { decodeLeaves(vector) From e9828234833cdff7cf6f8afc1881acf5195af987 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 28 Sep 2023 13:50:48 +0200 Subject: [PATCH 2/5] Fix rebuild manager tests --- test/lib/group-id.test.js | 4 +- test/rebuild-manager.test.js | 114 +++++++++++++++++------------------ 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/test/lib/group-id.test.js b/test/lib/group-id.test.js index d6d8cd2b..cc60a8f0 100644 --- a/test/lib/group-id.test.js +++ b/test/lib/group-id.test.js @@ -56,9 +56,9 @@ test('groupId', t => { }) }) - // ----------------------------------------------------------- +// ----------------------------------------------------------- -test('groupId vectors', t=> { +test('groupId vectors', t => { /* testing against shared test-vectors */ vectors.forEach(vector => { decodeLeaves(vector) diff --git a/test/rebuild-manager.test.js b/test/rebuild-manager.test.js index 2b5d1273..500080ea 100644 --- a/test/rebuild-manager.test.js +++ b/test/rebuild-manager.test.js @@ -31,81 +31,81 @@ async function setup () { return ssb } -test('rebuild-manager', async t => { +test('rebuild-manager', t => { t.plan(3) - const ssb = await setup() - + setup().then(ssb => { // we wrap ssb.rebuild once to know exactly what goes through to the db - // we expect only one call to come through from the rebuildManager - // AFTER indexing is complete - let rebuildCount = 0 - ssb.rebuild.hook((rebuild, [cb]) => { - t.true(ssb.status().sync.sync, 'rebuild only gets called once indexing is done') - rebuildCount++ - rebuild(cb) - }) + // we expect only one call to come through from the rebuildManager + // AFTER indexing is complete + let rebuildCount = 0 + ssb.rebuild.hook((rebuild, [cb]) => { + t.true(ssb.status().sync.sync, 'rebuild only gets called once indexing is done') + rebuildCount++ + rebuild(cb) + }) - // this wraps ssb.rebuild again - const manager = new Manager(ssb) + // this wraps ssb.rebuild again + const manager = new Manager(ssb) - manager.rebuild('my dog') - manager.rebuild('my cat', () => t.pass('callback in the middle')) - manager.rebuild('my fish', () => { - t.equal(rebuildCount, 1, 'db rebuild only gets called once') + manager.rebuild('my dog') + manager.rebuild('my cat', () => t.pass('callback in the middle')) + manager.rebuild('my fish', () => { + t.equal(rebuildCount, 1, 'db rebuild only gets called once') - ssb.close() + ssb.close() + }) }) }) -test('rebuild-manager (rebuild called during rebuild with EXISTING reason)', async t => { +test('rebuild-manager (rebuild called during rebuild with EXISTING reason)', t => { t.plan(4) - const ssb = await setup() - - let rebuildCount = 0 - ssb.rebuild.hook((rebuild, [cb]) => { - t.true(ssb.status().sync.sync, 'rebuild only gets called once indexing is done') - rebuildCount++ - rebuild.call(ssb, cb) - manager.rebuild('my cat', () => { // << 'my cat' already cited as EXISTING reason for rebuild - t.equal(rebuildCount, 1, 'existing reason and cb folded into current run') + setup().then(ssb => { + let rebuildCount = 0 + ssb.rebuild.hook((rebuild, [cb]) => { + t.true(ssb.status().sync.sync, 'rebuild only gets called once indexing is done') + rebuildCount++ + rebuild.call(ssb, cb) + manager.rebuild('my cat', () => { // << 'my cat' already cited as EXISTING reason for rebuild + t.equal(rebuildCount, 1, 'existing reason and cb folded into current run') + }) }) - }) - const manager = new Manager(ssb) + const manager = new Manager(ssb) - manager.rebuild('my fish') - manager.rebuild('my dog', () => t.pass('callback in the middle')) - manager.rebuild('my cat', () => { - t.equal(rebuildCount, 1, 'db rebuild only gets called once') + manager.rebuild('my fish') + manager.rebuild('my dog', () => t.pass('callback in the middle')) + manager.rebuild('my cat', () => { + t.equal(rebuildCount, 1, 'db rebuild only gets called once') - ssb.close() + ssb.close() + }) }) }) -test('rebuild-manager (rebuild called during rebuild with NEW reason)', async t => { +test('rebuild-manager (rebuild called during rebuild with NEW reason)', t => { t.plan(5) - const ssb = await setup() - - let rebuildCount = 0 - ssb.rebuild.hook((rebuild, [cb]) => { - t.true(ssb.status().sync.sync, 'rebuild only gets called once indexing is done') // see this twice - rebuildCount++ - rebuild.call(ssb, cb) - - if (rebuildCount === 1) { - manager.rebuild('my pig', () => { // << 'my pig' is a NEW reason for rebuilding! - t.equal(rebuildCount, 2, 'rebuild called second time') - - ssb.close() - }) - } - }) + setup().then(ssb => { + let rebuildCount = 0 + ssb.rebuild.hook((rebuild, [cb]) => { + t.true(ssb.status().sync.sync, 'rebuild only gets called once indexing is done') // see this twice + rebuildCount++ + rebuild.call(ssb, cb) + + if (rebuildCount === 1) { + manager.rebuild('my pig', () => { // << 'my pig' is a NEW reason for rebuilding! + t.equal(rebuildCount, 2, 'rebuild called second time') + + ssb.close() + }) + } + }) - const manager = new Manager(ssb) + const manager = new Manager(ssb) - manager.rebuild('my fish') - manager.rebuild('my dog', () => t.pass('callback in the middle')) - manager.rebuild('my cat', () => { - t.equal(rebuildCount, 1, 'first rebuild completed') + manager.rebuild('my fish') + manager.rebuild('my dog', () => t.pass('callback in the middle')) + manager.rebuild('my cat', () => { + t.equal(rebuildCount, 1, 'first rebuild completed') + }) }) }) From 6ac1aa44b5ed15307442316769c4885deb79fcbf Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 28 Sep 2023 13:55:12 +0200 Subject: [PATCH 3/5] Fix replicate test --- test/replicate.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/replicate.test.js b/test/replicate.test.js index 8fab13c7..fb71b541 100644 --- a/test/replicate.test.js +++ b/test/replicate.test.js @@ -3,7 +3,7 @@ const { promisify: p } = require('util') const Keys = require('ssb-keys') const { Server, replicate } = require('./helpers') -test('replicate group members', async t => { +test('replicate group members', t => { t.plan(7) // 3 calls to request // 1 successful shutdown @@ -50,15 +50,15 @@ test('replicate group members', async t => { if (i === expected.length) testPersistence() }) - try { - const { groupId: aliceGroup } = await p(alice.tribes.create)({}) - await p(alice.tribes.invite)(aliceGroup, [bob.id], {}) - - const { groupId: bobGroup } = await p(bob.tribes.create)({}) - await p(bob.tribes.invite)(bobGroup, [alice.id, celId, ericId], {}) - } catch (err) { + p(alice.tribes.create)({}).then(({ groupId: aliceGroup }) => { + return p(alice.tribes.invite)(aliceGroup, [bob.id], {}) + }).then(() => { + return p(bob.tribes.create)({}) + }).then(({ groupId: bobGroup }) => { + return p(bob.tribes.invite)(bobGroup, [alice.id, celId, ericId], {}) + }).catch((err) => { t.fail(err) - } + }) function testPersistence () { // NOTE: Currently we do not persist membership because it's simpler. From a805a59ed74ea1e8a1cb2a263dfcf259f0d9dbc0 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 28 Sep 2023 14:01:56 +0200 Subject: [PATCH 4/5] Fix listen test --- test/listen.test.js | 57 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/test/listen.test.js b/test/listen.test.js index 8e5c884d..3a48ac9c 100644 --- a/test/listen.test.js +++ b/test/listen.test.js @@ -8,7 +8,7 @@ const listen = require('../listen') // TODO this is... not listen any more // we may need to rename this -test('listen.addMember', async t => { +test('listen.addMember', t => { const alice = Server() const bob = Server() @@ -50,22 +50,24 @@ test('listen.addMember', async t => { }) ) - const groupData = await p(alice.tribes.create)({}) + p(alice.tribes.create)({}).then((groupData) => { groupId = groupData.groupId // eslint-disable-line - await p(alice.tribes.invite)(groupId, [bob.id], {}) - await p(replicate)({ from: alice, to: bob }) - - setTimeout(() => { - t.equal(aliceHeard, 2, 'alice: heard add-members [[alice], [bob]]') - t.equal(bobHeard, 2, 'bob heard add-members [[bob], [admin]]') - - alice.close() - bob.close() - t.end() - }, 500) + return p(alice.tribes.invite)(groupId, [bob.id], {}) + }).then(() => { + return p(replicate)({ from: alice, to: bob }) + }).then(() => { + setTimeout(() => { + t.equal(aliceHeard, 2, 'alice: heard add-members [[alice], [bob]]') + t.equal(bobHeard, 2, 'bob heard add-members [[bob], [admin]]') + + alice.close() + bob.close() + t.end() + }, 500) + }) }) -test('listen.poBox', async t => { +test('listen.poBox', t => { const alice = Server() const bob = Server() @@ -75,17 +77,18 @@ test('listen.poBox', async t => { listen.poBox(alice, m => aliceHeard++) listen.poBox(bob, m => bobHeard++) - const { groupId } = await p(alice.tribes.create)({ addPOBox: true }) - await p(alice.tribes.invite)(groupId, [bob.id], {}) - - await p(replicate)({ from: alice, to: bob }) - - setTimeout(() => { - t.equal(aliceHeard, 1, 'alice heard own po-box') - t.equal(bobHeard, 1, 'bob heard po-box') - - alice.close() - bob.close() - t.end() - }, 500) // wait for bob to do two rebuilds + p(alice.tribes.create)({ addPOBox: true }).then(({ groupId }) => { + return p(alice.tribes.invite)(groupId, [bob.id], {}) + }).then(() => { + return p(replicate)({ from: alice, to: bob }) + }).then(() => { + setTimeout(() => { + t.equal(aliceHeard, 1, 'alice heard own po-box') + t.equal(bobHeard, 1, 'bob heard po-box') + + alice.close() + bob.close() + t.end() + }, 500) // wait for bob to do two rebuilds + }) }) From 8f0e7fe8c642aec5d83fb0ea6059a6daba5eb7af Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Thu, 28 Sep 2023 14:07:17 +0200 Subject: [PATCH 5/5] Fix new author listener add test --- test/api/add-new-author-listener.test.js | 26 +++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/test/api/add-new-author-listener.test.js b/test/api/add-new-author-listener.test.js index e225e95b..c1adae32 100644 --- a/test/api/add-new-author-listener.test.js +++ b/test/api/add-new-author-listener.test.js @@ -2,7 +2,7 @@ const test = require('tape') const { promisify: p } = require('util') const { Server, replicate } = require('../helpers') -test('addNewAuthorListener', async t => { +test('addNewAuthorListener', t => { t.plan(6) const admin = Server({ name: 'admin', debug: false }) // me @@ -43,23 +43,21 @@ test('addNewAuthorListener', async t => { }, 1000) }) - try { - const groupData = await p(admin.tribes.create)({}).catch(t.fail) - // this makes a group, but also in the background, alerts the newAuthorListeners - // so the above listener can get called *before* we have access to the groupId + // this makes a group, but also in the background, alerts the newAuthorListeners + // so the above listener can get called *before* we have access to the groupId + p(admin.tribes.create)({}).then((groupData) => { groupId = groupData.groupId - await p(admin.tribes.invite)(groupId, [newPerson.id], { text: 'ahoy' }).catch(err => { - console.error('invite failed:', err) - t.fail(err) - }) - - await p(admin.tribes.invite)(groupId, [newPerson.id], { text: 'ahoy again' }).catch(t.fail) + return p(admin.tribes.invite)(groupId, [newPerson.id], { text: 'ahoy' }) + }).then(() => { + return p(admin.tribes.invite)(groupId, [newPerson.id], { text: 'ahoy again' }) + }).then(() => { // we want to test that duplicate adds dont fire the addNewAuthorListener multiple times, // unfortunately there are race conditions around calculating the new authors, so // we have added a small delay here + // later note: no we haven't? - p(replicate)({ from: admin, to: newPerson, name }) - } catch (err) { + return p(replicate)({ from: admin, to: newPerson, name }) + }).catch((err) => { t.fail(err) - } + }) })