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

Commit 27beca5

Browse files
Pedro Santosachingbrain
authored andcommitted
chore: update tests to async await (#87)
* chore: update ipfsd-ctl version and use daemon.js util file * chore: update all the tests to use async/await * chore: code review changes * chore: more code review changes * fix: update deps to fix tests
1 parent 4e6a980 commit 27beca5

18 files changed

+393
-512
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"homepage": "https://github.com/ipfs/interop#readme",
4040
"dependencies": {
4141
"aegir": "^20.3.1",
42-
"async": "^2.6.2",
4342
"base64url": "^3.0.0",
4443
"bl": "^3.0.0",
4544
"bs58": "^4.0.1",
4645
"chai": "^4.2.0",
46+
"chai-as-promised": "^7.1.1",
4747
"cids": "~0.7.1",
4848
"cross-env": "^5.2.0",
4949
"delay": "^4.3.0",
@@ -55,12 +55,11 @@
5555
"form-data": "^2.3.3",
5656
"go-ipfs-dep": "~0.4.22",
5757
"hat": "~0.0.3",
58-
"ipfs": "^0.38.0",
59-
"ipfs-http-client": "^38.2.1",
60-
"ipfs-repo": "~0.26.6",
58+
"ipfs": "^0.39.0",
59+
"ipfs-http-client": "^39.0.2",
6160
"ipfs-unixfs": "~0.1.16",
6261
"ipfsd-ctl": "~0.47.4",
63-
"ipns": "~0.5.1",
62+
"ipns": "^0.6.1",
6463
"is-ci": "^2.0.0",
6564
"is-os": "^1.0.1",
6665
"left-pad": "^1.3.0",
@@ -70,6 +69,7 @@
7069
"mocha": "^5.2.0",
7170
"multihashes": "~0.4.14",
7271
"ncp": "^2.0.0",
72+
"p-retry": "^4.1.0",
7373
"pretty-bytes": "^5.1.0",
7474
"promisify-es6": "^1.0.3",
7575
"random-fs": "^1.0.3",

test/cid-version-agnostic.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const expect = chai.expect
7-
chai.use(dirtyChai)
84
const hat = require('hat')
95
const CID = require('cids')
6+
const { expect } = require('./utils/chai')
7+
108
const { spawnGoDaemon, spawnJsDaemon } = require('./utils/daemon')
119

1210
const jsDaemonOptions = {

test/circuit.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
/* eslint-env mocha */
33
'use strict'
44

5-
const chai = require('chai')
6-
const dirtyChai = require('dirty-chai')
7-
chai.use(dirtyChai)
8-
95
const all = require('./circuit/all')
106
const browser = require('./circuit/browser')
117

@@ -56,8 +52,8 @@ describe('circuit', () => {
5652
return tests[test].connect(nodeA, nodeB, relay)
5753
})
5854

59-
it('send', (done) => {
60-
tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api, done)
55+
it('send', () => {
56+
return tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api)
6157
})
6258
})
6359
})

test/exchange-files.js

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
/* eslint-env mocha */
33
'use strict'
44

5-
const chai = require('chai')
6-
const dirtyChai = require('dirty-chai')
7-
const expect = chai.expect
8-
chai.use(dirtyChai)
9-
10-
const series = require('async/series')
11-
const parallel = require('async/parallel')
12-
const waterfall = require('async/waterfall')
135
const crypto = require('crypto')
146
const pretty = require('pretty-bytes')
157
const randomFs = require('random-fs')
@@ -20,8 +12,8 @@ const hat = require('hat')
2012
const isCi = require('is-ci')
2113
const isWindows = require('is-os').isWindows
2214
const os = require('os')
23-
2415
const rmDir = promisify(rimraf)
16+
const { expect } = require('./utils/chai')
2517

2618
const { spawnGoDaemon, spawnJsDaemon } = require('./utils/daemon')
2719

@@ -119,74 +111,66 @@ describe('exchange files', function () {
119111
let id2
120112

121113
before('spawn nodes', async function () {
122-
const nodes = await Promise.all(tests[name].map(fn => fn()))
123-
daemon1 = nodes[0]
124-
daemon2 = nodes[1]
114+
[daemon1, daemon2] = await Promise.all(tests[name].map(fn => fn()))
125115
})
126116

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)
117+
before('connect', async function () {
118+
this.timeout(timeout); // eslint-disable-line
119+
120+
[id1, id2] = await Promise.all([
121+
daemon1.api.id(),
122+
daemon2.api.id()
123+
])
124+
125+
await daemon1.api.swarm.connect(id2.addresses[0])
126+
await daemon2.api.swarm.connect(id1.addresses[0])
127+
128+
const [peer1, peer2] = await Promise.all([
129+
daemon1.api.swarm.peers(),
130+
daemon2.api.swarm.peers()
131+
])
132+
133+
expect(peer1.map((p) => p.peer.toB58String())).to.include(id2.id)
134+
expect(peer2.map((p) => p.peer.toB58String())).to.include(id1.id)
150135
})
151136

152137
after('stop nodes', function () {
153138
return Promise.all([daemon1, daemon2].map((node) => node.stop()))
154139
})
155140

156141
describe('cat file', () => sizes.forEach((size) => {
157-
it(`${name}: ${pretty(size)}`, function (done) {
142+
it(`${name}: ${pretty(size)}`, async function () {
143+
this.timeout(timeout)
144+
158145
const data = crypto.randomBytes(size)
159146

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-
})
147+
const res = await daemon1.api.add(data)
148+
const file = await daemon2.api.cat(res[0].hash)
149+
150+
expect(file).to.eql(data)
168151
})
169152
}))
170153

171154
if (isWindows()) { return }
172155
// TODO fix dir tests on Windows
173156

174157
describe('get directory', () => depth.forEach((d) => dirs.forEach((num) => {
175-
it(`${name}: depth: ${d}, num: ${num}`, function () {
158+
it(`${name}: depth: ${d}, num: ${num}`, async function () {
159+
this.timeout(timeout)
160+
176161
const dir = tmpDir()
177-
return randomFs({
162+
163+
await randomFs({
178164
path: dir,
179165
depth: d,
180166
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)
189167
})
168+
const res = await daemon1.api.addFromFs(dir, { recursive: true })
169+
const hash = res[res.length - 1].hash
170+
const getRes = await daemon2.api.get(hash)
171+
expect(getRes).to.exist()
172+
173+
return rmDir(dir)
190174
})
191175
})))
192176
})

0 commit comments

Comments
 (0)