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

Commit 3f95aab

Browse files
author
Pedro Santos
committed
refactor: name before and after methods to async syntax
1 parent 1cb16c8 commit 3f95aab

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

src/name/publish.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const hat = require('hat')
55

66
const { fixture } = require('./utils')
7-
const { spawnNodeWithId } = require('../utils/spawn')
87
const { getDescribe, getIt, expect } = require('../utils/mocha')
98

109
module.exports = (createCommon, options) => {
@@ -17,41 +16,28 @@ module.exports = (createCommon, options) => {
1716
let ipfs
1817
let nodeId
1918

20-
before(function (done) {
21-
// CI takes longer to instantiate the daemon, so we need to increase the
22-
// timeout for the before step
23-
this.timeout(60 * 1000)
24-
25-
common.setup((err, factory) => {
26-
expect(err).to.not.exist()
27-
28-
spawnNodeWithId(factory, (err, node) => {
29-
expect(err).to.not.exist()
30-
31-
ipfs = node
32-
nodeId = node.peerId.id
33-
34-
ipfs.add(fixture.data, { pin: false }, done)
35-
})
36-
})
19+
before(async () => {
20+
ipfs = await common.setup()
21+
nodeId = ipfs.peerId.id
22+
await ipfs.add(fixture.data, { pin: false })
3723
})
3824

39-
after((done) => common.teardown(done))
25+
after(() => common.teardown())
4026

4127
it('should publish an IPNS record with the default params', async function () {
4228
this.timeout(50 * 1000)
4329

4430
const value = fixture.cid
4531

46-
const res = await ipfs.name.publish(value, { 'allow-offline': true })
32+
const res = await ipfs.name.publish(value, { allowOffline: true })
4733
expect(res).to.exist()
4834
expect(res.name).to.equal(nodeId)
4935
expect(res.value).to.equal(`/ipfs/${value}`)
5036
})
5137

5238
it('should publish correctly with the lifetime option and resolve', async () => {
5339
const [{ path }] = await ipfs.add(Buffer.from('should publish correctly with the lifetime option and resolve'))
54-
await ipfs.name.publish(path, { 'allow-offline': true, resolve: false, lifetime: '2h' })
40+
await ipfs.name.publish(path, { allowOffline: true, resolve: false, lifetime: '2h' })
5541

5642
return expect(await ipfs.name.resolve(`/ipns/${nodeId}`)).to.eq(`/ipfs/${path}`)
5743
})
@@ -66,7 +52,7 @@ module.exports = (createCommon, options) => {
6652
lifetime: '1m',
6753
ttl: '10s',
6854
key: 'self',
69-
'allow-offline': true
55+
allowOffline: true
7056
}
7157

7258
const res = await ipfs.name.publish(value, options)
@@ -84,7 +70,7 @@ module.exports = (createCommon, options) => {
8470
lifetime: '24h',
8571
ttl: '10s',
8672
key: keyName,
87-
'allow-offline': true
73+
allowOffline: true
8874
}
8975

9076
const key = await ipfs.key.gen(keyName, { type: 'rsa', size: 2048 })

src/name/resolve.js

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

5-
const { spawnNodeWithId } = require('../utils/spawn')
65
const { getDescribe, getIt, expect } = require('../utils/mocha')
76
const delay = require('delay')
87
const CID = require('cids')
@@ -16,21 +15,12 @@ module.exports = (createCommon, options) => {
1615
let ipfs
1716
let nodeId
1817

19-
before(function (done) {
20-
common.setup((err, factory) => {
21-
expect(err).to.not.exist()
22-
23-
spawnNodeWithId(factory, (err, node) => {
24-
expect(err).to.not.exist()
25-
26-
ipfs = node
27-
nodeId = node.peerId.id
28-
done()
29-
})
30-
})
18+
before(async () => {
19+
ipfs = await common.setup()
20+
nodeId = ipfs.peerId.id
3121
})
3222

33-
after((done) => common.teardown(done))
23+
after(() => common.teardown())
3424

3525
it('should resolve a record default options', async function () {
3626
this.timeout(20 * 1000)

0 commit comments

Comments
 (0)