Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 159246d

Browse files
author
Pedro Santos
committed
chore: update all the tests to use async/await
1 parent c110c4a commit 159246d

File tree

10 files changed

+340
-318
lines changed

10 files changed

+340
-318
lines changed

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"mocha": "^5.2.0",
7171
"multihashes": "~0.4.14",
7272
"ncp": "^2.0.0",
73+
"p-retry": "^4.1.0",
7374
"pretty-bytes": "^5.1.0",
7475
"promisify-es6": "^1.0.3",
7576
"random-fs": "^1.0.3",

test/circuit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ describe('circuit', () => {
5656
return tests[test].connect(nodeA, nodeB, relay)
5757
})
5858

59-
it('send', (done) => {
60-
tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api, done)
59+
it('send', () => {
60+
return tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api)
6161
})
6262
})
6363
})

test/exchange-files.js

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
99

10-
const series = require('async/series')
11-
const parallel = require('async/parallel')
12-
const waterfall = require('async/waterfall')
1310
const crypto = require('crypto')
1411
const pretty = require('pretty-bytes')
1512
const randomFs = require('random-fs')
@@ -124,69 +121,66 @@ describe('exchange files', function () {
124121
daemon2 = nodes[1]
125122
})
126123

127-
before('connect', function (done) {
128-
series([
129-
(cb) => parallel([
130-
(cb) => daemon1.api.id(cb),
131-
(cb) => daemon2.api.id(cb)
132-
], (err, ids) => {
133-
expect(err).to.not.exist()
134-
id1 = ids[0]
135-
id2 = ids[1]
136-
cb()
137-
}),
138-
(cb) => daemon1.api.swarm.connect(id2.addresses[0], cb),
139-
(cb) => daemon2.api.swarm.connect(id1.addresses[0], cb),
140-
(cb) => parallel([
141-
(cb) => daemon1.api.swarm.peers(cb),
142-
(cb) => daemon2.api.swarm.peers(cb)
143-
], (err, peers) => {
144-
expect(err).to.not.exist()
145-
expect(peers[0].map((p) => p.peer.toB58String())).to.include(id2.id)
146-
expect(peers[1].map((p) => p.peer.toB58String())).to.include(id1.id)
147-
cb()
148-
})
149-
], done)
124+
before('connect', async function () {
125+
this.timeout(timeout)
126+
127+
const ids = await Promise.all([
128+
daemon1.api.id(),
129+
daemon2.api.id()
130+
])
131+
132+
id1 = ids[0]
133+
id2 = ids[1]
134+
135+
await daemon1.api.swarm.connect(id2.addresses[0])
136+
await daemon2.api.swarm.connect(id1.addresses[0])
137+
138+
const peers = await Promise.all([
139+
daemon1.api.swarm.peers(),
140+
daemon2.api.swarm.peers()
141+
])
142+
143+
expect(peers[0].map((p) => p.peer.toB58String())).to.include(id2.id)
144+
expect(peers[1].map((p) => p.peer.toB58String())).to.include(id1.id)
150145
})
151146

152147
after('stop nodes', function () {
153148
return Promise.all([daemon1, daemon2].map((node) => node.stop()))
154149
})
155150

156151
describe('cat file', () => sizes.forEach((size) => {
157-
it(`${name}: ${pretty(size)}`, function (done) {
152+
it(`${name}: ${pretty(size)}`, async function () {
153+
this.timeout(timeout)
154+
158155
const data = crypto.randomBytes(size)
159156

160-
waterfall([
161-
(cb) => daemon1.api.add(data, cb),
162-
(res, cb) => daemon2.api.cat(res[0].hash, cb)
163-
], (err, file) => {
164-
expect(err).to.not.exist()
165-
expect(file).to.eql(data)
166-
done()
167-
})
157+
const res = await daemon1.api.add(data)
158+
const file = await daemon2.api.cat(res[0].hash)
159+
160+
expect(file).to.eql(data)
168161
})
169162
}))
170163

171164
if (isWindows()) { return }
172165
// TODO fix dir tests on Windows
173166

174167
describe('get directory', () => depth.forEach((d) => dirs.forEach((num) => {
175-
it(`${name}: depth: ${d}, num: ${num}`, function () {
168+
it(`${name}: depth: ${d}, num: ${num}`, async function () {
169+
this.timeout(timeout)
170+
176171
const dir = tmpDir()
177-
return randomFs({
172+
173+
await randomFs({
178174
path: dir,
179175
depth: d,
180176
number: num
181-
}).then(() => {
182-
return daemon1.api.addFromFs(dir, { recursive: true })
183-
}).then((res) => {
184-
const hash = res[res.length - 1].hash
185-
return daemon2.api.get(hash)
186-
}).then((res) => {
187-
expect(res).to.exist()
188-
return rmDir(dir)
189177
})
178+
const res = await daemon1.api.addFromFs(dir, { recursive: true })
179+
const hash = res[res.length - 1].hash
180+
const getRes = await daemon2.api.get(hash)
181+
expect(getRes).to.exist()
182+
183+
return rmDir(dir)
190184
})
191185
})))
192186
})

0 commit comments

Comments
 (0)