Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
test(pubsub): include line breaks in topic/data
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Nov 17, 2021
1 parent f9407ce commit 18a5c7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
3 changes: 1 addition & 2 deletions test/ipns-pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 28 additions & 3 deletions test/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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()
])
})
})
})
})

0 comments on commit 18a5c7d

Please sign in to comment.