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

Commit fb3590b

Browse files
committed
fix: bitswap tests
1 parent fe1acd5 commit fb3590b

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

test/core/bitswap.spec.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ const isNode = require('detect-node')
1616
const multihashing = require('multihashing-async')
1717
const CID = require('cids')
1818

19+
const IPFS = require('../../src/core')
20+
1921
const DaemonFactory = require('ipfsd-ctl')
20-
const df = DaemonFactory.create()
22+
const df = DaemonFactory.create({ type: 'js', exec: `./src/cli/bin.js` })
23+
24+
const dfProc = DaemonFactory.create({ type: 'proc', exec: IPFS })
2125

2226
// This gets replaced by '../utils/create-repo-browser.js' in the browser
2327
const createTempRepo = require('../utils/create-repo-nodejs.js')
2428

25-
const IPFS = require('../../src/core')
26-
2729
function makeBlock (callback) {
2830
const d = Buffer.from(`IPFS is awesome ${Math.random()}`)
2931

@@ -67,7 +69,13 @@ function connectNodes (remoteNode, inProcNode, callback) {
6769
let nodes = []
6870

6971
function addNode (inProcNode, callback) {
70-
df.spawn({ type: 'js', exec: `./src/cli/bin.js` }, (err, ipfsd) => {
72+
df.spawn({
73+
config: {
74+
Addresses: {
75+
Swarm: [`/ip4/127.0.0.1/tcp/0/ws`]
76+
}
77+
}
78+
}, (err, ipfsd) => {
7179
expect(err).to.not.exist()
7280
nodes.push(ipfsd)
7381
connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api))
@@ -82,8 +90,7 @@ describe('bitswap', function () {
8290
beforeEach(function (done) {
8391
this.timeout(60 * 1000)
8492

85-
let options = {
86-
repo: createTempRepo(),
93+
let config = {
8794
config: {
8895
Addresses: {
8996
Swarm: []
@@ -98,7 +105,7 @@ describe('bitswap', function () {
98105
}
99106

100107
if (isNode) {
101-
options = Object.assign(options, {
108+
config = Object.assign(config, {
102109
config: {
103110
Addresses: {
104111
Swarm: ['/ip4/127.0.0.1/tcp/0']
@@ -107,18 +114,21 @@ describe('bitswap', function () {
107114
})
108115
}
109116

110-
inProcNode = new IPFS(options)
111-
inProcNode.on('ready', () => done())
117+
dfProc.spawn({ config }, (err, _ipfsd) => {
118+
expect(err).to.not.exist()
119+
nodes.push(_ipfsd)
120+
inProcNode = _ipfsd.api
121+
done()
122+
})
112123
})
113124

114125
afterEach(function (done) {
115126
this.timeout(80 * 1000)
116127
const tasks = nodes.map((node) => (cb) => node.stop(cb))
117-
tasks.push((cb) => setTimeout(() => inProcNode.stop(() => cb()), 500))
118128
parallel(tasks, (err) => {
119129
expect(err).to.not.exist()
120130
nodes = []
121-
done(err)
131+
done()
122132
})
123133
})
124134

0 commit comments

Comments
 (0)