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

Commit

Permalink
chore: update tests to async await (#87)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Pedro Santos authored and achingbrain committed Nov 8, 2019
1 parent 4e6a980 commit 27beca5
Show file tree
Hide file tree
Showing 18 changed files with 393 additions and 512 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
"homepage": "https://github.com/ipfs/interop#readme",
"dependencies": {
"aegir": "^20.3.1",
"async": "^2.6.2",
"base64url": "^3.0.0",
"bl": "^3.0.0",
"bs58": "^4.0.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cids": "~0.7.1",
"cross-env": "^5.2.0",
"delay": "^4.3.0",
Expand All @@ -55,12 +55,11 @@
"form-data": "^2.3.3",
"go-ipfs-dep": "~0.4.22",
"hat": "~0.0.3",
"ipfs": "^0.38.0",
"ipfs-http-client": "^38.2.1",
"ipfs-repo": "~0.26.6",
"ipfs": "^0.39.0",
"ipfs-http-client": "^39.0.2",
"ipfs-unixfs": "~0.1.16",
"ipfsd-ctl": "~0.47.4",
"ipns": "~0.5.1",
"ipns": "^0.6.1",
"is-ci": "^2.0.0",
"is-os": "^1.0.1",
"left-pad": "^1.3.0",
Expand All @@ -70,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
6 changes: 2 additions & 4 deletions test/cid-version-agnostic.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const hat = require('hat')
const CID = require('cids')
const { expect } = require('./utils/chai')

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

const jsDaemonOptions = {
Expand Down
8 changes: 2 additions & 6 deletions test/circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
chai.use(dirtyChai)

const all = require('./circuit/all')
const browser = require('./circuit/browser')

Expand Down Expand Up @@ -56,8 +52,8 @@ describe('circuit', () => {
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
92 changes: 38 additions & 54 deletions test/exchange-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
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 All @@ -20,8 +12,8 @@ const hat = require('hat')
const isCi = require('is-ci')
const isWindows = require('is-os').isWindows
const os = require('os')

const rmDir = promisify(rimraf)
const { expect } = require('./utils/chai')

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

Expand Down Expand Up @@ -119,74 +111,66 @@ describe('exchange files', function () {
let id2

before('spawn nodes', async function () {
const nodes = await Promise.all(tests[name].map(fn => fn()))
daemon1 = nodes[0]
daemon2 = nodes[1]
[daemon1, daemon2] = await Promise.all(tests[name].map(fn => fn()))
})

before('connect', function (done) {
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)
before('connect', async function () {
this.timeout(timeout); // eslint-disable-line

[id1, id2] = await Promise.all([
daemon1.api.id(),
daemon2.api.id()
])

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

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

expect(peer1.map((p) => p.peer.toB58String())).to.include(id2.id)
expect(peer2.map((p) => p.peer.toB58String())).to.include(id1.id)
})

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

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 27beca5

Please sign in to comment.