Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 4bb4dab

Browse files
committed
Make pubsub tests runnable within normal test suite
1 parent 6c7f595 commit 4bb4dab

File tree

6 files changed

+19
-86
lines changed

6 files changed

+19
-86
lines changed

src/api/pubsub.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const promisify = require('promisify-es6')
44
const bs58 = require('bs58')
55
var Base64 = require('js-base64').Base64
66
var Stream = require('stream')
7-
// const Wreck = require('wreck')
87
var http = require('http')
98

109
let activeSubscriptions = []
@@ -22,8 +21,8 @@ const addSubscription = (subscriptions, topic) => {
2221
return subscriptions.concat([topic])
2322
}
2423

25-
module.exports = (send) => {
26-
const api = {
24+
module.exports = (send, config) => {
25+
return {
2726
sub: promisify((topic, options, callback) => {
2827
if (typeof options === 'function') {
2928
callback = options
@@ -42,10 +41,12 @@ module.exports = (send) => {
4241
return callback(new Error('Already subscribed to ' + topic), null)
4342
}
4443

45-
// we're using http.get here to have more control
44+
// we're using http.get here to have more control over the request
45+
// and avoid refactoring of the request-api where wreck is gonna be
46+
// replaced by fetch (https://github.com/ipfs/js-ipfs-api/pull/355)
4647
const request = http.get({
47-
host: 'localhost',
48-
port: 5001,
48+
host: config.host,
49+
port: config.port,
4950
path: '/api/v0/pubsub/sub/' + topic
5051
}, function (response) {
5152
response.on('data', function (d) {
@@ -101,6 +102,4 @@ module.exports = (send) => {
101102
})
102103
})
103104
}
104-
105-
return api
106105
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function IpfsAPI (hostOrMultiaddr, port, opts) {
3636
}
3737

3838
const requestAPI = getRequestAPI(config)
39-
const cmds = loadCommands(requestAPI)
39+
const cmds = loadCommands(requestAPI, config)
4040
cmds.send = requestAPI
4141
cmds.Buffer = Buffer
4242

src/load-commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ function requireCommands () {
5858
return cmds
5959
}
6060

61-
function loadCommands (send) {
61+
function loadCommands (send, config) {
6262
const files = requireCommands()
6363
const cmds = {}
6464

6565
Object.keys(files).forEach((file) => {
66-
cmds[file] = files[file](send)
66+
cmds[file] = files[file](send, config)
6767
})
6868

6969
return cmds

test.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/factory/daemon-spawner.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,6 @@ function Factory () {
5252
}
5353
}
5454

55-
function spawnLocalNode (callback) {
56-
console.log("Spawn local node")
57-
ipfsd.local((err, node) => {
58-
if (err) {
59-
return callback(err)
60-
}
61-
62-
console.log("start daemon")
63-
node.startDaemon((err, ipfs) => {
64-
console.log("started")
65-
if (err) {
66-
return callback(err)
67-
}
68-
69-
callback(null, node)
70-
})
71-
})
72-
}
73-
7455
function spawnEphemeralNode (callback) {
7556
ipfsd.disposable((err, node) => {
7657
if (err) {

test/ipfs-api/pubsub.spec.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
const expect = require('chai').expect
66
const isNode = require('detect-node')
77
const FactoryClient = require('../factory/factory-client')
8-
const ipfsApi = require('../../src')
9-
10-
const useLocalDaemon = true
118

129
const topicName = 'js-ipfs-api-tests'
1310

@@ -28,20 +25,18 @@ describe('.pubsub', () => {
2825
let fc
2926

3027
before(function (done) {
31-
this.timeout(20 * 1000) // slow CI
32-
// fc = new FactoryClient()
33-
// fc.spawnNode(null, null, useLocalDaemon, (err, node) => {
34-
// console.log("aaaa", err, node)
35-
// expect(err).to.not.exist
36-
// if(err) done(err)
37-
ipfs = ipfsApi()
28+
fc = new FactoryClient()
29+
fc.spawnNode((err, node) => {
30+
expect(err).to.not.exist
31+
if (err) done(err)
32+
ipfs = node
3833
done()
39-
// })
34+
})
4035
})
4136

42-
// after((done) => {
43-
// // fc.dismantle(done)
44-
// })
37+
after((done) => {
38+
fc.dismantle(done)
39+
})
4540

4641
describe('.publish', () => {
4742
it('message from string', (done) => {

0 commit comments

Comments
 (0)