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

Commit 03b5d6f

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

File tree

3 files changed

+11
-53
lines changed

3 files changed

+11
-53
lines changed

src/name-pubsub/cancel.js

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
const PeerId = require('peer-id')
66

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

109
module.exports = (createCommon, options) => {
@@ -16,26 +15,12 @@ module.exports = (createCommon, options) => {
1615
let ipfs
1716
let nodeId
1817

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

38-
after((done) => common.teardown(done))
23+
after(() => common.teardown())
3924

4025
it('should return false when the name that is intended to cancel is not subscribed', async function () {
4126
this.timeout(60 * 1000)

src/name-pubsub/state.js

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

4-
const { spawnNodeWithId } = require('../utils/spawn')
54
const { getDescribe, getIt, expect } = require('../utils/mocha')
65

76
module.exports = (createCommon, options) => {
@@ -10,26 +9,14 @@ module.exports = (createCommon, options) => {
109
const common = createCommon()
1110

1211
describe('.name.pubsub.state', function () {
12+
this.timeout(60 * 1000)
1313
let ipfs
1414

15-
before(function (done) {
16-
// CI takes longer to instantiate the daemon, so we need to increase the
17-
// timeout for the before step
18-
this.timeout(60 * 1000)
19-
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-
done()
28-
})
29-
})
15+
before(async () => {
16+
ipfs = await common.setup()
3017
})
3118

32-
after((done) => common.teardown(done))
19+
after(() => common.teardown())
3320

3421
it('should get the current state of pubsub', async function () {
3522
this.timeout(50 * 1000)

src/name-pubsub/subs.js

Lines changed: 3 additions & 17 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

87
module.exports = (createCommon, options) => {
@@ -13,24 +12,11 @@ module.exports = (createCommon, options) => {
1312
describe('.name.pubsub.subs', function () {
1413
let ipfs
1514

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-
24-
spawnNodeWithId(factory, (err, node) => {
25-
expect(err).to.not.exist()
26-
27-
ipfs = node
28-
done()
29-
})
30-
})
15+
before(async () => {
16+
ipfs = await common.setup()
3117
})
3218

33-
after((done) => common.teardown(done))
19+
after(() => common.teardown())
3420

3521
it('should get an empty array as a result of subscriptions before any resolve', async function () {
3622
this.timeout(60 * 1000)

0 commit comments

Comments
 (0)