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

Commit

Permalink
chore: update all the tests to use async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Santos committed Sep 30, 2019
1 parent da93ced commit ce990bd
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 335 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"mocha": "^5.2.0",
"multihashes": "~0.4.14",
"ncp": "^2.0.0",
"p-retry": "^4.1.0",
"pretty-bytes": "^5.1.0",
"promisify-es6": "^1.0.3",
"random-fs": "^1.0.3",
Expand Down
8 changes: 4 additions & 4 deletions test/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ describe('circuit', () => {

after(() => Promise.all(nodes.map((node) => node.stop())))

it('connect', (done) => {
tests[test].connect(nodeA, nodeB, relay, done)
it('connect', () => {
return tests[test].connect(nodeA, nodeB, relay)
})

it('send', (done) => {
tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api, done)
it('send', () => {
return tests[test].send(nodeA.ipfsd.api, nodeB.ipfsd.api)
})
})
})
Expand Down
78 changes: 33 additions & 45 deletions test/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const series = require('async/series')
const parallel = require('async/parallel')
const waterfall = require('async/waterfall')
const crypto = require('crypto')
const pretty = require('pretty-bytes')
const randomFs = require('random-fs')
Expand Down Expand Up @@ -125,31 +122,27 @@ describe('exchange files', () => {
daemon2 = nodes[1]
})

before('connect', function (done) {
before('connect', async function () {
this.timeout(timeout)

series([
(cb) => parallel([
(cb) => daemon1.api.id(cb),
(cb) => daemon2.api.id(cb)
], (err, ids) => {
expect(err).to.not.exist()
id1 = ids[0]
id2 = ids[1]
cb()
}),
(cb) => daemon1.api.swarm.connect(id2.addresses[0], cb),
(cb) => daemon2.api.swarm.connect(id1.addresses[0], cb),
(cb) => parallel([
(cb) => daemon1.api.swarm.peers(cb),
(cb) => daemon2.api.swarm.peers(cb)
], (err, peers) => {
expect(err).to.not.exist()
expect(peers[0].map((p) => p.peer.toB58String())).to.include(id2.id)
expect(peers[1].map((p) => p.peer.toB58String())).to.include(id1.id)
cb()
})
], done)
const ids = await Promise.all([
daemon1.api.id(),
daemon2.api.id()
])

id1 = ids[0]
id2 = ids[1]

await daemon1.api.swarm.connect(id2.addresses[0])
await daemon2.api.swarm.connect(id1.addresses[0])

const peers = await Promise.all([
daemon1.api.swarm.peers(),
daemon2.api.swarm.peers()
])

expect(peers[0].map((p) => p.peer.toB58String())).to.include(id2.id)
expect(peers[1].map((p) => p.peer.toB58String())).to.include(id1.id)
})

after('stop nodes', function () {
Expand All @@ -159,43 +152,38 @@ describe('exchange files', () => {
})

describe('cat file', () => sizes.forEach((size) => {
it(`${name}: ${pretty(size)}`, function (done) {
it(`${name}: ${pretty(size)}`, async function () {
this.timeout(timeout)

const data = crypto.randomBytes(size)

waterfall([
(cb) => daemon1.api.add(data, cb),
(res, cb) => daemon2.api.cat(res[0].hash, cb)
], (err, file) => {
expect(err).to.not.exist()
expect(file).to.eql(data)
done()
})
const res = await daemon1.api.add(data)
const file = await daemon2.api.cat(res[0].hash)

expect(file).to.eql(data)
})
}))

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

describe('get directory', () => depth.forEach((d) => dirs.forEach((num) => {
it(`${name}: depth: ${d}, num: ${num}`, function () {
it(`${name}: depth: ${d}, num: ${num}`, async function () {
this.timeout(timeout)

const dir = tmpDir()
return randomFs({

await randomFs({
path: dir,
depth: d,
number: num
}).then(() => {
return daemon1.api.addFromFs(dir, { recursive: true })
}).then((res) => {
const hash = res[res.length - 1].hash
return daemon2.api.get(hash)
}).then((res) => {
expect(res).to.exist()
return rmDir(dir)
})
const res = await daemon1.api.addFromFs(dir, { recursive: true })
const hash = res[res.length - 1].hash
const getRes = await daemon2.api.get(hash)
expect(getRes).to.exist()

return rmDir(dir)
})
})))
})
Expand Down
Loading

0 comments on commit ce990bd

Please sign in to comment.