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

Commit c1172c2

Browse files
author
Pedro Santos
committed
chore: update assertion on failure tests
1 parent d02e535 commit c1172c2

Some content is hidden

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

42 files changed

+171
-485
lines changed

src/bitswap/stat.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ module.exports = (common, options) => {
3131
const node = await common.node()
3232
await node.stop()
3333

34-
try {
35-
await node.api.bitswap.stat()
36-
expect.fail('bitswap.stat() did not throw an error as expected')
37-
} catch (err) {
38-
expect(err).to.exist()
39-
}
34+
await expect(node.api.bitswap.stat()).to.be.rejected()
4035
})
4136
})
4237
}

src/bitswap/wantlist.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ module.exports = (common, options) => {
4242
const node = await common.node()
4343
await node.stop()
4444

45-
try {
46-
await node.bitswap.wantlist()
47-
expect.fail('bitswap.wantlist() did not throw an error as expected')
48-
} catch (err) {
49-
expect(err).to.exist()
50-
}
45+
await expect(node.api.bitswap.wantlist()).to.be.rejected()
5146
})
5247
})
5348
}

src/block/get.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,8 @@ module.exports = (common, options) => {
8282
expect(block.data).to.eql(input)
8383
})
8484

85-
it('should return an error for an invalid CID', async () => {
86-
try {
87-
await ipfs.block.get('invalid')
88-
expect.fail('should have returned an error for invalid argument')
89-
} catch (err) {
90-
expect(err).to.be.an.instanceof(Error)
91-
}
85+
it('should return an error for an invalid CID', () => {
86+
return expect(ipfs.block.get('invalid')).to.eventually.be.rejected.and.be.an.instanceOf(Error)
9287
})
9388
})
9489
}

src/block/put.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,10 @@ module.exports = (common, options) => {
7272
expect(block.cid.multihash).to.eql(multihash.fromB58String(expectedHash))
7373
})
7474

75-
it('should error with array of blocks', async () => {
75+
it('should error with array of blocks', () => {
7676
const blob = Buffer.from('blorb')
7777

78-
try {
79-
await ipfs.block.put([blob, blob])
80-
expect.fail('should have returned an error for array of blocks')
81-
} catch (err) {
82-
expect(err).to.be.an.instanceof(Error)
83-
}
78+
return expect(ipfs.block.put([blob, blob])).to.eventually.be.rejected.and.be.an.instanceOf(Error)
8479
})
8580
})
8681
}

src/block/stat.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,12 @@ module.exports = (common, options) => {
3535
expect(stats).to.have.property('size')
3636
})
3737

38-
it('should return error for missing argument', async () => {
39-
try {
40-
await ipfs.block.stat(null)
41-
expect.fail('should have thrown for missing parameter')
42-
} catch (err) {
43-
expect(err).to.be.an.instanceof(Error)
44-
}
38+
it('should return error for missing argument', () => {
39+
return expect(ipfs.block.stat(null)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
4540
})
4641

47-
it('should return error for invalid argument', async () => {
48-
try {
49-
await ipfs.block.stat('invalid')
50-
expect.fail('should have thrown for invalid parameter')
51-
} catch (err) {
52-
expect(err).to.be.an.instanceof(Error)
53-
}
42+
it('should return error for invalid argument', () => {
43+
return expect(ipfs.block.stat('invalid')).to.eventually.be.rejected.and.be.an.instanceOf(Error)
5444
})
5545
})
5646
}

src/bootstrap/add.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ module.exports = (common, options) => {
2626

2727
after(() => common.teardown())
2828

29-
it('should return an error when called with an invalid arg', async () => {
30-
try {
31-
await ipfs.bootstrap.add(invalidArg)
32-
expect.fail('bootstrap.add() did not throw when called with an invalid arg')
33-
} catch (err) {
34-
expect(err).to.be.an.instanceof(Error)
35-
}
29+
it('should return an error when called with an invalid arg', () => {
30+
return expect(ipfs.bootstrap.add(invalidArg)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
3631
})
3732

3833
it('should return a list containing the bootstrap peer when called with a valid arg (ip4)', async () => {

src/bootstrap/rm.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@ module.exports = (common, options) => {
2424

2525
after(() => common.teardown())
2626

27-
it('should return an error when called with an invalid arg', async () => {
28-
try {
29-
await ipfs.bootstrap.rm(invalidArg)
30-
expect.fail('bootstrap.rm() did not throw when called with an invalid arg')
31-
} catch (err) {
32-
expect(err).to.be.an.instanceof(Error)
33-
}
27+
it('should return an error when called with an invalid arg', () => {
28+
return expect(ipfs.bootstrap.rm(invalidArg)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
3429
})
3530

3631
it('should return an empty list because no peers removed when called without an arg or options', async () => {

src/config/get.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,12 @@ module.exports = (common, options) => {
3838
expect(swarmAddrs).to.exist()
3939
})
4040

41-
it('should fail on non valid key', async () => {
42-
try {
43-
await ipfs.config.get(1234)
44-
expect.fail('config.get() did not throw on non valid key')
45-
} catch (err) {
46-
expect(err).to.exist()
47-
}
41+
it('should fail on non valid key', () => {
42+
return expect(ipfs.config.get(1234)).to.eventually.be.rejected()
4843
})
4944

50-
it('should fail on non existent key', async () => {
51-
try {
52-
await ipfs.config.get('Bananas')
53-
expect.fail('config.get() did not throw on non existent key')
54-
} catch (err) {
55-
expect(err).to.exist()
56-
}
45+
it('should fail on non existent key', () => {
46+
return expect(ipfs.config.get('Bananas')).to.eventually.be.rejected()
5747
})
5848
})
5949
}

src/config/set.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,12 @@ module.exports = (common, options) => {
6969
expect(result).to.deep.equal(val)
7070
})
7171

72-
it('should fail on non valid key', async () => {
73-
try {
74-
await ipfs.config.set(Buffer.from('heeey'), '')
75-
expect.fail('config.set() did not throw on non valid key')
76-
} catch (err) {
77-
expect(err).to.exist()
78-
}
72+
it('should fail on non valid key', () => {
73+
return expect(ipfs.config.set(Buffer.from('heeey'), '')).to.eventually.be.rejected()
7974
})
8075

81-
it('should fail on non valid value', async () => {
82-
try {
83-
await ipfs.config.set('Fruit', Buffer.from('abc'))
84-
expect.fail('config.set() did not throw on non valid value')
85-
} catch (err) {
86-
expect(err).to.exist()
87-
}
76+
it('should fail on non valid value', () => {
77+
return expect(ipfs.config.set('Fruit', Buffer.from('abc'))).to.eventually.be.rejected()
8878
})
8979
})
9080
}

src/dht/find-peer.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@ module.exports = (common, options) => {
3737
expect(nodeAddresses).to.include(peerAddresses[0])
3838
})
3939

40-
it('should fail to find other peer if peer does not exist', async () => {
41-
try {
42-
await nodeA.dht.findPeer('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ')
43-
expect.fail('dht.findPeer() did not throw when peer does not exist')
44-
} catch (err) {
45-
expect(err).to.exist()
46-
}
40+
it('should fail to find other peer if peer does not exist', () => {
41+
return expect(nodeA.dht.findPeer('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ')).to.eventually.be.rejected()
4742
})
4843
})
4944
}

src/dht/find-provs.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ module.exports = (common, options) => {
7272

7373
const cidV0 = await fakeCid()
7474

75-
try {
76-
await nodeA.dht.findProvs(cidV0, options)
77-
expect.fail('dht.findProvs() did not throw as expected')
78-
} catch (err) {
79-
expect(err).to.exist()
80-
}
75+
await expect(nodeA.dht.findProvs(cidV0, options)).to.be.rejected()
8176
})
8277
})
8378
}

src/dht/get.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@ module.exports = (common, options) => {
2727

2828
after(() => common.teardown())
2929

30-
it('should error when getting a non-existent key from the DHT', async () => {
31-
try {
32-
await nodeA.dht.get('non-existing', { timeout: 100 })
33-
expect.fail('dht.get() did not throw when getting a non-existent key from the DHT')
34-
} catch (err) {
35-
expect(err).to.be.an.instanceof(Error)
36-
}
30+
it('should error when getting a non-existent key from the DHT', () => {
31+
return expect(nodeA.dht.get('non-existing', { timeout: 100 })).to.eventually.be.rejected.and.be.an.instanceOf(Error)
3732
})
3833

3934
it('should get a value after it was put on another node', async () => {

src/dht/provide.js

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,13 @@ module.exports = (common, options) => {
3232
await ipfs.dht.provide(new CID(res[0].hash))
3333
})
3434

35-
it('should not provide if block not found locally', async () => {
35+
it('should not provide if block not found locally', () => {
3636
const cid = new CID('Qmd7qZS4T7xXtsNFdRoK1trfMs5zU94EpokQ9WFtxdPxsZ')
3737

38-
try {
39-
await ipfs.dht.provide(cid)
40-
expect.fail('dht.provide() did not throw when block is not found locally')
41-
} catch (err) {
42-
expect(err).to.exist()
43-
expect(err.message).to.include('not found locally')
44-
}
38+
return expect(ipfs.dht.provide(cid)).to.eventually.be.rejected
39+
.and.be.an.instanceOf(Error)
40+
.and.have.property('message')
41+
.that.include('not found locally')
4542
})
4643

4744
it('should allow multiple CIDs to be passed', async () => {
@@ -64,22 +61,12 @@ module.exports = (common, options) => {
6461
await ipfs.dht.provide(cid)
6562
})
6663

67-
it('should error on non CID arg', async () => {
68-
try {
69-
await ipfs.dht.provide({})
70-
expect.fail('ipfs.dht.provide() did not throw on non CID arg')
71-
} catch (err) {
72-
expect(err).to.exist()
73-
}
64+
it('should error on non CID arg', () => {
65+
return expect(ipfs.dht.provide({})).to.eventually.be.rejected()
7466
})
7567

76-
it('should error on array containing non CID arg', async () => {
77-
try {
78-
await ipfs.dht.provide([{}])
79-
expect.fail('ipfs.dht.provide() did not throw on array containing non CID arg')
80-
} catch (err) {
81-
expect(err).to.exist()
82-
}
68+
it('should error on array containing non CID arg', () => {
69+
return expect(ipfs.dht.provide([{}])).to.eventually.be.rejected()
8370
})
8471
})
8572
}

src/files-mfs/cp.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ module.exports = (common, options) => {
2323

2424
after(() => common.teardown())
2525

26-
it('should copy file, expect error', async () => {
26+
it('should copy file, expect error', () => {
2727
const testDir = `/test-${hat()}`
2828

29-
try {
30-
await ipfs.files.cp(`${testDir}/c`, `${testDir}/b`)
31-
expect.fail('files.cp() did not throw as expected on copy file')
32-
} catch (err) {
33-
expect(err).to.exist()
34-
}
29+
return expect(ipfs.files.cp(`${testDir}/c`, `${testDir}/b`)).to.eventually.be.rejected()
3530
})
3631

3732
it('should copy file, expect no error', async () => {
@@ -42,15 +37,10 @@ module.exports = (common, options) => {
4237
await ipfs.files.cp(`${testDir}/a`, `${testDir}/b`)
4338
})
4439

45-
it('should copy dir, expect error', async () => {
40+
it('should copy dir, expect error', () => {
4641
const testDir = `/test-${hat()}`
4742

48-
try {
49-
await ipfs.files.cp(`${testDir}/lv1/lv3`, `${testDir}/lv1/lv4`)
50-
expect.fail('files.cp() did not throw as expected on copy dir')
51-
} catch (err) {
52-
expect(err).to.exist()
53-
}
43+
return expect(ipfs.files.cp(`${testDir}/lv1/lv3`, `${testDir}/lv1/lv4`)).to.eventually.be.rejected()
5444
})
5545

5646
it('should copy dir, expect no error', async () => {

src/files-mfs/ls.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ module.exports = (common, options) => {
2323

2424
after(() => common.teardown())
2525

26-
it('should not ls not found file/dir, expect error', async () => {
26+
it('should not ls not found file/dir, expect error', () => {
2727
const testDir = `/test-${hat()}`
2828

29-
try {
30-
await ipfs.files.ls(`${testDir}/404`)
31-
expect.fail('files.ls() did not throw when file/dir was not found')
32-
} catch (err) {
33-
expect(err).to.exist()
34-
}
29+
return expect(ipfs.files.ls(`${testDir}/404`)).to.eventually.be.rejected()
3530
})
3631

3732
it('should ls directory', async () => {

src/files-mfs/mkdir.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,8 @@ module.exports = (common, options) => {
3434
return ipfs.files.mkdir(`${testDir}/lv1/lv2`, { p: true })
3535
})
3636

37-
it('should not make already existent directory', async () => {
38-
try {
39-
await ipfs.files.mkdir('/')
40-
expect.fail('files.mkdir() did not throw when making already existent directory')
41-
} catch (err) {
42-
expect(err).to.exist()
43-
}
37+
it('should not make already existent directory', () => {
38+
return expect(ipfs.files.mkdir('/')).to.eventually.be.rejected()
4439
})
4540
})
4641
}

src/files-mfs/mv.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,10 @@ module.exports = (common, options) => {
2626
})
2727
after(() => common.teardown())
2828

29-
it('should not move not found file/dir, expect error', async () => {
29+
it('should not move not found file/dir, expect error', () => {
3030
const testDir = `/test-${hat()}`
3131

32-
try {
33-
await ipfs.files.mv(`${testDir}/404`, `${testDir}/a`)
34-
expect.fail('files.mv() did not throw while moving not found file/dir')
35-
} catch (err) {
36-
expect(err).to.exist()
37-
}
32+
return expect(ipfs.files.mv(`${testDir}/404`, `${testDir}/a`)).to.eventually.be.rejected()
3833
})
3934

4035
it('should move file, expect no error', async () => {

src/files-mfs/read.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ module.exports = (common, options) => {
2323

2424
after(() => common.teardown())
2525

26-
it('should not read not found, expect error', async () => {
26+
it('should not read not found, expect error', () => {
2727
const testDir = `/test-${hat()}`
2828

29-
try {
30-
await ipfs.files.read(`${testDir}/404`)
31-
expect.fail('files.read() did not throw when reading not found file/dir')
32-
} catch (err) {
33-
expect(err).to.exist()
34-
expect(err.message).to.contain('does not exist')
35-
}
29+
return expect(ipfs.files.cp(`${testDir}/c`, `${testDir}/b`)).to.eventually.be.rejected
30+
.and.be.an.instanceOf(Error)
31+
.and.to.have.property('message')
32+
.that.include('does not exist')
3633
})
3734

3835
it('should read file', async () => {

src/files-mfs/rm.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ module.exports = (common, options) => {
2222

2323
after(() => common.teardown())
2424

25-
it('should not remove not found file/dir, expect error', async () => {
25+
it('should not remove not found file/dir, expect error', () => {
2626
const testDir = `/test-${hat()}`
2727

28-
try {
29-
await ipfs.files.rm(`${testDir}/a`)
30-
expect.fail('files.read() did not throw when removing not found file/dir')
31-
} catch (err) {
32-
expect(err).to.exist()
33-
}
28+
return expect(ipfs.files.rm(`${testDir}/a`)).to.eventually.be.rejected()
3429
})
3530

3631
it('should remove file, expect no error', async () => {

0 commit comments

Comments
 (0)