• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap.js')
2var fs = require('fs')
3var path = require('path')
4
5var test = require('tap').test
6
7var npm = require('../../lib/npm.js')
8
9var pkg = common.pkg
10var npmrc = path.resolve(pkg, '.npmrc')
11var packagePath = path.resolve(pkg, 'package.json')
12
13var json = { name: 'blah', version: '0.1.2' }
14
15var configContents = 'sign-git-commit=false\nsign-git-tag=false\nmessage=":bookmark: %s"\n'
16
17test('npm version <semver> with message config', function (t) {
18  setup()
19
20  npm.load({ prefix: pkg, userconfig: npmrc }, function () {
21    var git = require('../../lib/utils/git.js')
22
23    common.makeGitRepo({ path: pkg }, function (er) {
24      t.ifErr(er, 'git bootstrap ran without error')
25
26      common.npm(
27        [
28          'version',
29          'patch',
30          '--loglevel', 'silent'
31          // package config is picked up from env
32        ],
33        { cwd: pkg, env: { PATH: process.env.PATH } },
34        function (err, code, stdout, stderr) {
35          t.ifError(err, 'npm version ran without issue')
36          t.notOk(code, 'exited with a non-error code')
37          t.notOk(stderr, 'no error output')
38
39          git.whichAndExec(
40            ['log'],
41            { cwd: pkg, env: process.env },
42            function (er, log, stderr) {
43              t.ok(log.match(/:bookmark: 0\.1\.3/g), 'config was picked up by version')
44              t.end()
45            }
46          )
47        }
48      )
49    })
50  })
51})
52
53function setup () {
54  process.chdir(pkg)
55
56  fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
57  fs.writeFileSync(npmrc, configContents, 'ascii')
58}
59