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

Commit cb07f73

Browse files
author
Pedro Santos
committed
refactor: pin before and after methods to async syntax
1 parent 187c89e commit cb07f73

File tree

3 files changed

+29
-80
lines changed

3 files changed

+29
-80
lines changed

src/pin/add.js

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

4-
const each = require('async/each')
54
const { fixtures } = require('./utils')
65
const { getDescribe, getIt, expect } = require('../utils/mocha')
76

@@ -11,32 +10,18 @@ module.exports = (createCommon, options) => {
1110
const common = createCommon()
1211

1312
describe('.pin.add', function () {
14-
this.timeout(50 * 1000)
13+
this.timeout(60 * 1000)
1514

1615
let ipfs
1716

18-
before(function (done) {
19-
// CI takes longer to instantiate the daemon, so we need to increase the
20-
// timeout for the before step
21-
this.timeout(60 * 1000)
22-
23-
common.setup((err, factory) => {
24-
expect(err).to.not.exist()
25-
factory.spawnNode((err, node) => {
26-
expect(err).to.not.exist()
27-
ipfs = node
28-
populate()
29-
})
30-
})
31-
32-
function populate () {
33-
each(fixtures.files, (file, cb) => {
34-
ipfs.add(file.data, { pin: false }, cb)
35-
}, done)
36-
}
17+
before(async () => {
18+
ipfs = await common.setup()
19+
await Promise.all(fixtures.files.map(file => {
20+
return ipfs.add(file.data, { pin: false })
21+
}))
3722
})
3823

39-
after((done) => common.teardown(done))
24+
after(() => common.teardown())
4025

4126
it('should add a pin', async () => {
4227
const pinset = await ipfs.pin.add(fixtures.files[0].cid, { recursive: false })

src/pin/ls.js

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

4-
const series = require('async/series')
54
const { fixtures } = require('./utils')
65
const { getDescribe, getIt, expect } = require('../utils/mocha')
76

@@ -11,43 +10,25 @@ module.exports = (createCommon, options) => {
1110
const common = createCommon()
1211

1312
describe('.pin.ls', function () {
14-
this.timeout(50 * 1000)
13+
this.timeout(60 * 1000)
1514

1615
let ipfs
1716

18-
before(function (done) {
19-
// CI takes longer to instantiate the daemon, so we need to increase the
20-
// timeout for the before step
21-
this.timeout(60 * 1000)
22-
23-
common.setup((err, factory) => {
24-
expect(err).to.not.exist()
25-
factory.spawnNode((err, node) => {
26-
expect(err).to.not.exist()
27-
ipfs = node
28-
populate()
29-
})
30-
})
31-
32-
function populate () {
33-
series([
34-
// two files wrapped in directories, only root CID pinned recursively
35-
cb => {
36-
const dir = fixtures.directory.files.map((file) => ({ path: file.path, content: file.data }))
37-
ipfs.add(dir, { pin: false, cidVersion: 0 }, cb)
38-
},
39-
cb => ipfs.pin.add(fixtures.directory.cid, { recursive: true }, cb),
40-
// a file (CID pinned recursively)
41-
cb => ipfs.add(fixtures.files[0].data, { pin: false, cidVersion: 0 }, cb),
42-
cb => ipfs.pin.add(fixtures.files[0].cid, { recursive: true }, cb),
43-
// a single CID (pinned directly)
44-
cb => ipfs.add(fixtures.files[1].data, { pin: false, cidVersion: 0 }, cb),
45-
cb => ipfs.pin.add(fixtures.files[1].cid, { recursive: false }, cb)
46-
], done)
47-
}
17+
before(async () => {
18+
ipfs = await common.setup()
19+
// two files wrapped in directories, only root CID pinned recursively
20+
const dir = fixtures.directory.files.map((file) => ({ path: file.path, content: file.data }))
21+
await ipfs.add(dir, { pin: false, cidVersion: 0 })
22+
await ipfs.pin.add(fixtures.directory.cid, { recursive: true })
23+
// a file (CID pinned recursively)
24+
await ipfs.add(fixtures.files[0].data, { pin: false, cidVersion: 0 })
25+
await ipfs.pin.add(fixtures.files[0].cid, { recursive: true })
26+
// a single CID (pinned directly)
27+
await ipfs.add(fixtures.files[1].data, { pin: false, cidVersion: 0 })
28+
await ipfs.pin.add(fixtures.files[1].cid, { recursive: false })
4829
})
4930

50-
after((done) => common.teardown(done))
31+
after(() => common.teardown())
5132

5233
// 1st, because ipfs.add pins automatically
5334
it('should list all recursive pins', async () => {

src/pin/rm.js

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

4-
const series = require('async/series')
54
const { fixtures } = require('./utils')
65
const { getDescribe, getIt, expect } = require('../utils/mocha')
76

@@ -11,35 +10,19 @@ module.exports = (createCommon, options) => {
1110
const common = createCommon()
1211

1312
describe('.pin.rm', function () {
14-
this.timeout(50 * 1000)
13+
this.timeout(60 * 1000)
1514

1615
let ipfs
1716

18-
before(function (done) {
19-
// CI takes longer to instantiate the daemon, so we need to increase the
20-
// timeout for the before step
21-
this.timeout(60 * 1000)
22-
23-
common.setup((err, factory) => {
24-
expect(err).to.not.exist()
25-
factory.spawnNode((err, node) => {
26-
expect(err).to.not.exist()
27-
ipfs = node
28-
populate()
29-
})
30-
})
31-
32-
function populate () {
33-
series([
34-
cb => ipfs.add(fixtures.files[0].data, { pin: false }, cb),
35-
cb => ipfs.pin.add(fixtures.files[0].cid, { recursive: true }, cb),
36-
cb => ipfs.add(fixtures.files[1].data, { pin: false }, cb),
37-
cb => ipfs.pin.add(fixtures.files[1].cid, { recursive: false }, cb)
38-
], done)
39-
}
17+
before(async () => {
18+
ipfs = await common.setup()
19+
await ipfs.add(fixtures.files[0].data, { pin: false })
20+
await ipfs.pin.add(fixtures.files[0].cid, { recursive: true })
21+
await ipfs.add(fixtures.files[1].data, { pin: false })
22+
await ipfs.pin.add(fixtures.files[1].cid, { recursive: false })
4023
})
4124

42-
after((done) => common.teardown(done))
25+
after(() => common.teardown())
4326

4427
it('should remove a recursive pin', async () => {
4528
const removedPinset = await ipfs.pin.rm(fixtures.files[0].cid, { recursive: true })

0 commit comments

Comments
 (0)