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

Commit f00b03d

Browse files
author
Pedro Santos
committed
refactor: stats before and after methods to async syntax
1 parent 25a99bf commit f00b03d

File tree

5 files changed

+28
-79
lines changed

5 files changed

+28
-79
lines changed

src/stats/bitswap.js

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

4-
const { getDescribe, getIt, expect } = require('../utils/mocha')
4+
const { getDescribe, getIt } = require('../utils/mocha')
55
const { expectIsBitswap } = require('./utils')
66

77
module.exports = (createCommon, options) => {
@@ -12,22 +12,11 @@ module.exports = (createCommon, options) => {
1212
describe('.stats.bitswap', () => {
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-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
done()
26-
})
27-
})
15+
before(async () => {
16+
ipfs = await common.setup()
2817
})
2918

30-
after((done) => common.teardown(done))
19+
after(() => common.teardown())
3120

3221
it('should get bitswap stats', async () => {
3322
const res = await ipfs.stats.bitswap()

src/stats/bw-pull-stream.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,22 @@
33

44
const { expectIsBandwidth } = require('./utils')
55
const pullToPromise = require('pull-to-promise')
6-
const { getDescribe, getIt, expect } = require('../utils/mocha')
6+
const { getDescribe, getIt } = require('../utils/mocha')
77

88
module.exports = (createCommon, options) => {
99
const describe = getDescribe(options)
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.stats.bwPullStream', () => {
13+
describe('.stats.bwPullStream', function () {
14+
this.timeout(60 * 1000)
1415
let ipfs
1516

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-
})
17+
before(async () => {
18+
ipfs = await common.setup()
2919
})
3020

31-
after((done) => common.teardown(done))
21+
after(() => common.teardown())
3222

3323
it('should get bandwidth stats over pull stream', async () => {
3424
const stream = ipfs.stats.bwPullStream()

src/stats/bw-readable-stream.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,23 @@
22
'use strict'
33

44
const { expectIsBandwidth } = require('./utils')
5-
const { getDescribe, getIt, expect } = require('../utils/mocha')
5+
const { getDescribe, getIt } = require('../utils/mocha')
66
const getStream = require('get-stream')
77

88
module.exports = (createCommon, options) => {
99
const describe = getDescribe(options)
1010
const it = getIt(options)
1111
const common = createCommon()
1212

13-
describe('.stats.bwReadableStream', () => {
13+
describe('.stats.bwReadableStream', function () {
14+
this.timeout(60 * 1000)
1415
let ipfs
1516

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-
})
17+
before(async () => {
18+
ipfs = await common.setup()
2919
})
3020

31-
after((done) => common.teardown(done))
21+
after(() => common.teardown())
3222

3323
it('should get bandwidth stats over readable stream', async () => {
3424
const stream = ipfs.stats.bwReadableStream()

src/stats/bw.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,22 @@
22
'use strict'
33

44
const { expectIsBandwidth } = require('./utils')
5-
const { getDescribe, getIt, expect } = require('../utils/mocha')
5+
const { getDescribe, getIt } = require('../utils/mocha')
66

77
module.exports = (createCommon, options) => {
88
const describe = getDescribe(options)
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.stats.bw', () => {
12+
describe('.stats.bw', function () {
13+
this.timeout(60 * 1000)
1314
let ipfs
1415

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-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
done()
26-
})
27-
})
16+
before(async () => {
17+
ipfs = await common.setup()
2818
})
2919

30-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3121

3222
it('should get bandwidth stats ', async () => {
3323
const res = await ipfs.stats.bw()

src/stats/repo.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,22 @@
22
'use strict'
33

44
const { expectIsRepo } = require('./utils')
5-
const { getDescribe, getIt, expect } = require('../utils/mocha')
5+
const { getDescribe, getIt } = require('../utils/mocha')
66

77
module.exports = (createCommon, options) => {
88
const describe = getDescribe(options)
99
const it = getIt(options)
1010
const common = createCommon()
1111

12-
describe('.stats.repo', () => {
12+
describe('.stats.repo', function () {
13+
this.timeout(60 * 1000)
1314
let ipfs
1415

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-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
done()
26-
})
27-
})
16+
before(async () => {
17+
ipfs = await common.setup()
2818
})
2919

30-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3121

3222
it('should get repo stats', async () => {
3323
const res = await ipfs.stats.repo()

0 commit comments

Comments
 (0)