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

Commit 1cb16c8

Browse files
author
Pedro Santos
committed
refactor: miscellaneous before and after methods to async syntax
1 parent dd446e8 commit 1cb16c8

File tree

5 files changed

+23
-94
lines changed

5 files changed

+23
-94
lines changed

src/miscellaneous/dns.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,11 @@ module.exports = (createCommon, options) => {
1313
this.retries(3)
1414
let ipfs
1515

16-
before(function (done) {
17-
// CI takes longer to instantiate the daemon, so we need to increase the
18-
// timeout for the before step
19-
this.timeout(60 * 1000)
20-
21-
common.setup((err, factory) => {
22-
expect(err).to.not.exist()
23-
factory.spawnNode((err, node) => {
24-
expect(err).to.not.exist()
25-
ipfs = node
26-
done()
27-
})
28-
})
16+
before(async () => {
17+
ipfs = await common.setup()
2918
})
3019

31-
after((done) => {
32-
common.teardown(done)
33-
})
20+
after(() => common.teardown())
3421

3522
it('should non-recursively resolve ipfs.io', async () => {
3623
const res = await ipfs.dns('ipfs.io', { recursive: false })

src/miscellaneous/id.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,11 @@ module.exports = (createCommon, options) => {
1212
this.timeout(60 * 1000)
1313
let ipfs
1414

15-
before(function (done) {
16-
common.setup((err, factory) => {
17-
expect(err).to.not.exist()
18-
factory.spawnNode((err, node) => {
19-
expect(err).to.not.exist()
20-
ipfs = node
21-
done()
22-
})
23-
})
15+
before(async () => {
16+
ipfs = await common.setup()
2417
})
2518

26-
after((done) => {
27-
common.teardown(done)
28-
})
19+
after(() => common.teardown())
2920

3021
it('should get the node ID', async () => {
3122
const res = await ipfs.id()

src/miscellaneous/resolve.js

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const isIpfs = require('is-ipfs')
66
const loadFixture = require('aegir/fixtures')
77
const hat = require('hat')
88
const multibase = require('multibase')
9-
const { spawnNodeWithId } = require('../utils/spawn')
10-
const { connect } = require('../utils/swarm')
119
const { getDescribe, getIt, expect } = require('../utils/mocha')
1210

1311
module.exports = (createCommon, options) => {
@@ -18,22 +16,12 @@ module.exports = (createCommon, options) => {
1816
describe('.resolve', function () {
1917
this.timeout(60 * 1000)
2018
let ipfs
21-
let nodeId
22-
23-
before(function (done) {
24-
common.setup((err, factory) => {
25-
expect(err).to.not.exist()
26-
spawnNodeWithId(factory, (err, node) => {
27-
expect(err).to.not.exist()
28-
29-
ipfs = node
30-
nodeId = node.peerId.id
31-
done()
32-
})
33-
})
19+
20+
before(async () => {
21+
ipfs = await common.setup()
3422
})
3523

36-
after(common.teardown)
24+
after(() => common.teardown())
3725

3826
it('should resolve an IPFS hash', async () => {
3927
const content = loadFixture('test/fixtures/testfile.txt', 'interface-ipfs-core')
@@ -89,25 +77,14 @@ module.exports = (createCommon, options) => {
8977
})
9078

9179
it('should resolve IPNS link recursively', async function () {
92-
this.timeout(20 * 1000)
93-
94-
// Ensure another node exists for publishing to
95-
await new Promise((resolve, reject) => {
96-
common.setup((err, factory) => {
97-
if (err) return reject(err)
98-
spawnNodeWithId(factory, (err, node) => {
99-
if (err) return reject(err)
100-
const addr = node.peerId.addresses.find((a) => a.includes('127.0.0.1'))
101-
connect(ipfs, addr, resolve)
102-
})
103-
})
104-
})
80+
const node = await common.setup()
81+
await ipfs.swarm.connect(node.peerId.addresses.find((a) => a.includes('127.0.0.1')))
10582

10683
const [{ path }] = await ipfs.add(Buffer.from('should resolve a record recursive === true'))
10784
const { id: keyId } = await ipfs.key.gen('key-name', { type: 'rsa', size: 2048 })
10885

10986
await ipfs.name.publish(path, { allowOffline: true })
110-
await ipfs.name.publish(`/ipns/${nodeId}`, { allowOffline: true, key: 'key-name', resolve: false })
87+
await ipfs.name.publish(`/ipns/${ipfs.peerId.id}`, { allowOffline: true, key: 'key-name', resolve: false })
11188

11289
return expect(await ipfs.resolve(`/ipns/${keyId}`, { recursive: true }))
11390
.to.eq(`/ipfs/${path}`)

src/miscellaneous/stop.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,16 @@ module.exports = (createCommon, options) => {
88
const it = getIt(options)
99
const common = createCommon()
1010

11-
describe('.stop', () => {
11+
describe('.stop', function () {
12+
this.timeout(60 * 1000)
1213
let ipfs
1314

14-
before(function (done) {
15-
// CI takes longer to instantiate the daemon, so we need to increase the
16-
// timeout for the before step
17-
this.timeout(60 * 1000)
18-
19-
common.setup((err, factory) => {
20-
expect(err).to.not.exist()
21-
factory.spawnNode((err, node) => {
22-
expect(err).to.not.exist()
23-
ipfs = node
24-
done()
25-
})
26-
})
27-
})
28-
29-
after((done) => {
30-
common.teardown(done)
15+
before(async () => {
16+
ipfs = await common.setup()
3117
})
3218

3319
// must be last test to run
34-
it('should stop the node2', async function () {
20+
it('should stop the node', async function () {
3521
this.timeout(10 * 1000)
3622

3723
await ipfs.stop()

src/miscellaneous/version.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,15 @@ module.exports = (createCommon, options) => {
88
const it = getIt(options)
99
const common = createCommon()
1010

11-
describe('.version', () => {
11+
describe('.version', function () {
12+
this.timeout(60 * 1000)
1213
let ipfs
1314

14-
before(function (done) {
15-
// CI takes longer to instantiate the daemon, so we need to increase the
16-
// timeout for the before step
17-
this.timeout(60 * 1000)
18-
19-
common.setup((err, factory) => {
20-
expect(err).to.not.exist()
21-
factory.spawnNode((err, node) => {
22-
expect(err).to.not.exist()
23-
ipfs = node
24-
done()
25-
})
26-
})
15+
before(async () => {
16+
ipfs = await common.setup()
2717
})
2818

29-
after((done) => {
30-
common.teardown(done)
31-
})
19+
after(() => common.teardown())
3220

3321
it('should get the node version', async () => {
3422
const result = await ipfs.version()

0 commit comments

Comments
 (0)