Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d311dc5

Browse files
bmordandryajov
authored andcommitted
adds a test for createProgressBar
1 parent cb42844 commit d311dc5

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

src/cli/commands/files/add.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const pull = require('pull-stream')
88
const paramap = require('pull-paramap')
99
const zip = require('pull-zip')
1010
const toPull = require('stream-to-pull-stream')
11-
const Progress = require('progress')
1211
const getFolderSize = require('get-folder-size')
1312
const byteman = require('byteman')
1413
const waterfall = require('async/waterfall')
1514
const utils = require('../../utils')
1615
const print = require('../../utils').print
16+
const createProgressBar = require('../../utils').createProgressBar
1717

1818
const WRAPPER = 'wrapper/'
1919

@@ -52,19 +52,6 @@ function getTotalBytes (path, recursive, cb) {
5252
}
5353
}
5454

55-
function createProgressBar (totalBytes) {
56-
const total = byteman(totalBytes, 2, 'MB')
57-
const barFormat = `:progress / ${total} [:bar] :percent :etas`
58-
59-
// 16 MB / 34 MB [=========== ] 48% 5.8s //
60-
return new Progress(barFormat, {
61-
incomplete: ' ',
62-
clear: true,
63-
stream: process.stdout,
64-
total: totalBytes
65-
})
66-
}
67-
6855
function addPipeline (index, addStream, list, argv) {
6956
const {
7057
wrapWithDirectory,

src/cli/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const path = require('path')
99
const debug = require('debug')
1010
const log = debug('cli')
1111
log.error = debug('cli:error')
12+
const Progress = require('progress')
13+
const byteman = require('byteman')
1214

1315
exports = module.exports
1416

@@ -85,3 +87,16 @@ exports.print = (msg, newline) => {
8587
process.stdout.write(msg)
8688
}
8789
}
90+
91+
exports.createProgressBar = (totalBytes) => {
92+
const total = byteman(totalBytes, 2, 'MB')
93+
const barFormat = `:progress / ${total} [:bar] :percent :etas`
94+
95+
// 16 MB / 34 MB [=========== ] 48% 5.8s //
96+
return new Progress(barFormat, {
97+
incomplete: ' ',
98+
clear: true,
99+
stream: process.stdout,
100+
total: totalBytes
101+
})
102+
}

test/cli/progress-bar.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const expect = require('chai').expect
5+
const createProgressBar = require('../../src/cli/utils').createProgressBar
6+
7+
describe('progress bar', () => {
8+
it('created with the correct properties', () => {
9+
const total = 1000
10+
11+
const bar = createProgressBar(total)
12+
expect(bar.total).to.eql(total)
13+
expect(typeof bar.tick).to.eql('function')
14+
})
15+
})

0 commit comments

Comments
 (0)