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

Commit ae5a200

Browse files
committed
feat: add support for a simpler and async test setup
1 parent d8b65ef commit ae5a200

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+651
-301
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"ipld-dag-pb": "^0.18.1",
5656
"is-ipfs": "~0.6.1",
5757
"is-plain-object": "^3.0.0",
58-
"it-pushable": "^1.2.1",
58+
"it-pushable": "^1.3.1",
5959
"libp2p-crypto": "~0.16.0",
6060
"multiaddr": "^6.0.0",
6161
"multibase": "~0.6.0",
@@ -75,7 +75,8 @@
7575
"through2": "^3.0.0"
7676
},
7777
"devDependencies": {
78-
"aegir": "^20.0.0"
78+
"aegir": "^20.3.2",
79+
"ipfsd-ctl": "ipfs/js-ipfsd-ctl#feat/interface-tests"
7980
},
8081
"contributors": [
8182
"Alan Shaw <alan.shaw@protocol.ai>",

src/bitswap/stat.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const { expectIsBitswap } = require('../stats/utils')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
8+
/**
9+
* @param {TestsInterface} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

1216
describe('.bitswap.stat', () => {
17+
this.timeout(60 * 1000)
1318
let ipfs
1419

15-
before(async function () {
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+
before(async () => {
2021
ipfs = await common.setup()
2122
})
2223

@@ -28,9 +29,7 @@ module.exports = (createCommon, options) => {
2829
})
2930

3031
it('should not get bitswap stats when offline', async function () {
31-
this.timeout(60 * 1000)
32-
33-
const node = await createCommon().setup()
32+
const node = await common.node()
3433
await node.stop()
3534

3635
return expect(node.bitswap.stat()).to.eventually.be.rejected()

src/bitswap/wantlist.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const { waitForWantlistKey } = require('./utils')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
8+
/**
9+
* @param {TestsInterface} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

12-
describe('.bitswap.wantlist', () => {
16+
describe('.bitswap.wantlist', function () {
17+
this.timeout(60 * 1000)
1318
let ipfsA
1419
let ipfsB
1520
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
@@ -21,11 +26,9 @@ module.exports = (createCommon, options) => {
2126

2227
ipfsA = await common.setup()
2328
ipfsB = await common.setup()
24-
29+
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
2530
// Add key to the wantlist for ipfsB
2631
ipfsB.block.get(key).catch(() => {})
27-
28-
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
2932
})
3033

3134
after(function () {
@@ -35,22 +38,18 @@ module.exports = (createCommon, options) => {
3538
})
3639

3740
it('should get the wantlist', function () {
38-
this.timeout(60 * 1000)
3941
return waitForWantlistKey(ipfsB, key)
4042
})
4143

4244
it('should get the wantlist by peer ID for a different node', function () {
43-
this.timeout(60 * 1000)
4445
return waitForWantlistKey(ipfsA, key, {
4546
peerId: ipfsB.peerId.id,
4647
timeout: 60 * 1000
4748
})
4849
})
4950

50-
it('should not get the wantlist when offline', async function () {
51-
this.timeout(60 * 1000)
52-
53-
const node = await createCommon().setup()
51+
it('should not get the wantlist when offline', async () => {
52+
const node = await common.node()
5453
await node.stop()
5554

5655
return expect(node.bitswap.wantlist()).to.eventually.be.rejected()

src/block/get.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ const multihash = require('multihashes')
55
const CID = require('cids')
66
const { getDescribe, getIt, expect } = require('../utils/mocha')
77

8-
module.exports = (createCommon, options) => {
8+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
9+
/**
10+
* @param {TestsInterface} common
11+
* @param {Object} options
12+
*/
13+
module.exports = (common, options) => {
914
const describe = getDescribe(options)
1015
const it = getIt(options)
11-
const common = createCommon()
1216

1317
describe('.block.get', () => {
1418
const data = Buffer.from('blorb')

src/block/put.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ const multihash = require('multihashes')
66
const CID = require('cids')
77
const { getDescribe, getIt, expect } = require('../utils/mocha')
88

9-
module.exports = (createCommon, options) => {
9+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
10+
/**
11+
* @param {TestsInterface} common
12+
* @param {Object} options
13+
*/
14+
module.exports = (common, options) => {
1015
const describe = getDescribe(options)
1116
const it = getIt(options)
12-
const common = createCommon()
1317

1418
describe('.block.put', () => {
1519
let ipfs

src/block/rm.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const hat = require('hat')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
8+
/**
9+
* @param {TestsInterface} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

1216
describe('.block.rm', () => {
1317
let ipfs
1418

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

2321
after(() => common.teardown())
2422

src/block/stat.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
const CID = require('cids')
55
const { getDescribe, getIt, expect } = require('../utils/mocha')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
8+
/**
9+
* @param {TestsInterface} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

1216
describe('.block.stat', () => {
1317
const data = Buffer.from('blorb')

src/bootstrap/add.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ const { getDescribe, getIt, expect } = require('../utils/mocha')
66
const invalidArg = 'this/Is/So/Invalid/'
77
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
88

9-
module.exports = (createCommon, options) => {
9+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
10+
/**
11+
* @param {TestsInterface} common
12+
* @param {Object} options
13+
*/
14+
module.exports = (common, options) => {
1015
const describe = getDescribe(options)
1116
const it = getIt(options)
12-
const common = createCommon()
1317

1418
describe('.bootstrap.add', function () {
1519
this.timeout(100 * 1000)

src/bootstrap/list.js

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

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55

6-
module.exports = (createCommon, options) => {
6+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
7+
/**
8+
* @param {TestsInterface} common
9+
* @param {Object} options
10+
*/
11+
module.exports = (common, options) => {
712
const describe = getDescribe(options)
813
const it = getIt(options)
9-
const common = createCommon()
1014

1115
describe('.bootstrap.list', function () {
1216
this.timeout(100 * 1000)
1317

1418
let ipfs
1519

16-
before(async function () {
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-
ipfs = await common.setup()
22-
})
20+
before(async () => { ipfs = await common.setup() })
2321

2422
after(() => common.teardown())
2523

src/bootstrap/rm.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55

6-
module.exports = (createCommon, options) => {
6+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
7+
/**
8+
* @param {TestsInterface} common
9+
* @param {Object} options
10+
*/
11+
module.exports = (common, options) => {
712
const describe = getDescribe(options)
813
const it = getIt(options)
9-
const common = createCommon()
1014

1115
const invalidArg = 'this/Is/So/Invalid/'
1216
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
@@ -16,13 +20,7 @@ module.exports = (createCommon, options) => {
1620

1721
let ipfs
1822

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

2725
after(() => common.teardown())
2826

src/config/get.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,20 @@
44
const { getDescribe, getIt, expect } = require('../utils/mocha')
55
const isPlainObject = require('is-plain-object')
66

7-
module.exports = (createCommon, options) => {
7+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
8+
/**
9+
* @param {TestsInterface} common
10+
* @param {Object} options
11+
*/
12+
module.exports = (common, options) => {
813
const describe = getDescribe(options)
914
const it = getIt(options)
10-
const common = createCommon()
1115

1216
describe('.config.get', function () {
1317
this.timeout(30 * 1000)
1418
let ipfs
1519

16-
before(async function () {
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-
ipfs = await common.setup()
22-
})
20+
before(async () => { ipfs = await common.setup() })
2321

2422
after(() => common.teardown())
2523

src/config/profiles/apply.js

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

44
const { getDescribe, getIt, expect } = require('../../utils/mocha')
5-
6-
module.exports = (createCommon, options) => {
5+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
6+
/**
7+
* @param {TestsInterface} common
8+
* @param {Object} options
9+
*/
10+
module.exports = (common, options) => {
711
const describe = getDescribe(options)
812
const it = getIt(options)
9-
const common = createCommon()
1013

1114
describe('.config.profiles.apply', function () {
1215
this.timeout(30 * 1000)

src/config/profiles/list.js

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

44
const { getDescribe, getIt, expect } = require('../../utils/mocha')
5-
6-
module.exports = (createCommon, options) => {
5+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
6+
/**
7+
* @param {TestsInterface} common
8+
* @param {Object} options
9+
*/
10+
module.exports = (common, options) => {
711
const describe = getDescribe(options)
812
const it = getIt(options)
9-
const common = createCommon()
1013

1114
describe('.config.profiles.list', function () {
1215
this.timeout(30 * 1000)

src/config/replace.js

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

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
5-
6-
module.exports = (createCommon, options) => {
5+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
6+
/**
7+
* @param {TestsInterface} common
8+
* @param {Object} options
9+
*/
10+
module.exports = (common, options) => {
711
const describe = getDescribe(options)
812
const it = getIt(options)
9-
const common = createCommon()
1013

1114
describe('.config.replace', function () {
1215
this.timeout(30 * 1000)

src/config/set.js

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

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
5-
6-
module.exports = (createCommon, options) => {
5+
/** @typedef { import("ipfsd-ctl").TestsInterface } TestsInterface */
6+
/**
7+
* @param {TestsInterface} common
8+
* @param {Object} options
9+
*/
10+
module.exports = (common, options) => {
711
const describe = getDescribe(options)
812
const it = getIt(options)
9-
const common = createCommon()
1013

1114
describe('.config.set', function () {
1215
this.timeout(30 * 1000)

0 commit comments

Comments
 (0)