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

Commit 143333b

Browse files
committed
Remove one level of callback nesting
1 parent 0feb397 commit 143333b

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

src/dht.js

+27-37
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,33 @@ module.exports = (common) => {
2424
})
2525

2626
describe('callback API', () => {
27-
describe('.get', (done) => {
28-
it('errors when getting a non-existent key from the DHT', (done) => {
29-
ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => {
30-
expect(err).to.be.an.instanceof(Error)
31-
done()
32-
})
27+
it('.get errors when getting a non-existent key from the DHT', (done) => {
28+
ipfs.dht.get('non-existing', {timeout: '100ms'}, (err, value) => {
29+
expect(err).to.be.an.instanceof(Error)
30+
done()
3331
})
3432
})
35-
describe('.findprovs', () => {
36-
it('finds providers', (done) => {
37-
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
38-
expect(err).to.not.exist
33+
it('.findprovs', (done) => {
34+
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
35+
expect(err).to.not.exist
3936

40-
expect(res).to.be.an('array')
41-
done()
42-
})
37+
expect(res).to.be.an('array')
38+
done()
4339
})
4440
})
4541
})
4642
describe('promise API', () => {
47-
describe('.get', (done) => {
48-
it('errors when getting a non-existent key from the DHT', (done) => {
49-
ipfs.dht.get('non-existing', {timeout: '100ms'}).catch((err) => {
50-
expect(err).to.be.an.instanceof(Error)
51-
done()
52-
})
43+
it('.get errors when getting a non-existent key from the DHT', (done) => {
44+
ipfs.dht.get('non-existing', {timeout: '100ms'}).catch((err) => {
45+
expect(err).to.be.an.instanceof(Error)
46+
done()
5347
})
5448
})
55-
describe('.findprovs', () => {
56-
it('finds providers', (done) => {
57-
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP').then((res) => {
58-
expect(res).to.be.an('array')
59-
done()
60-
}).catch(done)
61-
})
49+
it('.findprovs', (done) => {
50+
ipfs.dht.findprovs('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP').then((res) => {
51+
expect(res).to.be.an('array')
52+
done()
53+
}).catch(done)
6254
})
6355
})
6456
// Tests below are tests that haven't been implemented yet or is not
@@ -79,19 +71,17 @@ module.exports = (common) => {
7971
})
8072
})
8173
})
82-
xdescribe('.put & .get', () => {
83-
it('puts and gets a key value pair in the DHT', (done) => {
84-
peers.a.ipfs.dht.put('scope', 'interplanetary', (err, res) => {
85-
expect(err).to.not.exist
74+
xit('.put and .get a key value pair in the DHT', (done) => {
75+
peers.a.ipfs.dht.put('scope', 'interplanetary', (err, res) => {
76+
expect(err).to.not.exist
8677

87-
expect(res).to.be.an('array')
78+
expect(res).to.be.an('array')
8879

89-
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
90-
peers.b.ipfs.dht.get('scope', (err, value) => {
91-
expect(err).to.not.exist
92-
expect(value).to.be.equal('interplanetary')
93-
done()
94-
})
80+
// bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
81+
peers.b.ipfs.dht.get('scope', (err, value) => {
82+
expect(err).to.not.exist
83+
expect(value).to.be.equal('interplanetary')
84+
done()
9585
})
9686
})
9787
})

0 commit comments

Comments
 (0)