File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const _progress = Symbol ( '_progress' )
22const _onError = Symbol ( '_onError' )
3+ const _setProgress = Symbol ( '_setProgess' )
34const npmlog = require ( 'npmlog' )
45
56module . exports = cls => class Tracker extends cls {
67 constructor ( options = { } ) {
78 super ( options )
9+ this [ _setProgress ] = ! ! options . progress
810 this [ _progress ] = new Map ( )
911 }
1012
@@ -27,7 +29,7 @@ module.exports = cls => class Tracker extends cls {
2729 // 1. no existing tracker, no subsection
2830 // Create a new tracker from npmlog
2931 // starts progress bar
30- if ( this [ _progress ] . size === 0 ) {
32+ if ( this [ _setProgress ] && this [ _progress ] . size === 0 ) {
3133 npmlog . enableProgress ( )
3234 }
3335
@@ -76,7 +78,7 @@ module.exports = cls => class Tracker extends cls {
7678
7779 // remove progress bar if all
7880 // trackers are finished
79- if ( this [ _progress ] . size === 0 ) {
81+ if ( this [ _setProgress ] && this [ _progress ] . size === 0 ) {
8082 npmlog . disableProgress ( )
8183 }
8284 } else if ( ! hasTracker && subsection === null ) {
@@ -92,7 +94,9 @@ module.exports = cls => class Tracker extends cls {
9294 }
9395
9496 [ _onError ] ( msg ) {
95- npmlog . disableProgress ( )
97+ if ( this [ _setProgress ] ) {
98+ npmlog . disableProgress ( )
99+ }
96100 throw new Error ( msg )
97101 }
98102}
Original file line number Diff line number Diff line change 11const Tracker = require ( '../lib/tracker.js' ) ( class { } )
22const t = require ( 'tap' )
33
4- t . test ( 'no npmlog ' , t => {
5- const tr = new Tracker ( )
4+ t . test ( 'with progress ' , t => {
5+ const tr = new Tracker ( { progress : true } )
66 t . doesNotThrow ( ( ) => {
77 tr . addTracker ( 'testTracker' )
88 } )
99 t . doesNotThrow ( ( ) => {
1010 tr . finishTracker ( 'testTracker' )
1111 } )
1212
13+ t . throws ( ( ) => {
14+ tr . addTracker ( )
15+ } , Error , `Tracker can't be null or undefined` )
16+
1317 t . end ( )
1418} )
1519
You can’t perform that action at this time.
0 commit comments