summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/progress-config.js
blob: 634c9e8596c17ff0d8b3a34adef1aa300dbc64bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict'
var path = require('path')
var test = require('tap').test
var log = require('npmlog')
var fs = require('graceful-fs')
var configName = path.join(__dirname, path.basename(__filename, '.js')) + '-npmrc'

// We use requireInject to get a fresh copy of
// the npm singleton each time we require it.
// If we didn't, we'd have shared state between
// these various tests.
var requireInject = require('require-inject')

// Make sure existing environment vars don't muck up the test
process.env = {}

function hasOnlyAscii (s) {
  return /^[\000-\177]*$/.test(s)
}

test('setup', function (t) {
  fs.writeFileSync(configName, '')
  t.done()
})

test('disabled', function (t) {
  t.plan(1)
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName, progress: false}, function () {
    t.is(log.progressEnabled, false, 'should be disabled')
  })
})

test('enabled', function (t) {
  t.plan(1)
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName, progress: true}, function () {
    t.is(log.progressEnabled, true, 'should be enabled')
  })
})

test('default', function (t) {
  t.plan(1)
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName}, function () {
    t.is(log.progressEnabled, true, 'should be enabled')
  })
})

test('default-travis', function (t) {
  t.plan(1)
  global.process.env.TRAVIS = 'true'
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName}, function () {
    t.is(log.progressEnabled, false, 'should be disabled')
    delete global.process.env.TRAVIS
  })
})

test('default-ci', function (t) {
  t.plan(1)
  global.process.env.CI = 'true'
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName}, function () {
    t.is(log.progressEnabled, false, 'should be disabled')
    delete global.process.env.CI
  })
})

test('unicode-true', function (t) {
  t.plan(6)
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName, unicode: true}, function () {
    Object.keys(log.gauge.theme).forEach(function (key) {
      t.notOk(hasOnlyAscii(log.gauge.theme[key]), 'only unicode')
    })
  })
})

test('unicode-false', function (t) {
  t.plan(6)
  var npm = requireInject('../../lib/npm.js', {})
  npm.load({userconfig: configName, unicode: false}, function () {
    Object.keys(log.gauge.theme).forEach(function (key) {
      t.ok(hasOnlyAscii(log.gauge.theme[key]), 'only ASCII')
    })
  })
})

test('cleanup', function (t) {
  fs.unlinkSync(configName)
  t.done()
})