From 18a5c7d52b796ba340e98740f7a85463538a8a4d Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 22 Oct 2021 16:03:37 +0200 Subject: [PATCH] test(pubsub): include line breaks in topic/data --- test/ipns-pubsub.js | 3 +-- test/pubsub.js | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/test/ipns-pubsub.js b/test/ipns-pubsub.js index 158db3fc..52aaba5b 100644 --- a/test/ipns-pubsub.js +++ b/test/ipns-pubsub.js @@ -22,8 +22,7 @@ const namespace = '/record/' const ipfsRef = '/ipfs/QmPFVLPmp9zv5Z5KUqLhe2EivAGccQW2r7M7jhVJGLZoZU' -// TODO: unskip after https://github.com/ipfs/js-ipfs/pull/3922 and https://github.com/ipfs/go-ipfs/pull/8183 both ship -describe.skip('ipns-pubsub', function () { +describe('ipns-pubsub', function () { let nodes = [] let factory diff --git a/test/pubsub.js b/test/pubsub.js index c8accd7a..87069d29 100644 --- a/test/pubsub.js +++ b/test/pubsub.js @@ -27,8 +27,7 @@ const daemonOptions = { const timeout = 20e3 -// TODO: unskip after https://github.com/ipfs/js-ipfs/pull/3922 and https://github.com/ipfs/go-ipfs/pull/8183 both ship -describe.skip('pubsub', function () { +describe('pubsub', function () { this.timeout(60 * 1000) const tests = { @@ -100,7 +99,7 @@ describe.skip('pubsub', function () { }) it('should exchange non ascii data', function () { - const data = uint8ArrayFromString('你好世界') + const data = uint8ArrayFromString('你好世界 zażółć gęślą jaźń') const topic = 'pubsub-non-ascii' const subscriber = () => new Promise((resolve) => { @@ -150,6 +149,32 @@ describe.skip('pubsub', function () { publisher() ]) }) + + it('should exchange data over a topic with unicode and newlines', function () { + const data = uint8ArrayFromString('你好世界\nzażółć\r\ngęślą\njaźń') + const topic = 'pubsub\n你好世界\r\njaźń' + + const subscriber = () => new Promise((resolve) => { + daemon2.api.pubsub.subscribe(topic, (msg) => { + expect(uint8ArrayEquals(data, msg.data)).to.be.true() + expect(msg).to.have.property('seqno') + expect(msg.seqno).to.be.an.instanceof(Uint8Array) + expect(msg).to.have.property('topicIDs').and.to.include(topic) + expect(msg).to.have.property('from', daemon1.api.peerId.id) + resolve() + }) + }) + + const publisher = async () => { + await waitForTopicPeer(topic, daemon2.api.peerId, daemon1) + await daemon1.api.pubsub.publish(topic, data) + } + + return Promise.all([ + subscriber(), + publisher() + ]) + }) }) }) })