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

Commit 4172720

Browse files
author
Pedro Santos
committed
refactor: files-regular before and after methods to async syntax
1 parent 50eabf6 commit 4172720

17 files changed

+62
-275
lines changed

src/files-regular/add-from-fs.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,14 @@ module.exports = (createCommon, options) => {
1313
const common = createCommon()
1414

1515
describe('.addFromFs', function () {
16-
this.timeout(40 * 1000)
16+
this.timeout(60 * 1000)
1717

1818
const fixturesPath = path.join(__dirname, '../../test/fixtures')
1919
let ipfs
2020

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

36-
after((done) => common.teardown(done))
23+
after(() => common.teardown())
3724

3825
it('should add a directory from the file system', async () => {
3926
const filesPath = path.join(fixturesPath, 'test-folder')

src/files-regular/add-from-stream.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,13 @@ module.exports = (createCommon, options) => {
1111
const common = createCommon()
1212

1313
describe('.addFromStream', function () {
14-
this.timeout(40 * 1000)
14+
this.timeout(60 * 1000)
1515

1616
let ipfs
1717

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-
done()
29-
})
30-
})
31-
})
18+
before(async () => { ipfs = await common.setup() })
3219

33-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3421

3522
it('should add from a stream', async () => {
3623
const stream = new Readable({

src/files-regular/add-from-url.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,13 @@ module.exports = (createCommon, options) => {
1111
const common = createCommon()
1212

1313
describe('.addFromURL', function () {
14-
this.timeout(40 * 1000)
14+
this.timeout(60 * 1000)
1515

1616
let ipfs
1717

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

32-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3321

3422
it('should add from a HTTP URL', async () => {
3523
const text = `TEST${Date.now()}`

src/files-regular/add-pull-stream.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,13 @@ module.exports = (createCommon, options) => {
1212
const common = createCommon()
1313

1414
describe('.addPullStream', function () {
15-
this.timeout(40 * 1000)
15+
this.timeout(60 * 1000)
1616

1717
let ipfs
1818

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)
19+
before(async () => { ipfs = await common.setup() })
2320

24-
common.setup((err, factory) => {
25-
expect(err).to.not.exist()
26-
factory.spawnNode((err, node) => {
27-
expect(err).to.not.exist()
28-
ipfs = node
29-
done()
30-
})
31-
})
32-
})
33-
34-
after((done) => common.teardown(done))
21+
after(() => common.teardown())
3522

3623
it('should add pull stream of valid files and dirs', async function () {
3724
const content = (name) => ({

src/files-regular/add-readable-stream.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,13 @@ module.exports = (createCommon, options) => {
1111
const common = createCommon()
1212

1313
describe('.addReadableStream', function () {
14-
this.timeout(40 * 1000)
14+
this.timeout(60 * 1000)
1515

1616
let ipfs
1717

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

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-
done()
29-
})
30-
})
31-
})
32-
33-
after((done) => common.teardown(done))
20+
after(() => common.teardown())
3421

3522
it('should add readable stream of valid files and dirs', async function () {
3623
const content = (name) => ({

src/files-regular/add.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,9 @@ module.exports = (createCommon, options) => {
1818

1919
let ipfs
2020

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

36-
after((done) => common.teardown(done))
23+
after(() => common.teardown())
3724

3825
it('should add a File', async function () {
3926
if (!supportsFileReader) return this.skip('skip in node')

src/files-regular/cat-pull-stream.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,13 @@ module.exports = (createCommon, options) => {
1111
const common = createCommon()
1212

1313
describe('.catPullStream', function () {
14-
this.timeout(40 * 1000)
14+
this.timeout(60 * 1000)
1515

1616
let ipfs
1717

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-
done()
29-
})
30-
})
31-
})
18+
before(async () => { ipfs = await common.setup() })
3219

3320
before(() => ipfs.add(fixtures.smallFile.data))
34-
3521
after(() => common.teardown())
3622

3723
it('should return a Pull Stream for a CID', async () => {

src/files-regular/cat-readable-stream.js

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,17 @@ module.exports = (createCommon, options) => {
1111
const common = createCommon()
1212

1313
describe('.catReadableStream', function () {
14-
this.timeout(40 * 1000)
14+
this.timeout(60 * 1000)
1515

1616
let ipfs
1717

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-
done()
29-
})
30-
})
18+
before(async () => {
19+
ipfs = await common.setup()
20+
await ipfs.add(fixtures.bigFile.data)
21+
await ipfs.add(fixtures.smallFile.data)
3122
})
3223

33-
before((done) => ipfs.add(fixtures.bigFile.data, done))
34-
before((done) => ipfs.add(fixtures.smallFile.data, done))
35-
36-
after((done) => common.teardown(done))
24+
after(() => common.teardown())
3725

3826
it('should return a Readable Stream for a CID', async () => {
3927
const stream = ipfs.catReadableStream(fixtures.bigFile.cid)

src/files-regular/cat.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,13 @@ module.exports = (createCommon, options) => {
1212
const common = createCommon()
1313

1414
describe('.cat', function () {
15-
this.timeout(40 * 1000)
15+
this.timeout(60 * 1000)
1616

1717
let ipfs
1818

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-
factory.spawnNode((err, node) => {
27-
expect(err).to.not.exist()
28-
ipfs = node
29-
done()
30-
})
31-
})
32-
})
19+
before(async () => { ipfs = await common.setup() })
3320

34-
after((done) => common.teardown(done))
21+
after(() => common.teardown())
3522

3623
before(() => Promise.all([
3724
ipfs.add(fixtures.smallFile.data),

src/files-regular/get-pull-stream.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,15 @@ module.exports = (createCommon, options) => {
1111
const common = createCommon()
1212

1313
describe('.getPullStream', function () {
14-
this.timeout(40 * 1000)
14+
this.timeout(60 * 1000)
1515

1616
let ipfs
1717

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-
done()
29-
})
30-
})
31-
})
18+
before(async () => { ipfs = await common.setup() })
3219

3320
before(() => ipfs.add(fixtures.smallFile.data))
3421

35-
after((done) => common.teardown(done))
22+
after(() => common.teardown())
3623

3724
it('should return a Pull Stream of Pull Streams', async () => {
3825
const stream = ipfs.getPullStream(fixtures.smallFile.cid)

src/files-regular/get-readable-stream.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,16 @@ module.exports = (createCommon, options) => {
1212
const common = createCommon()
1313

1414
describe('.getReadableStream', function () {
15-
this.timeout(40 * 1000)
15+
this.timeout(60 * 1000)
1616

1717
let ipfs
1818

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-
factory.spawnNode((err, node) => {
27-
expect(err).to.not.exist()
28-
ipfs = node
29-
done()
30-
})
31-
})
19+
before(async () => {
20+
ipfs = await common.setup()
21+
await ipfs.add(fixtures.smallFile.data)
3222
})
3323

34-
before((done) => ipfs.add(fixtures.smallFile.data, done))
35-
36-
after((done) => common.teardown(done))
24+
after(() => common.teardown())
3725

3826
it('should return a Readable Stream of Readable Streams', async () => {
3927
const stream = ipfs.getReadableStream(fixtures.smallFile.cid)

src/files-regular/get.js

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
const { fixtures } = require('./utils')
55
const bs58 = require('bs58')
6-
const parallel = require('async/parallel')
76
const CID = require('cids')
87
const { getDescribe, getIt, expect } = require('../utils/mocha')
98

@@ -13,33 +12,17 @@ module.exports = (createCommon, options) => {
1312
const common = createCommon()
1413

1514
describe('.get', function () {
16-
this.timeout(40 * 1000)
15+
this.timeout(60 * 1000)
1716

1817
let ipfs
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-
factory.spawnNode((err, node) => {
28-
expect(err).to.not.exist()
29-
ipfs = node
30-
done()
31-
})
32-
})
33-
})
34-
35-
before((done) => {
36-
parallel([
37-
(cb) => ipfs.add(fixtures.smallFile.data, cb),
38-
(cb) => ipfs.add(fixtures.bigFile.data, cb)
39-
], done)
19+
before(async () => {
20+
ipfs = await common.setup()
21+
await ipfs.add(fixtures.smallFile.data)
22+
await ipfs.add(fixtures.bigFile.data)
4023
})
4124

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

4427
it('should get with a base58 encoded multihash', async () => {
4528
const files = await ipfs.get(fixtures.smallFile.cid)

0 commit comments

Comments
 (0)