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
|
var test = require('tap').test
const common = require('../common-tap.js')
var npm = require('../..')
var path = require('path')
var rimraf = require('rimraf')
var npmrc = path.join(common.pkg, 'npmrc')
var fs = require('fs')
test('setup', function (t) {
fs.writeFileSync(npmrc, 'foo = bar\n', 'ascii')
t.end()
})
test('calling set/get on config pre-load should throw', function (t) {
var threw = true
try {
npm.config.get('foo')
threw = false
} catch (er) {
t.equal(er.message, 'npm.load() required')
} finally {
t.ok(threw, 'get before load should throw')
}
threw = true
try {
npm.config.set('foo', 'bar')
threw = false
} catch (er) {
t.equal(er.message, 'npm.load() required')
} finally {
t.ok(threw, 'set before load should throw')
}
npm.load({ userconfig: npmrc }, function (er) {
if (er) throw er
t.equal(npm.config.get('foo'), 'bar')
npm.config.set('foo', 'baz')
t.equal(npm.config.get('foo'), 'baz')
t.end()
})
})
test('cleanup', function (t) {
rimraf.sync(npmrc)
t.end()
})
|