summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/version-message-config.js
blob: 94e9e951e776f0f19e861872afe7e82b51c35387 (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
var common = require('../common-tap.js')
var fs = require('fs')
var path = require('path')

var test = require('tap').test

var npm = require('../../lib/npm.js')

var pkg = common.pkg
var npmrc = path.resolve(pkg, '.npmrc')
var packagePath = path.resolve(pkg, 'package.json')

var json = { name: 'blah', version: '0.1.2' }

var configContents = 'sign-git-commit=false\nsign-git-tag=false\nmessage=":bookmark: %s"\n'

test('npm version <semver> with message config', function (t) {
  setup()

  npm.load({ prefix: pkg, userconfig: npmrc }, function () {
    var git = require('../../lib/utils/git.js')

    common.makeGitRepo({ path: pkg }, function (er) {
      t.ifErr(er, 'git bootstrap ran without error')

      common.npm(
        [
          'version',
          'patch',
          '--loglevel', 'silent'
          // package config is picked up from env
        ],
        { cwd: pkg, env: { PATH: process.env.PATH } },
        function (err, code, stdout, stderr) {
          t.ifError(err, 'npm version ran without issue')
          t.notOk(code, 'exited with a non-error code')
          t.notOk(stderr, 'no error output')

          git.whichAndExec(
            ['log'],
            { cwd: pkg, env: process.env },
            function (er, log, stderr) {
              t.ok(log.match(/:bookmark: 0\.1\.3/g), 'config was picked up by version')
              t.end()
            }
          )
        }
      )
    })
  })
})

function setup () {
  process.chdir(pkg)

  fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
  fs.writeFileSync(npmrc, configContents, 'ascii')
}