diff --git a/SPEC/STATS.md b/SPEC/STATS.md index 7bcd5f9d..6ce0e226 100644 --- a/SPEC/STATS.md +++ b/SPEC/STATS.md @@ -25,7 +25,9 @@ Where: - `poll` is used to print bandwidth at an interval. - `interval` is the time interval to wait between updating output, if `poll` is true. -`callback` must follow `function (err, stats) {}` signature, where `err` is an error if the operation was not successful. `stats` is an Object containing the following keys: +If `poll` is `true`, then `callback` must follow `function (err, stream) {}` signature, where `err` is an error if the operation was not successful and `stream` is a Readable Stream where you can listen to the event `data` with a listener that must follow `function (stat) {}` signature. + +Otherwise, `callback` must follow `function (err, stat) {}` signature, where `err` is an error and `stat` is an Object containing the following keys: - `totalIn` - `totalOut` diff --git a/js/src/stats.js b/js/src/stats.js index 58703c2e..73607151 100644 --- a/js/src/stats.js +++ b/js/src/stats.js @@ -95,6 +95,26 @@ module.exports = (common) => { }) }) + it('.bw Poll', (done) => { + if (!withGo) { + console.log('Not supported in js-ipfs yet') + return done() + } + + ipfs.stats.bw({poll: true}, (err, res) => { + expect(err).to.not.exist() + expect(res).to.exist() + + res.once('data', (data) => { + expect(data).to.have.a.property('totalIn') + expect(data).to.have.a.property('totalOut') + expect(data).to.have.a.property('rateIn') + expect(data).to.have.a.property('rateOut') + done() + }) + }) + }) + it('.bw Promise', () => { if (!withGo) { console.log('Not supported in js-ipfs yet') @@ -110,6 +130,28 @@ module.exports = (common) => { }) }) + it('.bw Promise Poll', (done) => { + if (!withGo) { + console.log('Not supported in js-ipfs yet') + return + } + + ipfs.stats.bw({poll: true}).then((res) => { + expect(res).to.exist() + + res.once('data', (data) => { + expect(data).to.have.a.property('totalIn') + expect(data).to.have.a.property('totalOut') + expect(data).to.have.a.property('rateIn') + expect(data).to.have.a.property('rateOut') + done() + }) + }).catch(err => { + expect(err).to.not.exist() + done() + }) + }) + it('.repo', (done) => { if (!withGo) { console.log('Not supported in js-ipfs yet')