Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
chore: create test case #3465
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Dec 31, 2020
1 parent 7b48f14 commit c1cee88
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/ipfs-http-client/test/pubsub.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-env mocha */
'use strict'

const { expect } = require('aegir/utils/chai')
const { describe, Promise, console } = require('ipfs-utils/src/globalthis')
const all = require('it-all')
const uint8ArrayFromString = require('uint8arrays/from-string')

const f = require('./utils/factory')()

describe('.pubsub', function () {
this.timeout(20 * 1000)
describe('.subscribe', () => {
let ipfs
let ctl

before(async function () {
this.timeout(30 * 1000) // slow CI

ctl = await await f.spawn({
args: '--enable-pubsub-experiment'
})

ipfs = ctl.api
})

after(() => f.clean())

it('.onError when connection is closed', async () => {
const topic = 'gossipboom'
const messages = []
let onError

// eslint-disable-next-line promise/param-names
const error = new Promise((_, reject) => {
onError = reject
})

ipfs.pubsub.subscribe(topic, message => {
messages.push(message)
}, {
onError
})

await ipfs.pubsub.publish(topic, 'hello')
await ipfs.pubsub.publish(topic, 'bye')
// Stop the daemon
await ctl.stop()

await expect(error).to.eventually.be.rejectedWith(/network/ig)
expect(messages).property('length').equal(2)
})
})
})

0 comments on commit c1cee88

Please sign in to comment.