• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const common = require('../common-tap.js')
2
3var path = require('path')
4var fs = require('graceful-fs')
5var test = require('tap').test
6var rimraf = require('rimraf')
7var npmconf = require('../../lib/config/core.js')
8
9var dir = common.pkg
10var beep = path.resolve(dir, 'beep.pem')
11var npmrc = path.resolve(dir, 'npmrc')
12
13test('can set new cafile when old is gone', function (t) {
14  t.plan(5)
15  fs.writeFileSync(npmrc, '')
16  fs.writeFileSync(beep, '')
17  npmconf.load({ userconfig: npmrc }, function (error, conf) {
18    npmconf.loaded = false
19    t.ifError(error)
20    conf.set('cafile', beep, 'user')
21    conf.save('user', function (error) {
22      t.ifError(error)
23      t.equal(conf.get('cafile'), beep)
24      rimraf.sync(beep)
25      npmconf.load({ userconfig: npmrc }, function (error, conf) {
26        if (error) {
27          throw error
28        }
29        t.equal(conf.get('cafile'), beep)
30        conf.del('cafile')
31        conf.save('user', function (error) {
32          t.ifError(error)
33        })
34      })
35    })
36  })
37})
38