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

Commit 43e059a

Browse files
committedNov 27, 2015
tests: Start work on moving to chai
1 parent e8d2454 commit 43e059a

8 files changed

+36
-48
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"babel-plugin-transform-runtime": "^6.1.18",
3030
"babel-preset-es2015": "^6.0.15",
3131
"babel-runtime": "^5.8.34",
32+
"chai": "^3.4.1",
3233
"concurrently": "^1.0.0",
3334
"eslint-config-standard": "^4.4.0",
3435
"eslint-plugin-standard": "^1.3.1",

‎test/.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"globals": {
66
"apiClients": true,
77
"isNode": true,
8-
"assert": true
8+
"expect": true
99
}
1010
}

‎test/api/add.spec.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,21 @@ describe('.add', () => {
3434
})
3535

3636
apiClients['a'].add(file, (err, res) => {
37-
if (err) throw err
37+
expect(err).to.not.exist
3838

3939
const added = res[0] != null ? res[0] : res
40-
assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
41-
assert.equal(added.Name, path.basename(testfilePath))
40+
expect(added).to.have.property('Hash', 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
41+
expect(added).to.have.property('Name', path.basename(testfilePath))
4242
done()
4343
})
4444
})
4545

4646
it('add buffer', done => {
4747
let buf = new Buffer(testfile)
4848
apiClients['a'].add(buf, (err, res) => {
49-
if (err) throw err
50-
51-
assert.equal(res.length, 1)
52-
const added = res[0]
53-
assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
49+
expect(err).to.not.exist
50+
expect(res).to.have.length(1)
51+
expect(res[0]).to.have.property('Hash', 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
5452
done()
5553
})
5654
})
@@ -61,11 +59,9 @@ describe('.add', () => {
6159
}
6260

6361
apiClients['a'].add(testfileBig, (err, res) => {
64-
if (err) throw err
65-
66-
assert.equal(res.length, 1)
67-
const added = res[0]
68-
assert.equal(added.Hash, 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq')
62+
expect(err).to.not.exist
63+
expect(res).to.have.length(1)
64+
expect(res[0]).to.have.a.property('Hash', 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq')
6965
done()
7066
})
7167
})
@@ -76,24 +72,24 @@ describe('.add', () => {
7672
}
7773

7874
apiClients['a'].add(testfilePath, (err, res) => {
79-
if (err) throw err
75+
expect(err).to.not.exist
8076

8177
const added = res[0] != null ? res[0] : res
82-
assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
78+
expect(added).to.have.property('Hash', 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
8379
done()
8480
})
8581
})
8682

8783
it('add a nested dir', done => {
8884
apiClients['a'].add(__dirname + '/../test-folder', { recursive: true }, (err, res) => {
8985
if (isNode) {
90-
if (err) throw err
86+
expect(err).to.not.exist
9187

9288
const added = res[res.length - 1]
93-
assert.equal(added.Hash, 'QmSzLpCVbWnEm3XoTWnv6DT6Ju5BsVoLhzvxKXZeQ2cmdg')
89+
expect(added).to.have.property('Hash', 'QmSzLpCVbWnEm3XoTWnv6DT6Ju5BsVoLhzvxKXZeQ2cmdg')
9490
done()
9591
} else {
96-
assert.equal(err.message, 'Recursive uploads are not supported in the browser')
92+
expect(err.message).to.be.equal('Recursive uploads are not supported in the browser')
9793
done()
9894
}
9995
})
@@ -104,21 +100,21 @@ describe('.add', () => {
104100
stream.push('Hello world')
105101
stream.push(null)
106102
apiClients['a'].add(stream, (err, res) => {
107-
if (err) throw err
103+
expect(err).to.not.exist
108104

109105
const added = res[0] != null ? res[0] : res
110-
assert.equal(added.Hash, 'QmNRCQWfgze6AbBCaT1rkrkV5tJ2aP4oTNPb5JZcXYywve')
106+
expect(added).to.have.a.property('Hash', 'QmNRCQWfgze6AbBCaT1rkrkV5tJ2aP4oTNPb5JZcXYywve')
111107
done()
112108
})
113109
})
114110

115111
it('add url', done => {
116112
const url = 'https://raw.githubusercontent.com/ipfs/js-ipfs-api/2a9cc63d7427353f2145af6b1a768a69e67c0588/README.md'
117113
apiClients['a'].add(url, (err, res) => {
118-
if (err) throw err
114+
expect(err).to.not.exist
119115

120116
const added = res[0] != null ? res[0] : res
121-
assert.equal(added.Hash, 'QmZmHgEX9baxUn3qMjsEXQzG6DyNcrVnwieQQTrpDdrFvt')
117+
expect(added).to.have.a.property('Hash', 'QmZmHgEX9baxUn3qMjsEXQzG6DyNcrVnwieQQTrpDdrFvt')
122118
done()
123119
})
124120
})

‎test/api/block.spec.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ describe('.block', () => {
66

77
it('block.put', done => {
88
apiClients['a'].block.put(blorb, (err, res) => {
9-
if (err) throw err
10-
const store = res.Key
11-
assert.equal(store, 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
9+
expect(err).to.not.exist
10+
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
1211
done()
1312
})
1413
})
1514

1615
it('block.get', done => {
1716
apiClients['a'].block.get(blorbKey, (err, res) => {
18-
if (err) throw err
17+
expect(err).to.not.exist
1918

2019
let buf = ''
2120
res
2221
.on('data', function (data) { buf += data })
2322
.on('end', function () {
24-
assert.equal(buf, 'blorb')
23+
expect(buf).to.be.equal('blorb')
2524
done()
2625
})
2726
})

‎test/api/cat.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe('.cat', () => {
4444

4545
// Do not blow out the memory of nodejs :)
4646
streamEqual(res, testfileBig, (err, equal) => {
47-
if (err) throw err
48-
assert(equal)
47+
expect(err).to.not.exist
48+
expect(equal).to.be.true
4949
done()
5050
})
5151
})

‎test/api/commands.spec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
describe('.commands', () => {
44
it('lists commands', done => {
55
apiClients['a'].commands((err, res) => {
6-
if (err) {
7-
throw err
8-
}
9-
assert(res)
6+
expect(err).to.not.exist
7+
expect(res).to.exist
108
done()
119
})
1210
})

‎test/api/config.spec.js

+7-13
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@ describe('.config', () => {
66
const confVal = 'arbitraryVal'
77

88
apiClients['a'].config.set(confKey, confVal, (err, res) => {
9-
if (err) throw err
9+
expect(err).to.not.exist
1010
apiClients['a'].config.get(confKey, (err, res) => {
11-
if (err) throw err
12-
assert.equal(res.Value, confVal)
11+
expect(err).to.not.exist
12+
expect(res).to.have.a.property('Value', confVal)
1313
done()
1414
})
1515
})
1616
})
1717

1818
it('.config.show', done => {
1919
apiClients['c'].config.show((err, res) => {
20-
if (err) {
21-
throw err
22-
}
23-
24-
assert(res)
20+
expect(err).to.not.exist
21+
expect(res).to.exist
2522
done()
2623
})
2724
})
@@ -32,11 +29,8 @@ describe('.config', () => {
3229
}
3330

3431
apiClients['c'].config.replace(__dirname + '/../r-config.json', (err, res) => {
35-
if (err) {
36-
throw err
37-
}
38-
39-
assert.equal(res, null)
32+
expect(err).to.not.exist
33+
expect(res).to.be.equal(null)
4034
done()
4135
})
4236
})

‎test/setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const ipfsAPI = require('../src/index.js')
44
const apiAddrs = require('./tmp-disposable-nodes-addrs.json')
55

6-
global.assert = require('assert')
6+
global.expect = require('chai').expect
77
global.apiClients = {} // a, b, c
88
global.isNode = !global.window
99

0 commit comments

Comments
 (0)
This repository has been archived.