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

Commit 2a809ec

Browse files
committed
fix: refactor missing pieces and await clean in bitswap tests
1 parent f475252 commit 2a809ec

File tree

7 files changed

+19
-81
lines changed

7 files changed

+19
-81
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@
159159
"multihashing-async": "^0.8.0",
160160
"node-fetch": "^2.3.0",
161161
"p-iteration": "^1.1.8",
162-
"p-map": "^3.0.0",
163162
"p-queue": "^6.1.0",
164163
"peer-book": "^0.9.1",
165164
"peer-id": "~0.12.2",
@@ -212,6 +211,7 @@
212211
"lodash": "^4.17.15",
213212
"ncp": "^2.0.0",
214213
"p-event": "^4.1.0",
214+
"p-map": "^3.0.0",
215215
"qs": "^6.5.2",
216216
"rimraf": "^3.0.0",
217217
"sinon": "^7.4.2",

test/core/bitswap.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('bitswap', function () {
3131
const b = await remote.block.get(block.cid)
3232

3333
expect(b.data).to.eql(block.data)
34-
df.clean()
34+
await df.clean()
3535
})
3636

3737
it('3 peers', async () => {
@@ -55,7 +55,7 @@ describe('bitswap', function () {
5555
expect(await remote2.block.get(block.cid)).to.eql(block)
5656
expect(await proc.block.get(block.cid)).to.eql(block)
5757
}, { concurrency: 3 })
58-
df.clean()
58+
await df.clean()
5959
})
6060
})
6161

@@ -71,7 +71,7 @@ describe('bitswap', function () {
7171
const files = await remote.add([{ path: 'awesome.txt', content: file }])
7272
const data = await proc.cat(files[0].hash)
7373
expect(data).to.eql(file)
74-
df.clean()
74+
await df.clean()
7575
})
7676
})
7777

@@ -84,7 +84,7 @@ describe('bitswap', function () {
8484
expect(err).to.exist()
8585
expect(err.code).to.equal('ERR_INVALID_CID')
8686
} finally {
87-
df.clean()
87+
await df.clean()
8888
}
8989
})
9090
})

test/core/dht.spec.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ describe.skip('dht', () => {
4545
ipfs = ipfsd.api
4646
})
4747

48-
after(() => {
49-
if (ipfsd) {
50-
return ipfsd.stop()
51-
}
52-
})
48+
after(() => df.clean())
5349

5450
describe('put', () => {
5551
it('should error when DHT not available', async () => {

test/core/name.spec.js

+10-45
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ describe('name', function () {
8181

8282
// TODO: unskip when DHT is enabled: https://github.com/ipfs/js-ipfs/pull/1994
8383
describe.skip('work with dht', () => {
84-
let nodes
8584
let nodeA
8685
let nodeB
8786
let nodeC
@@ -115,7 +114,6 @@ describe('name', function () {
115114
], (err, _nodes) => {
116115
expect(err).to.not.exist()
117116

118-
nodes = _nodes
119117
nodeA = _nodes[0].api
120118
nodeB = _nodes[1].api
121119
nodeC = _nodes[2].api
@@ -136,11 +134,7 @@ describe('name', function () {
136134
})
137135
})
138136

139-
after(function (done) {
140-
this.timeout(80 * 1000)
141-
142-
parallel(nodes.map((node) => (cb) => node.stop(cb)), done)
143-
})
137+
after(() => df.clean())
144138

145139
it('should publish and then resolve correctly with the default options', function (done) {
146140
this.timeout(380 * 1000)
@@ -175,32 +169,17 @@ describe('name', function () {
175169
before(async function () {
176170
this.timeout(40 * 1000)
177171
ipfsd = await df.spawn({
178-
exec: IPFS,
179-
args: ['--pass', hat()],
180-
config: {
181-
Bootstrap: [],
182-
Discovery: {
183-
MDNS: {
184-
Enabled: false
185-
},
186-
webRTCStar: {
187-
Enabled: false
188-
}
189-
}
190-
},
191-
preload: { enabled: false }
172+
ipfsOptions: {
173+
pass: hat()
174+
}
192175
})
193176
node = ipfsd.api
194177

195178
const res = await node.id()
196179
nodeId = res.id
197180
})
198181

199-
after(() => {
200-
if (ipfsd) {
201-
return ipfsd.stop()
202-
}
203-
})
182+
after(() => df.clean())
204183

205184
it('should error to publish if does not receive private key', function () {
206185
return expect(node._ipns.publisher.publish(null, ipfsRef))
@@ -322,32 +301,18 @@ describe('name', function () {
322301
before(async function () {
323302
this.timeout(40 * 1000)
324303
ipfsd = await df.spawn({
325-
exec: IPFS,
326-
args: ['--pass', hat(), '--offline'],
327-
config: {
328-
Bootstrap: [],
329-
Discovery: {
330-
MDNS: {
331-
Enabled: false
332-
},
333-
webRTCStar: {
334-
Enabled: false
335-
}
336-
}
337-
},
338-
preload: { enabled: false }
304+
ipfsOptions: {
305+
pass: hat(),
306+
offline: true
307+
}
339308
})
340309
node = ipfsd.api
341310

342311
const res = await node.id()
343312
nodeId = res.id
344313
})
345314

346-
after(() => {
347-
if (ipfsd) {
348-
return ipfsd.stop()
349-
}
350-
})
315+
after(() => df.clean())
351316

352317
it('should resolve an ipfs path correctly', async function () {
353318
const res = await node.add(fixture)

test/core/pin.spec.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ describe('pin', function () {
1515
ipfs = ipfsd.api
1616
})
1717

18-
after(() => {
19-
if (ipfsd) {
20-
return ipfsd.stop()
21-
}
22-
})
18+
after(() => df.clean())
2319

2420
describe('ls', () => {
2521
it('should callback with error for invalid non-string pin type option', (done) => {

test/core/ping.spec.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,7 @@ describe('ping', function () {
163163
})
164164
})
165165

166-
after(async () => {
167-
if (ipfsdA) {
168-
await ipfsdA.stop()
169-
}
170-
})
171-
172-
after(async () => {
173-
if (ipfsdB) {
174-
await ipfsdB.stop()
175-
}
176-
})
177-
178-
after(async () => {
179-
if (ipfsdC) {
180-
await ipfsdC.stop()
181-
}
182-
})
166+
after(() => df.clean())
183167

184168
it('if enabled uses the DHT peer routing to find peer', (done) => {
185169
let messageNum = 0

test/utils/on-and-off.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ function on (tests) {
6363

6464
after(function () {
6565
resetLocaleToSystem()
66-
if (ipfsd) {
67-
this.timeout(15 * 1000)
68-
return ipfsd.stop()
69-
}
66+
df.clean()
7067
})
7168

7269
tests(thing)

0 commit comments

Comments
 (0)