• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var test = require('tap').test
2const common = require('../common-tap.js')
3var npm = require('../..')
4var path = require('path')
5var rimraf = require('rimraf')
6var npmrc = path.join(common.pkg, 'npmrc')
7var fs = require('fs')
8
9test('setup', function (t) {
10  fs.writeFileSync(npmrc, 'foo = bar\n', 'ascii')
11  t.end()
12})
13
14test('calling set/get on config pre-load should throw', function (t) {
15  var threw = true
16  try {
17    npm.config.get('foo')
18    threw = false
19  } catch (er) {
20    t.equal(er.message, 'npm.load() required')
21  } finally {
22    t.ok(threw, 'get before load should throw')
23  }
24
25  threw = true
26  try {
27    npm.config.set('foo', 'bar')
28    threw = false
29  } catch (er) {
30    t.equal(er.message, 'npm.load() required')
31  } finally {
32    t.ok(threw, 'set before load should throw')
33  }
34
35  npm.load({ userconfig: npmrc }, function (er) {
36    if (er) throw er
37
38    t.equal(npm.config.get('foo'), 'bar')
39    npm.config.set('foo', 'baz')
40    t.equal(npm.config.get('foo'), 'baz')
41    t.end()
42  })
43})
44
45test('cleanup', function (t) {
46  rimraf.sync(npmrc)
47  t.end()
48})
49