1'use strict' 2var test = require('tap').test 3var log = require('npmlog') 4var fs = require('graceful-fs') 5const common = require('../common-tap.js') 6var configName = common.pkg + '/npmrc' 7 8// We use requireInject to get a fresh copy of 9// the npm singleton each time we require it. 10// If we didn't, we'd have shared state between 11// these various tests. 12var requireInject = require('require-inject') 13 14// Make sure existing environment vars don't muck up the test 15process.env = {} 16// Pretend that stderr is a tty regardless, so we can get consistent 17// results. 18process.stderr.isTTY = true 19 20test('setup', function (t) { 21 fs.writeFileSync(configName, '') 22 t.done() 23}) 24 25function getFreshNpm () { 26 return requireInject.withEmptyCache('../../lib/npm.js', {npmlog: log}) 27} 28 29test('disabled', function (t) { 30 t.plan(1) 31 var npm = getFreshNpm() 32 npm.load({userconfig: configName, progress: false}, function () { 33 t.is(log.progressEnabled, false, 'should be disabled') 34 }) 35}) 36 37test('enabled', function (t) { 38 t.plan(1) 39 var npm = getFreshNpm() 40 npm.load({userconfig: configName, progress: true}, function () { 41 t.is(log.progressEnabled, true, 'should be enabled') 42 }) 43}) 44 45test('default', function (t) { 46 t.plan(1) 47 var npm = getFreshNpm() 48 npm.load({userconfig: configName}, function () { 49 t.is(log.progressEnabled, true, 'should be enabled') 50 }) 51}) 52 53test('default-travis', function (t) { 54 t.plan(1) 55 process.env.TRAVIS = 'true' 56 var npm = getFreshNpm() 57 npm.load({userconfig: configName}, function () { 58 t.is(log.progressEnabled, false, 'should be disabled') 59 delete process.env.TRAVIS 60 }) 61}) 62 63test('default-ci', function (t) { 64 t.plan(1) 65 process.env.CI = 'true' 66 var npm = getFreshNpm() 67 npm.load({userconfig: configName}, function () { 68 t.is(log.progressEnabled, false, 'should be disabled') 69 delete process.env.CI 70 }) 71}) 72 73test('unicode-true', function (t) { 74 var npm = getFreshNpm() 75 npm.load({userconfig: configName, unicode: true}, function () { 76 t.is(log.gauge._theme.hasUnicode, true, 'unicode will be selected') 77 t.done() 78 }) 79}) 80 81test('unicode-false', function (t) { 82 var npm = getFreshNpm() 83 npm.load({userconfig: configName, unicode: false}, function () { 84 t.is(log.gauge._theme.hasUnicode, false, 'unicode will NOT be selected') 85 t.done() 86 }) 87}) 88